summaryrefslogtreecommitdiffstats
path: root/module/obmc
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2018-09-07 03:13:59 -0500
committerDeepak Kodihalli <dkodihal@in.ibm.com>2018-09-07 04:42:12 -0500
commit958036845a0bdb15e01a28e62041e4c9fe4559d2 (patch)
tree53f7d6e084c0ef3184f84e4f1b8a7641bbd36f0e /module/obmc
parent6e1ca53062e8f76b16a6739db4eff36e28a8054c (diff)
downloadphosphor-rest-server-958036845a0bdb15e01a28e62041e4c9fe4559d2.tar.gz
phosphor-rest-server-958036845a0bdb15e01a28e62041e4c9fe4559d2.zip
Log requests only if setting is enabled
Log requests only if corresponding setting is turned on. The Logging plug-in reads the D-Bus setting and caches the value. It updates the value if the D-Bus property changes. The D-Bus setting object is at /xyz/openbmc_project/logging/rest_api_logs. Change-Id: If4afcbfd3898d09c6ef31cc7c79a058cb5017769 Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Diffstat (limited to 'module/obmc')
-rw-r--r--module/obmc/wsgi/apps/rest_dbus.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/module/obmc/wsgi/apps/rest_dbus.py b/module/obmc/wsgi/apps/rest_dbus.py
index 1ecacfc..2bfce21 100644
--- a/module/obmc/wsgi/apps/rest_dbus.py
+++ b/module/obmc/wsgi/apps/rest_dbus.py
@@ -1518,9 +1518,20 @@ class LoggingPlugin(object):
self.suppress_json_logging = suppress_json_logging
self.callback = callback
self.app = app
+ self.logging_enabled = None
+ self.bus = dbus.SystemBus()
+ self.dbus_path = '/xyz/openbmc_project/logging/rest_api_logs'
+ self.bus.add_signal_receiver(
+ self.properties_changed_handler,
+ dbus_interface=dbus.PROPERTIES_IFACE,
+ signal_name='PropertiesChanged',
+ path=self.dbus_path)
+ Greenlet.spawn(self.dbus_loop)
def __call__(self, *a, **kw):
resp = self.callback(*a, **kw)
+ if not self.enabled():
+ return resp;
if request.method == 'GET':
return resp;
json = request.json
@@ -1542,6 +1553,36 @@ class LoggingPlugin(object):
status=response.status))
return resp;
+ def enabled(self):
+ if self.logging_enabled is None:
+ try:
+ obj = self.bus.get_object(
+ 'xyz.openbmc_project.Settings',
+ self.dbus_path)
+ iface = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
+ logging_enabled = iface.Get(
+ 'xyz.openbmc_project.Object.Enable',
+ 'Enabled')
+ self.logging_enabled = logging_enabled
+ except dbus.exceptions.DBusException:
+ self.logging_enabled = False
+ return self.logging_enabled
+
+ def dbus_loop(self):
+ loop = gobject.MainLoop()
+ gcontext = loop.get_context()
+ while loop is not None:
+ try:
+ if gcontext.pending():
+ gcontext.iteration()
+ else:
+ gevent.sleep(5)
+ except Exception as e:
+ break
+
+ def properties_changed_handler(self, interface, new, old, **kw):
+ self.logging_enabled = new.values()[0]
+
def apply(self, callback, route):
cb = route.get_undecorated_callback()
skip = getattr(
OpenPOWER on IntegriCloud