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 | 8abb50c | 2015-09-16 10:58:16 -0500 | [diff] [blame] | 28 | def event_log_signal_handler(self,priority,msg,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 | 8abb50c | 2015-09-16 10:58:16 -0500 | [diff] [blame] | 35 | |
| 36 | json_dump = json.dumps(message) |
| 37 | print "EVENT_LOG: "+json_dump |
| 38 | syslog.openlog('[OpenBmc]',logoption=syslog.LOG_PID) |
| 39 | syslog.syslog(priority,json_dump) |
| 40 | syslog.closelog() |
| 41 | |
| 42 | |
| 43 | |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 44 | |
| 45 | if __name__ == '__main__': |
| 46 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 47 | |
| 48 | bus = dbus.SessionBus() |
| 49 | name = dbus.service.BusName(DBUS_NAME, bus) |
| 50 | obj = EventLogger(bus, OBJ_NAME) |
Norman James | 6f8d042 | 2015-09-14 18:48:00 -0500 | [diff] [blame] | 51 | mainloop = gobject.MainLoop() |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 52 | |
| 53 | print "Running EventLogger" |
| 54 | mainloop.run() |
| 55 | |