blob: 95edfb89ae551c526f045581f159697cee4ff858 [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 James8abb50c2015-09-16 10:58:16 -050028 def event_log_signal_handler(self,priority,msg,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 James8abb50c2015-09-16 10:58:16 -050035
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 James90baede2015-09-02 20:32:49 -050044
45if __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 James6f8d0422015-09-14 18:48:00 -050051 mainloop = gobject.MainLoop()
Norman James90baede2015-09-02 20:32:49 -050052
53 print "Running EventLogger"
54 mainloop.run()
55