[tor-commits] [nyx/master] Validate startup.events
atagar at torproject.org
atagar at torproject.org
Wed Jun 8 17:26:59 UTC 2016
commit fc08a1a26c5b4ad85b30e4cc4c2fb3e6cf67201b
Author: Sambuddha Basu <sambuddhabasu1 at gmail.com>
Date: Tue Jun 7 21:58:50 2016 -0700
Validate startup.events
---
nyx/panel/log.py | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/nyx/panel/log.py b/nyx/panel/log.py
index 5fd0cdf..482b567 100644
--- a/nyx/panel/log.py
+++ b/nyx/panel/log.py
@@ -31,6 +31,27 @@ def conf_handler(key, value):
return max(1000, value)
+def validate_events(events):
+ """
+ Check whether the events are any one of Tor runlevels, Nyx runlevels or
+ Tor events. If not, return the default events.
+ """
+ valid_events = tor_controller().get_info('events/names').split()
+ accepted_events, invalid_events = set(), set()
+
+ events = events.split(',')
+ for event in events:
+ if event in valid_events:
+ accepted_events.update([event])
+ else:
+ invalid_events.update([event])
+
+ if invalid_events:
+ return ['NOTICE', 'WARN', 'ERR', 'NYX_NOTICE', 'NYX_WARNING', 'NYX_ERROR']
+ else:
+ return accepted_events
+
+
CONFIG = conf.config_dict('nyx', {
'attr.log_color': {},
'cache.log_panel.size': 1000,
@@ -68,7 +89,7 @@ class LogPanel(nyx.panel.DaemonPanel):
def __init__(self):
nyx.panel.DaemonPanel.__init__(self, 'log', UPDATE_RATE)
- logged_events = CONFIG['startup.events'].split(',')
+ logged_events = validate_events(CONFIG['startup.events'])
self._event_log = nyx.log.LogGroup(CONFIG['cache.log_panel.size'], group_by_day = True)
self._event_log_paused = None
self._event_types = nyx.log.listen_for_events(self._register_tor_event, logged_events)
More information about the tor-commits
mailing list