Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import sys |
Norman James | 8abb50c | 2015-09-16 10:58:16 -0500 | [diff] [blame] | 4 | import datetime |
| 5 | import time |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 6 | import syslog |
| 7 | import json |
Norman James | 6f8d042 | 2015-09-14 18:48:00 -0500 | [diff] [blame] | 8 | import gobject |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 9 | import dbus |
| 10 | import dbus.service |
| 11 | import dbus.mainloop.glib |
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 12 | import Openbmc |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 13 | |
| 14 | DBUS_NAME = 'org.openbmc.loggers.EventLogger' |
| 15 | OBJ_NAME = '/org/openbmc/loggers/EventLogger/'+sys.argv[1] |
| 16 | |
Norman James | 8abb50c | 2015-09-16 10:58:16 -0500 | [diff] [blame] | 17 | |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 18 | class EventLogger(dbus.service.Object): |
| 19 | def __init__(self,bus,name): |
| 20 | dbus.service.Object.__init__(self,bus,name) |
| 21 | bus = dbus.SessionBus() |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 22 | bus.add_signal_receiver(self.event_log_signal_handler, |
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 23 | dbus_interface = "org.openbmc.EventLog", |
| 24 | signal_name = "EventLog", |
| 25 | path_keyword='path') |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 26 | |
| 27 | ## Signal handler |
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame^] | 28 | def event_log_signal_handler(self,priority,msg,rc,path = None): |
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 29 | message = {} |
Norman James | 8abb50c | 2015-09-16 10:58:16 -0500 | [diff] [blame] | 30 | ts = time.time() |
| 31 | |
| 32 | message['priority'] = priority |
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 33 | message['object_path'] = path |
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 34 | message['message'] = msg |
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame^] | 35 | message['rc'] = rc |
Norman James | 8abb50c | 2015-09-16 10:58:16 -0500 | [diff] [blame] | 36 | |
| 37 | json_dump = json.dumps(message) |
| 38 | print "EVENT_LOG: "+json_dump |
Norman James | 2d1ee89 | 2015-09-16 23:13:45 -0500 | [diff] [blame] | 39 | syslog.openlog('OpenBmc',logoption=syslog.LOG_PID) |
Norman James | 8abb50c | 2015-09-16 10:58:16 -0500 | [diff] [blame] | 40 | syslog.syslog(priority,json_dump) |
| 41 | syslog.closelog() |
| 42 | |
| 43 | |
| 44 | |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 45 | |
| 46 | if __name__ == '__main__': |
| 47 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 48 | |
| 49 | bus = dbus.SessionBus() |
| 50 | name = dbus.service.BusName(DBUS_NAME, bus) |
| 51 | obj = EventLogger(bus, OBJ_NAME) |
Norman James | 6f8d042 | 2015-09-14 18:48:00 -0500 | [diff] [blame] | 52 | mainloop = gobject.MainLoop() |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 53 | |
| 54 | print "Running EventLogger" |
| 55 | mainloop.run() |
| 56 | |