diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_eventlog.py b/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_eventlog.py index 6d5497251..f0d417a31 100644 --- a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_eventlog.py +++ b/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_eventlog.py @@ -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 diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py index 82983b296..70b69eaeb 100644 --- a/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py +++ b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py @@ -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 : ') + 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] diff --git a/xCAT-openbmc-py/lib/python/agent/xcatagent/openbmc.py b/xCAT-openbmc-py/lib/python/agent/xcatagent/openbmc.py index 85c26306a..63f6abff9 100644 --- a/xCAT-openbmc-py/lib/python/agent/xcatagent/openbmc.py +++ b/xCAT-openbmc-py/lib/python/agent/xcatagent/openbmc.py @@ -841,7 +841,7 @@ class OpenBMCManager(base.BaseManager): reventlog_usage = """ Usage: - eventlog [-V|--verbose] [all|clear|resolved] + eventlog [-V|--verbose] [|all|clear|resolved=(|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':