Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import sys |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 4 | import syslog |
| 5 | import json |
| 6 | from gi.repository import GObject |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 7 | import dbus |
| 8 | import dbus.service |
| 9 | import dbus.mainloop.glib |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 10 | |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 11 | |
| 12 | DBUS_NAME = 'org.openbmc.loggers.EventLogger' |
| 13 | OBJ_NAME = '/org/openbmc/loggers/EventLogger/'+sys.argv[1] |
| 14 | |
| 15 | class EventLogger(dbus.service.Object): |
| 16 | def __init__(self,bus,name): |
| 17 | dbus.service.Object.__init__(self,bus,name) |
| 18 | bus = dbus.SessionBus() |
| 19 | syslog.openlog('openbmc') |
| 20 | |
| 21 | bus.add_signal_receiver(self.event_log_signal_handler, |
| 22 | dbus_interface = "org.openbmc.EventLog", signal_name = "EventLog" ) |
| 23 | |
| 24 | ## Signal handler |
| 25 | def event_log_signal_handler(self,message): |
| 26 | syslog.syslog(json.dumps(message)) |
| 27 | |
| 28 | if __name__ == '__main__': |
| 29 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 30 | |
| 31 | bus = dbus.SessionBus() |
| 32 | name = dbus.service.BusName(DBUS_NAME, bus) |
| 33 | obj = EventLogger(bus, OBJ_NAME) |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 34 | mainloop = GObject.MainLoop() |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 35 | |
| 36 | print "Running EventLogger" |
| 37 | mainloop.run() |
| 38 | |