From 7ac880f3f8b412831f88de78ee3dd323b5e54d7b Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 20 Jan 2014 18:31:40 -0500 Subject: [PATCH] Add 'get_health' to Command class Provide a convenience function that summarizes the overall health of the managed system based. Currently, it just enumerates all SDR indicated sensors seeking unhealthy readings. Change-Id: Ifce6d05623acc86b6bf42ceb57824b65eefa36ae --- ipmictl.py | 2 ++ pyghmi/ipmi/command.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/ipmictl.py b/ipmictl.py index e31591ef..d0f00b52 100755 --- a/ipmictl.py +++ b/ipmictl.py @@ -60,6 +60,8 @@ def docommand(result, ipmisession): elif cmmand == 'sensors': for reading in ipmisession.get_sensor_data(): print repr(reading) + elif cmmand == 'health': + print repr(ipmisession.get_health()) elif cmmand == 'raw': print ipmisession.raw_command(netfn=int(args[0]), command=int(args[1]), diff --git a/pyghmi/ipmi/command.py b/pyghmi/ipmi/command.py index 27f297f5..22bcfc7f 100644 --- a/pyghmi/ipmi/command.py +++ b/pyghmi/ipmi/command.py @@ -15,6 +15,7 @@ # limitations under the License. # This represents the low layer message framing portion of IPMI +import pyghmi.constants as const import pyghmi.exceptions as exc from pyghmi.ipmi.private import session @@ -291,6 +292,22 @@ class Command(object): self.powerstate = 'on' if (response['data'][0] & 1) else 'off' return {'powerstate': self.powerstate} + def get_health(self): + """Summarize health of managed system + + This provides a summary of the health of the managed system. + It additionally provides an iterable list of reasons for + warning, critical, or failed assessments. + """ + summary = {} + summary['badreadings'] = [] + summary['health'] = const.Health.Ok + for reading in self.get_sensor_data(): + if reading.health != const.Health.Ok: + summary['health'] |= reading.health + summary['badreadings'].append(reading) + return summary + def get_sensor_data(self): """Get sensor reading objects