blob: 9bb42d9e2be568583ff9b30765a068fc51a70d95 [file] [log] [blame]
Norman James42c1be82015-10-22 14:34:26 -05001#!/usr/bin/python -u
Norman James90baede2015-09-02 20:32:49 -05002
3import sys
Norman James6f8d0422015-09-14 18:48:00 -05004#from gi.repository import GObject
5import gobject
Norman James90baede2015-09-02 20:32:49 -05006import dbus
7import dbus.service
8import dbus.mainloop.glib
9
10if (len(sys.argv) < 2):
11 print "Usage: sensor_manager.py [system name]"
12 exit(1)
Norman James5d78b4d2015-09-05 13:34:34 -050013System = __import__(sys.argv[1])
Norman James90baede2015-09-02 20:32:49 -050014import Openbmc
15
16DBUS_NAME = 'org.openbmc.managers.Sensors'
Norman Jamesa3e47c42015-10-18 14:43:10 -050017OBJ_NAME = '/org/openbmc/sensors'
18ENUM_INTF = 'org.openbmc.Object.Enumerate'
Norman James90baede2015-09-02 20:32:49 -050019
20class SensorManager(dbus.service.Object):
21 def __init__(self,bus,name):
22 dbus.service.Object.__init__(self,bus,name)
Norman James362a80f2015-09-14 14:04:39 -050023 bus.add_signal_receiver(self.SensorChangedHandler,
Norman James9e6acf92015-09-08 07:00:04 -050024 dbus_interface = 'org.openbmc.SensorValue',
25 signal_name = 'Changed', path_keyword='path')
Norman James32e74e22015-09-15 21:28:06 -050026 bus.add_signal_receiver(self.SensorErrorHandler,
27 dbus_interface = 'org.openbmc.SensorValue',
28 signal_name = 'Error', path_keyword='path')
Norman James90baede2015-09-02 20:32:49 -050029 bus.add_signal_receiver(self.NormalThreshold,
Norman James5d78b4d2015-09-05 13:34:34 -050030 dbus_interface = 'org.openbmc.SensorThreshold',
Norman James90baede2015-09-02 20:32:49 -050031 signal_name = 'Normal', path_keyword='path')
32 bus.add_signal_receiver(self.WarningThreshold,
Norman James5d78b4d2015-09-05 13:34:34 -050033 dbus_interface = 'org.openbmc.SensorThreshold',
Norman James90baede2015-09-02 20:32:49 -050034 signal_name = 'Warning', path_keyword='path')
35 bus.add_signal_receiver(self.CriticalThreshold,
Norman James5d78b4d2015-09-05 13:34:34 -050036 dbus_interface = 'org.openbmc.SensorThreshold',
Norman James90baede2015-09-02 20:32:49 -050037 signal_name = 'Critical', path_keyword='path')
38
39 self.sensor_cache = {}
Norman James362a80f2015-09-14 14:04:39 -050040
Norman Jamesa3e47c42015-10-18 14:43:10 -050041 @dbus.service.method(ENUM_INTF,
Norman James2d1ee892015-09-16 23:13:45 -050042 in_signature='', out_signature='a{sa{sv}}')
Norman Jamesa3e47c42015-10-18 14:43:10 -050043 def enumerate(self):
Norman James362a80f2015-09-14 14:04:39 -050044 return self.sensor_cache;
45
Norman James362a80f2015-09-14 14:04:39 -050046
Norman James90baede2015-09-02 20:32:49 -050047 @dbus.service.method(DBUS_NAME,
Norman James5d78b4d2015-09-05 13:34:34 -050048 in_signature='s', out_signature='v')
Norman James90baede2015-09-02 20:32:49 -050049 def getSensor(self,path):
Norman James362a80f2015-09-14 14:04:39 -050050 val = 0
Norman James90baede2015-09-02 20:32:49 -050051 if (self.sensor_cache.has_key(path) == True):
52 val = self.sensor_cache[path]['value']
Norman James362a80f2015-09-14 14:04:39 -050053 else:
Norman James8c6d8382015-10-06 07:47:16 -050054 print "ERROR: Unknown sensor: "+path
Norman James90baede2015-09-02 20:32:49 -050055 return val
Norman James362a80f2015-09-14 14:04:39 -050056
Norman James32e74e22015-09-15 21:28:06 -050057 ## Signal handlers
58 def SensorErrorHandler(self,path = None):
59 self.initSensorEntry(path)
60 self.sensor_cache[path]['error'] = True
61
Norman James362a80f2015-09-14 14:04:39 -050062 def SensorChangedHandler(self,value,units,path = None):
Norman James9e6acf92015-09-08 07:00:04 -050063 self.initSensorEntry(path)
64 self.sensor_cache[path]['value'] = value
65 self.sensor_cache[path]['units'] = units
Norman James90baede2015-09-02 20:32:49 -050066
67 @dbus.service.signal(DBUS_NAME)
68 def CriticalThreshold(self, path = None):
69 print "Critical: "+path
Norman James5d78b4d2015-09-05 13:34:34 -050070 self.initSensorEntry(path)
Norman James90baede2015-09-02 20:32:49 -050071 self.sensor_cache[path]['threshold'] = "CRITICAL"
72
Norman James90baede2015-09-02 20:32:49 -050073 @dbus.service.signal(DBUS_NAME)
74 def WarningThreshold(self, path = None):
Norman James5d78b4d2015-09-05 13:34:34 -050075 print "Warning:"+path
76 self.initSensorEntry(path)
Norman James90baede2015-09-02 20:32:49 -050077 self.sensor_cache[path]['threshold'] = "WARNING"
78
Norman James90baede2015-09-02 20:32:49 -050079 @dbus.service.signal(DBUS_NAME)
80 def NormalThreshold(self, path = None):
81 print "Normal: "+path
Norman James5d78b4d2015-09-05 13:34:34 -050082 self.initSensorEntry(path)
Norman James90baede2015-09-02 20:32:49 -050083 self.sensor_cache[path]['threshold'] = "NORMAL"
84
Norman James5d78b4d2015-09-05 13:34:34 -050085 def initSensorEntry(self,path):
86 if (self.sensor_cache.has_key(path) == False):
87 self.sensor_cache[path] = {}
Norman James90baede2015-09-02 20:32:49 -050088
Norman James5d78b4d2015-09-05 13:34:34 -050089
Norman James90baede2015-09-02 20:32:49 -050090if __name__ == '__main__':
91 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
Norman James5e792e32015-10-07 17:36:17 -050092 bus = Openbmc.getDBus()
Norman James90baede2015-09-02 20:32:49 -050093 name = dbus.service.BusName(DBUS_NAME,bus)
94 obj = SensorManager(bus,OBJ_NAME)
Norman James6f8d0422015-09-14 18:48:00 -050095 mainloop = gobject.MainLoop()
Norman James90baede2015-09-02 20:32:49 -050096
97 print "Running Sensor Manager"
98 mainloop.run()
99