mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-29 09:13:08 +00:00
openbmc eventlog in python, phase 2
This commit is contained in:
parent
f499b21f67
commit
d84895a3d1
@ -20,13 +20,35 @@ logger = logging.getLogger('xcatagent')
|
||||
class OpenBMCEventlogTask(ParallelNodesCommand):
|
||||
"""Executor for eventlog-related actions."""
|
||||
|
||||
def get_ev_info(self, eventlog_type, **kw):
|
||||
def get_ev_info(self, args, **kw):
|
||||
|
||||
node = kw['node']
|
||||
number_to_display = 0
|
||||
try:
|
||||
# Number of records to display from the end
|
||||
number_to_display = 0-int(args[0])
|
||||
except Exception:
|
||||
# All records to display
|
||||
number_to_display = 0
|
||||
|
||||
obmc = openbmc.OpenBMCRest(name=node, nodeinfo=kw['nodeinfo'], messager=self.callback, debugmode=self.debugmode, verbose=self.verbose)
|
||||
eventlog_info = []
|
||||
try:
|
||||
obmc.login()
|
||||
|
||||
# Get all eventlog records
|
||||
eventlog_info_dict = obmc.get_eventlog_info()
|
||||
|
||||
keys = eventlog_info_dict.keys()
|
||||
# Sort thy keys in natural order
|
||||
keys.sort(key=lambda x : int(x[0:]))
|
||||
|
||||
# Display all, or specified number of records from the end
|
||||
for key in list(keys)[number_to_display:]:
|
||||
self.callback.info('%s: %s' % (node, eventlog_info_dict[key]))
|
||||
eventlog_info += eventlog_info_dict[key]
|
||||
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info('%s: %s' % (node, e.message))
|
||||
|
||||
return eventlog_info
|
||||
|
@ -488,17 +488,68 @@ class OpenBMCRest(object):
|
||||
|
||||
return bool(func_list), fw_dict
|
||||
|
||||
# Extract all eventlog info and build a dictionary with eventid as a key
|
||||
def get_eventlog_info(self):
|
||||
|
||||
eventlog_data = self.request('GET', EVENTLOG_URL, cmd='get_eventlog_info')
|
||||
try:
|
||||
eventlog_dict = {}
|
||||
for key, value in eventlog_data.items():
|
||||
self.messager.info("EVENTLOG DATA: key=%s" %key)
|
||||
for key, value in sorted(eventlog_data.items()):
|
||||
id, event_log_line = self.parse_event_data(value)
|
||||
if int(id) != 0:
|
||||
eventlog_dict[str(id)] = event_log_line
|
||||
return eventlog_dict
|
||||
except KeyError:
|
||||
error = 'Error: Received wrong format response: %s' % eventlog_data
|
||||
raise SelfServerException(error)
|
||||
|
||||
# Parse a single eventlog entry and return data in formatted string
|
||||
def parse_event_data(self, event_log_entry):
|
||||
formatted_line = ""
|
||||
LED_tag = " [LED]"
|
||||
timestamp_str = ""
|
||||
message_str = ""
|
||||
pid_str = ""
|
||||
resolved_str = ""
|
||||
id_str = "0"
|
||||
callout = False
|
||||
for (sub_key, v) in event_log_entry.items():
|
||||
if sub_key == 'AdditionalData':
|
||||
for (data_key) in v:
|
||||
additional_data = data_key.split("=");
|
||||
if additional_data[0] == 'ESEL':
|
||||
#self.messager.info(' ESEL : <long data string>')
|
||||
info = additional_data[0].split('=')
|
||||
#esel = info[1]
|
||||
elif additional_data[0] == '_PID':
|
||||
pid_str = " (PID: " + str(additional_data[1]) + ")"
|
||||
elif 'CALLOUT_DEVICE_PATH' in additional_data[0]:
|
||||
callout = True
|
||||
info = additional_data[0].split('=')
|
||||
#callout_data = info[1]
|
||||
elif 'CALLOUT_INVENTORY_PATH' in additional_data[0]:
|
||||
callout = True
|
||||
callout_data="I2C"
|
||||
elif 'CALLOUT' in additional_data[0]:
|
||||
callout = True
|
||||
#else:
|
||||
# self.messager.info(' %s : %s' % (additional_data[0], additional_data[1]))
|
||||
elif sub_key == 'Timestamp':
|
||||
timestamp = time.localtime(v / 1000)
|
||||
timestamp_str = time.strftime("%m/%d/%Y %T", timestamp)
|
||||
elif sub_key == 'Id':
|
||||
#id_str = " [{0}]".format(v)
|
||||
id_str = str(v)
|
||||
elif sub_key == 'Resolved':
|
||||
resolved_str = " Resolved: " + str(v)
|
||||
elif sub_key == 'Message':
|
||||
message_str = " " + v
|
||||
#else:
|
||||
# self.messager.info(' %s : %s' % (sub_key, v))
|
||||
formatted_line = timestamp_str + " [" + id_str +"]" + ":" + message_str + pid_str + resolved_str
|
||||
if callout:
|
||||
formatted_line += LED_tag
|
||||
return id_str, formatted_line
|
||||
|
||||
def set_apis_values(self, key, value):
|
||||
attr_info = RSPCONFIG_APIS[key]
|
||||
|
@ -841,7 +841,7 @@ class OpenBMCManager(base.BaseManager):
|
||||
|
||||
reventlog_usage = """
|
||||
Usage:
|
||||
eventlog [-V|--verbose] [all|clear|resolved]
|
||||
eventlog [-V|--verbose] [<number>|all|clear|resolved=(<id>|LED)]
|
||||
|
||||
Options:
|
||||
-V --verbose eventlog verbose mode.
|
||||
@ -857,16 +857,15 @@ class OpenBMCManager(base.BaseManager):
|
||||
return
|
||||
|
||||
# 2, validate the args
|
||||
if action not in EVENTLOG_OPTIONS:
|
||||
self.messager.error("Not supported subcommand for reventlog: %s" % action)
|
||||
return
|
||||
self.messager.error("reventlog action: %s" % action)
|
||||
self.messager.error("reventlog args: %s" % args)
|
||||
#if action not in EVENTLOG_OPTIONS:
|
||||
# self.messager.error("Not supported subcommand for reventlog: %s" % action)
|
||||
# return
|
||||
|
||||
# 3, run the subcommands
|
||||
runner = OpenBMCEventlogTask(nodesinfo, callback=self.messager, debugmode=self.debugmode, verbose=self.verbose)
|
||||
if action == 'resolved':
|
||||
DefaultEventlogManager().get_eventlog_info(runner)
|
||||
else:
|
||||
DefaultEventlogManager().get_eventlog_info(runner, action)
|
||||
DefaultEventlogManager().get_eventlog_info(runner, args)
|
||||
|
||||
def _get_full_path(self,file_path):
|
||||
if type(self.cwd) == 'unicode':
|
||||
|
Loading…
x
Reference in New Issue
Block a user