From cbf595df2699ec6e98c3d3a8a4c14c84e19da17a Mon Sep 17 00:00:00 2001 From: Juliana Motira Date: Wed, 29 Jul 2015 15:58:39 -0300 Subject: [PATCH] Treating sensors that has status = Unavailable. --- confluent_server/confluent/messages.py | 26 +++++++++---------- .../plugins/hardwaremanagement/ipmi.py | 23 +++++++--------- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/confluent_server/confluent/messages.py b/confluent_server/confluent/messages.py index 89a8f141..f5163a6b 100644 --- a/confluent_server/confluent/messages.py +++ b/confluent_server/confluent/messages.py @@ -748,19 +748,19 @@ class SensorReadings(ConfluentMessage): readings = [] self.notnode = name is None for sensor in sensors: - sensordict = {'name': sensor['name']} - if 'value' in sensor: - sensordict['value'] = sensor['value'] - if 'units' in sensor: - sensordict['units'] = sensor['units'] - if 'states' in sensor: - sensordict['states'] = sensor['states'] - if 'state_ids' in sensor: - sensordict['state_ids'] = sensor['state_ids'] - if 'health' in sensor: - sensordict['health'] = sensor['health'] - if 'type' in sensor: - sensordict['type'] = sensor['type'] + sensordict = {'name': sensor.name} + if hasattr(sensor, 'value'): + sensordict['value'] = sensor.value + if hasattr(sensor, 'units'): + sensordict['units'] = sensor.units + if hasattr(sensor, 'states'): + sensordict['states'] = sensor.states + if hasattr(sensor, 'state_ids'): + sensordict['state_ids'] = sensor.state_ids + if hasattr(sensor, 'health'): + sensordict['health'] = sensor.health + if hasattr(sensor, 'type'): + sensordict['type'] = sensor.type readings.append(sensordict) if self.notnode: self.kvpairs = {'sensors': readings} diff --git a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py index 6028b538..4e5bd879 100644 --- a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py +++ b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py @@ -276,17 +276,6 @@ def perform_request(operator, node, element, persistent_ipmicmds = {} - -def _dict_sensor(pygreading): - retdict = {'name': pygreading.name, 'value': pygreading.value, - 'states': pygreading.states, 'state_ids': pygreading.state_ids, - 'units': pygreading.units, - 'health': _str_health(pygreading.health), - 'type': pygreading.type, - } - return retdict - - class IpmiHandler(object): def __init__(self, operation, node, element, cfd, inputdata, cfg, output): self.sensormap = {} @@ -532,7 +521,9 @@ class IpmiHandler(object): if ie.ipmicode == 203: continue raise - readings.append(_dict_sensor(reading)) + if hasattr(reading, 'health'): + reading.health = _str_health(reading.health) + readings.append(reading) self.output.put(msg.SensorReadings(readings, name=self.node)) else: self.make_sensor_map() @@ -543,8 +534,10 @@ class IpmiHandler(object): return reading = self.ipmicmd.get_sensor_reading( self.sensormap[sensorname]) + if hasattr(reading, 'health'): + reading.health = _str_health(reading.health) self.output.put( - msg.SensorReadings([_dict_sensor(reading)], + msg.SensorReadings([reading], name=self.node)) except pygexc.IpmiException: self.output.put(msg.ConfluentTargetTimeout(self.node)) @@ -635,7 +628,9 @@ class IpmiHandler(object): if 'badreadings' in response: badsensors = [] for reading in response['badreadings']: - badsensors.append(_dict_sensor(reading)) + if hasattr(reading, 'health'): + reading.health = _str_health(reading.health) + badsensors.append(reading) self.output.put(msg.SensorReadings(badsensors, name=self.node)) else: raise exc.InvalidArgumentException('health is read-only')