Norman James | 42c1be8 | 2015-10-22 14:34:26 -0500 | [diff] [blame] | 1 | #!/usr/bin/python -u |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 2 | |
| 3 | import sys |
Norman James | 6f8d042 | 2015-09-14 18:48:00 -0500 | [diff] [blame] | 4 | #from gi.repository import GObject |
| 5 | import gobject |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 6 | import dbus |
| 7 | import dbus.service |
| 8 | import dbus.mainloop.glib |
| 9 | |
| 10 | if (len(sys.argv) < 2): |
| 11 | print "Usage: sensor_manager.py [system name]" |
| 12 | exit(1) |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 13 | System = __import__(sys.argv[1]) |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 14 | import Openbmc |
| 15 | |
| 16 | DBUS_NAME = 'org.openbmc.managers.Sensors' |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 17 | OBJ_NAME = '/org/openbmc/sensors' |
| 18 | ENUM_INTF = 'org.openbmc.Object.Enumerate' |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 19 | |
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 20 | class SensorManager(Openbmc.DbusProperties): |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 21 | def __init__(self,bus,name): |
| 22 | dbus.service.Object.__init__(self,bus,name) |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 23 | bus.add_signal_receiver(self.SensorChangedHandler, |
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame] | 24 | dbus_interface = 'org.openbmc.SensorValue', |
| 25 | signal_name = 'Changed', path_keyword='path') |
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 26 | bus.add_signal_receiver(self.SensorErrorHandler, |
| 27 | dbus_interface = 'org.openbmc.SensorValue', |
| 28 | signal_name = 'Error', path_keyword='path') |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 29 | bus.add_signal_receiver(self.NormalThreshold, |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 30 | dbus_interface = 'org.openbmc.SensorThreshold', |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 31 | signal_name = 'Normal', path_keyword='path') |
| 32 | bus.add_signal_receiver(self.WarningThreshold, |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 33 | dbus_interface = 'org.openbmc.SensorThreshold', |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 34 | signal_name = 'Warning', path_keyword='path') |
| 35 | bus.add_signal_receiver(self.CriticalThreshold, |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 36 | dbus_interface = 'org.openbmc.SensorThreshold', |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 37 | signal_name = 'Critical', path_keyword='path') |
| 38 | |
| 39 | self.sensor_cache = {} |
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 40 | self.ObjectAdded(name,DBUS_NAME); |
| 41 | self.ObjectAdded(name,ENUM_INTF); |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 42 | |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 43 | @dbus.service.method(ENUM_INTF, |
Norman James | 2d1ee89 | 2015-09-16 23:13:45 -0500 | [diff] [blame] | 44 | in_signature='', out_signature='a{sa{sv}}') |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 45 | def enumerate(self): |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 46 | return self.sensor_cache; |
| 47 | |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 48 | |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 49 | @dbus.service.method(DBUS_NAME, |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 50 | in_signature='s', out_signature='v') |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 51 | def getSensor(self,path): |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 52 | val = 0 |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 53 | if (self.sensor_cache.has_key(path) == True): |
| 54 | val = self.sensor_cache[path]['value'] |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 55 | else: |
Norman James | 8c6d838 | 2015-10-06 07:47:16 -0500 | [diff] [blame] | 56 | print "ERROR: Unknown sensor: "+path |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 57 | return val |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 58 | |
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 59 | ## Signal handlers |
| 60 | def SensorErrorHandler(self,path = None): |
| 61 | self.initSensorEntry(path) |
| 62 | self.sensor_cache[path]['error'] = True |
| 63 | |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 64 | def SensorChangedHandler(self,value,units,path = None): |
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame] | 65 | self.initSensorEntry(path) |
| 66 | self.sensor_cache[path]['value'] = value |
| 67 | self.sensor_cache[path]['units'] = units |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 68 | |
| 69 | @dbus.service.signal(DBUS_NAME) |
| 70 | def CriticalThreshold(self, path = None): |
| 71 | print "Critical: "+path |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 72 | self.initSensorEntry(path) |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 73 | self.sensor_cache[path]['threshold'] = "CRITICAL" |
| 74 | |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 75 | @dbus.service.signal(DBUS_NAME) |
| 76 | def WarningThreshold(self, path = None): |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 77 | print "Warning:"+path |
| 78 | self.initSensorEntry(path) |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 79 | self.sensor_cache[path]['threshold'] = "WARNING" |
| 80 | |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 81 | @dbus.service.signal(DBUS_NAME) |
| 82 | def NormalThreshold(self, path = None): |
| 83 | print "Normal: "+path |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 84 | self.initSensorEntry(path) |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 85 | self.sensor_cache[path]['threshold'] = "NORMAL" |
| 86 | |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 87 | def initSensorEntry(self,path): |
| 88 | if (self.sensor_cache.has_key(path) == False): |
| 89 | self.sensor_cache[path] = {} |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 90 | |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 91 | |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 92 | if __name__ == '__main__': |
| 93 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
Norman James | 5e792e3 | 2015-10-07 17:36:17 -0500 | [diff] [blame] | 94 | bus = Openbmc.getDBus() |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 95 | name = dbus.service.BusName(DBUS_NAME,bus) |
| 96 | obj = SensorManager(bus,OBJ_NAME) |
Norman James | 6f8d042 | 2015-09-14 18:48:00 -0500 | [diff] [blame] | 97 | mainloop = gobject.MainLoop() |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 98 | |
| 99 | print "Running Sensor Manager" |
| 100 | mainloop.run() |
| 101 | |