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 |
Norman James | 6f8d042 | 2015-09-14 18:48:00 -0500 | [diff] [blame] | 6 | 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 | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame^] | 10 | import Openbmc |
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, |
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame^] | 22 | dbus_interface = "org.openbmc.EventLog", |
| 23 | signal_name = "EventLog", |
| 24 | path_keyword='path') |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 25 | |
| 26 | ## Signal handler |
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame^] | 27 | def event_log_signal_handler(self,e_type,msg,path = None): |
| 28 | message = {} |
| 29 | message['object_path'] = path |
| 30 | message['e_type'] = Openbmc.EVENT_TYPES[int(e_type)] |
| 31 | message['message'] = msg |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 32 | syslog.syslog(json.dumps(message)) |
| 33 | |
| 34 | if __name__ == '__main__': |
| 35 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 36 | |
| 37 | bus = dbus.SessionBus() |
| 38 | name = dbus.service.BusName(DBUS_NAME, bus) |
| 39 | obj = EventLogger(bus, OBJ_NAME) |
Norman James | 6f8d042 | 2015-09-14 18:48:00 -0500 | [diff] [blame] | 40 | mainloop = gobject.MainLoop() |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 41 | |
| 42 | print "Running EventLogger" |
| 43 | mainloop.run() |
| 44 | |