Skip to content

Commit 9580368

Browse files
committed
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 <[email protected]>
1 parent 6e1ca53 commit 9580368

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

module/obmc/wsgi/apps/rest_dbus.py

+41
Original file line numberDiff line numberDiff line change
@@ -1518,9 +1518,20 @@ def __init__(self, suppress_json_logging, callback, app):
15181518
self.suppress_json_logging = suppress_json_logging
15191519
self.callback = callback
15201520
self.app = app
1521+
self.logging_enabled = None
1522+
self.bus = dbus.SystemBus()
1523+
self.dbus_path = '/xyz/openbmc_project/logging/rest_api_logs'
1524+
self.bus.add_signal_receiver(
1525+
self.properties_changed_handler,
1526+
dbus_interface=dbus.PROPERTIES_IFACE,
1527+
signal_name='PropertiesChanged',
1528+
path=self.dbus_path)
1529+
Greenlet.spawn(self.dbus_loop)
15211530

15221531
def __call__(self, *a, **kw):
15231532
resp = self.callback(*a, **kw)
1533+
if not self.enabled():
1534+
return resp;
15241535
if request.method == 'GET':
15251536
return resp;
15261537
json = request.json
@@ -1542,6 +1553,36 @@ def __call__(self, *a, **kw):
15421553
status=response.status))
15431554
return resp;
15441555

1556+
def enabled(self):
1557+
if self.logging_enabled is None:
1558+
try:
1559+
obj = self.bus.get_object(
1560+
'xyz.openbmc_project.Settings',
1561+
self.dbus_path)
1562+
iface = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
1563+
logging_enabled = iface.Get(
1564+
'xyz.openbmc_project.Object.Enable',
1565+
'Enabled')
1566+
self.logging_enabled = logging_enabled
1567+
except dbus.exceptions.DBusException:
1568+
self.logging_enabled = False
1569+
return self.logging_enabled
1570+
1571+
def dbus_loop(self):
1572+
loop = gobject.MainLoop()
1573+
gcontext = loop.get_context()
1574+
while loop is not None:
1575+
try:
1576+
if gcontext.pending():
1577+
gcontext.iteration()
1578+
else:
1579+
gevent.sleep(5)
1580+
except Exception as e:
1581+
break
1582+
1583+
def properties_changed_handler(self, interface, new, old, **kw):
1584+
self.logging_enabled = new.values()[0]
1585+
15451586
def apply(self, callback, route):
15461587
cb = route.get_undecorated_callback()
15471588
skip = getattr(

0 commit comments

Comments
 (0)