blob: e36f9283fe83a92a472025e205b75cda5fdb9b5f [file] [log] [blame]
Norman James90baede2015-09-02 20:32:49 -05001#!/usr/bin/env python
2
3import sys
Norman James8abb50c2015-09-16 10:58:16 -05004import datetime
5import time
Norman James5d78b4d2015-09-05 13:34:34 -05006import syslog
7import json
Norman James6f8d0422015-09-14 18:48:00 -05008import gobject
Norman James90baede2015-09-02 20:32:49 -05009import dbus
10import dbus.service
11import dbus.mainloop.glib
Norman James32e74e22015-09-15 21:28:06 -050012import Openbmc
Norman James90baede2015-09-02 20:32:49 -050013
14DBUS_NAME = 'org.openbmc.loggers.EventLogger'
15OBJ_NAME = '/org/openbmc/loggers/EventLogger/'+sys.argv[1]
16
Norman James8abb50c2015-09-16 10:58:16 -050017
Norman James90baede2015-09-02 20:32:49 -050018class EventLogger(dbus.service.Object):
19 def __init__(self,bus,name):
20 dbus.service.Object.__init__(self,bus,name)
21 bus = dbus.SessionBus()
Norman James90baede2015-09-02 20:32:49 -050022 bus.add_signal_receiver(self.event_log_signal_handler,
Norman James32e74e22015-09-15 21:28:06 -050023 dbus_interface = "org.openbmc.EventLog",
24 signal_name = "EventLog",
25 path_keyword='path')
Norman James90baede2015-09-02 20:32:49 -050026
27 ## Signal handler
Norman James88872672015-09-21 16:51:35 -050028 def event_log_signal_handler(self,priority,msg,rc,path = None):
Norman James32e74e22015-09-15 21:28:06 -050029 message = {}
Norman James8abb50c2015-09-16 10:58:16 -050030 ts = time.time()
31
32 message['priority'] = priority
Norman James32e74e22015-09-15 21:28:06 -050033 message['object_path'] = path
Norman James32e74e22015-09-15 21:28:06 -050034 message['message'] = msg
Norman James88872672015-09-21 16:51:35 -050035 message['rc'] = rc
Norman James8abb50c2015-09-16 10:58:16 -050036
37 json_dump = json.dumps(message)
38 print "EVENT_LOG: "+json_dump
Norman James2d1ee892015-09-16 23:13:45 -050039 syslog.openlog('OpenBmc',logoption=syslog.LOG_PID)
Norman James8abb50c2015-09-16 10:58:16 -050040 syslog.syslog(priority,json_dump)
41 syslog.closelog()
42
43
44
Norman James90baede2015-09-02 20:32:49 -050045
46if __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 James6f8d0422015-09-14 18:48:00 -050052 mainloop = gobject.MainLoop()
Norman James90baede2015-09-02 20:32:49 -050053
54 print "Running EventLogger"
55 mainloop.run()
56