From 01980e40e98d95b12eb24ba9f53ca8ef97b49a60 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 14 May 2015 14:52:20 -0400 Subject: [PATCH] Add OEM event fixup Provide a facility for OEM plugins to modify events on the way out of the event handling functions. Change-Id: I24f31f7035dcba2c1f30810a6282c87ee987ddad --- pyghmi/ipmi/command.py | 3 ++- pyghmi/ipmi/events.py | 8 +++++++- pyghmi/ipmi/oem/generic.py | 14 ++++++++++++++ pyghmi/ipmi/oem/lenovo.py | 9 +++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/pyghmi/ipmi/command.py b/pyghmi/ipmi/command.py index cd8ddcbc..b8eaf69d 100644 --- a/pyghmi/ipmi/command.py +++ b/pyghmi/ipmi/command.py @@ -421,7 +421,8 @@ class Command(object): :param clear: Whether to remove the SEL entries from the target BMC """ - return sel.EventHandler(self.init_sdr()).fetch_sel(self, clear) + self.oem_init() + return sel.EventHandler(self.init_sdr(), self).fetch_sel(self, clear) def get_inventory_descriptions(self): """Retrieve list of things that could be inventoried diff --git a/pyghmi/ipmi/events.py b/pyghmi/ipmi/events.py index 46f29a0d..0ca3d39c 100644 --- a/pyghmi/ipmi/events.py +++ b/pyghmi/ipmi/events.py @@ -367,8 +367,9 @@ class EventHandler(object): :param sdr: An SDR object (per pyghmi.ipmi.sdr) matching the target BMC SDR """ - def __init__(self, sdr): + def __init__(self, sdr, ipmicmd): self._sdr = sdr + self._ipmicmd = ipmicmd def _decode_standard_event(self, eventdata, event): # Ignore the generator id for now.. @@ -386,12 +387,14 @@ class EventHandler(object): event['component'] = 'Sensor {0}'.format(eventdata[4]) event['deassertion'] = (eventdata[5] & 0b10000000 == 0b10000000) event_data = eventdata[6:] + event['event_data_bytes'] = event_data event_type = eventdata[5] & 0b1111111 byte2type = (event_data[0] & 0b11000000) >> 6 byte3type = (event_data[0] & 0b110000) >> 4 if byte2type == 1: event['triggered_value'] = event_data[1] evtoffset = event_data[0] & 0b1111 + event['event_type_byte'] = event_type if event_type <= 0xc: event['component_type_id'] = sensor_type event['event_id'] = '{0}.{1}'.format(event_type, evtoffset) @@ -449,6 +452,9 @@ class EventHandler(object): # In this class of OEM message, all bytes are OEM, interpretation # is wholly left up to the OEM layer, using the OEM ID of the BMC event['oemdata'] = selentry[3:] + self._ipmicmd._oem.process_event(event) + del event['event_type_byte'] + del event['event_data_bytes'] return event def _fetch_entries(self, ipmicmd, startat, targetlist, rsvid=0): diff --git a/pyghmi/ipmi/oem/generic.py b/pyghmi/ipmi/oem/generic.py index d0b6ffb6..be3195f3 100644 --- a/pyghmi/ipmi/oem/generic.py +++ b/pyghmi/ipmi/oem/generic.py @@ -27,6 +27,20 @@ class OEMHandler(object): def __init__(self, oemid, ipmicmd): pass + def process_event(self, event): + """Modify an event according with OEM understanding. + + Given an event, allow an OEM module to augment it. For example, + event data fields can have OEM bytes. Other times an OEM may wish + to apply some transform to some field to suit their conventions. + """ + event['oem_handler'] = None + evdata = event['event_data_bytes'] + if evdata[0] & 0b11000000 == 0b10000000: + event['oem_byte2'] = evdata[1] + if evdata[0] & 0b110000 == 0b100000: + event['oem_byte3'] = evdata[2] + def process_fru(self, fru): """Modify a fru entry with OEM understanding. diff --git a/pyghmi/ipmi/oem/lenovo.py b/pyghmi/ipmi/oem/lenovo.py index 2e289d58..701a6833 100644 --- a/pyghmi/ipmi/oem/lenovo.py +++ b/pyghmi/ipmi/oem/lenovo.py @@ -25,6 +25,15 @@ class OEMHandler(generic.OEMHandler): # variations. For example System X versus Thinkserver self.oemid = oemid + def process_event(self, event): + evdata = event['event_data_bytes'] + # For HDD bay events, the event data 2 is the bay, modify + # the description to be more specific + if (event['event_type_byte'] == 0x6f and + (evdata[0] & 0b11000000) == 0b10000000 and + event['component_type_id'] == 13): + event['component'] += ' {0}'.format(evdata[1]) + def process_fru(self, fru): if fru is None: return fru