Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import sys |
| 4 | import gobject |
| 5 | import dbus |
| 6 | import dbus.service |
| 7 | import dbus.mainloop.glib |
| 8 | |
| 9 | if (len(sys.argv) < 2): |
| 10 | print "Usage: sensor_manager.py [system name]" |
| 11 | exit(1) |
| 12 | |
| 13 | import Openbmc |
| 14 | |
| 15 | DBUS_NAME = 'org.openbmc.managers.Sensors' |
| 16 | OBJ_NAME = '/org/openbmc/managers/Sensors/'+sys.argv[1] |
| 17 | |
| 18 | class SensorManager(dbus.service.Object): |
| 19 | def __init__(self,bus,name): |
| 20 | dbus.service.Object.__init__(self,bus,name) |
| 21 | bus.add_signal_receiver(self.UpdateSensor, |
| 22 | dbus_interface = 'org.openbmc.SensorInteger', |
| 23 | signal_name = 'Changed', path_keyword='path') |
| 24 | bus.add_signal_receiver(self.NormalThreshold, |
| 25 | dbus_interface = 'org.openbmc.SensorIntegerThreshold', |
| 26 | signal_name = 'Normal', path_keyword='path') |
| 27 | bus.add_signal_receiver(self.WarningThreshold, |
| 28 | dbus_interface = 'org.openbmc.SensorIntegerThreshold', |
| 29 | signal_name = 'Warning', path_keyword='path') |
| 30 | bus.add_signal_receiver(self.CriticalThreshold, |
| 31 | dbus_interface = 'org.openbmc.SensorIntegerThreshold', |
| 32 | signal_name = 'Critical', path_keyword='path') |
| 33 | |
| 34 | self.sensor_cache = {} |
| 35 | |
| 36 | @dbus.service.method(DBUS_NAME, |
| 37 | in_signature='s', out_signature='i') |
| 38 | def getSensor(self,path): |
| 39 | val = None |
| 40 | if (self.sensor_cache.has_key(path) == True): |
| 41 | val = self.sensor_cache[path]['value'] |
| 42 | return val |
| 43 | |
| 44 | def UpdateSensor(self,value, units, path = None): |
| 45 | if (self.sensor_cache.has_key(path) == False): |
| 46 | self.sensor_cache[path] = {} |
| 47 | self.sensor_cache[path]['value'] = value |
| 48 | self.sensor_cache[path]['units'] = units |
| 49 | |
| 50 | @dbus.service.signal(DBUS_NAME) |
| 51 | def CriticalThreshold(self, path = None): |
| 52 | print "Critical: "+path |
| 53 | if (self.sensor_cache.has_key(path) == False): |
| 54 | self.sensor_cache[path] = {} |
| 55 | self.sensor_cache[path]['threshold'] = "CRITICAL" |
| 56 | |
| 57 | |
| 58 | @dbus.service.signal(DBUS_NAME) |
| 59 | def WarningThreshold(self, path = None): |
| 60 | print "Warning: "+path |
| 61 | if (self.sensor_cache.has_key(path) == False): |
| 62 | self.sensor_cache[path] = {} |
| 63 | self.sensor_cache[path]['threshold'] = "WARNING" |
| 64 | |
| 65 | |
| 66 | @dbus.service.signal(DBUS_NAME) |
| 67 | def NormalThreshold(self, path = None): |
| 68 | print "Normal: "+path |
| 69 | if (self.sensor_cache.has_key(path) == False): |
| 70 | self.sensor_cache[path] = {} |
| 71 | self.sensor_cache[path]['threshold'] = "NORMAL" |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | if __name__ == '__main__': |
| 77 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 78 | bus = dbus.SessionBus() |
| 79 | name = dbus.service.BusName(DBUS_NAME,bus) |
| 80 | obj = SensorManager(bus,OBJ_NAME) |
| 81 | mainloop = gobject.MainLoop() |
| 82 | |
| 83 | print "Running Sensor Manager" |
| 84 | mainloop.run() |
| 85 | |