add option to filter alerts by component
This commit is contained in:
parent
52cb7b2a90
commit
1088341426
3 changed files with 23 additions and 6 deletions
1
conf.py
1
conf.py
|
@ -45,6 +45,7 @@ def load_and_validate_config(path):
|
||||||
),
|
),
|
||||||
alerts=ConfigWrapper(
|
alerts=ConfigWrapper(
|
||||||
brightness=max(int(config.get('alerts', {}).get('brightness', 255)), 10),
|
brightness=max(int(config.get('alerts', {}).get('brightness', 255)), 10),
|
||||||
|
filters=sorted(config.get('alerts', {}).get('filters', set())),
|
||||||
),
|
),
|
||||||
rainbow=ConfigWrapper(
|
rainbow=ConfigWrapper(
|
||||||
enable=bool(config.get('rainbow', {}).get('enable', True) is True),
|
enable=bool(config.get('rainbow', {}).get('enable', True) is True),
|
||||||
|
|
|
@ -30,6 +30,11 @@ universe = 1
|
||||||
# rainbow brightness (see below).
|
# rainbow brightness (see below).
|
||||||
brightness = 255
|
brightness = 255
|
||||||
|
|
||||||
|
# Filter by specific components. If this list is non-empty, the message
|
||||||
|
# will get shown if atleast one of these filters match. The filters are
|
||||||
|
# applied by using re.search() on the component part of the message.
|
||||||
|
filters = []
|
||||||
|
|
||||||
|
|
||||||
[rainbow]
|
[rainbow]
|
||||||
# Wether to enable the rainbow 'no alerts' loop. If false, all other
|
# Wether to enable the rainbow 'no alerts' loop. If false, all other
|
||||||
|
|
|
@ -46,6 +46,15 @@ class MQTTQueue:
|
||||||
|
|
||||||
text = re.sub(r'\<[a-z\/]+\>', '', data['msg'])
|
text = re.sub(r'\<[a-z\/]+\>', '', data['msg'])
|
||||||
|
|
||||||
|
add_to_queue = True
|
||||||
|
if self.config.alerts.filters:
|
||||||
|
add_to_queue = False
|
||||||
|
for f in self.config.alerts.filters:
|
||||||
|
if re.search(f, data['component'], re.IGNORECASE):
|
||||||
|
add_to_queue = True
|
||||||
|
break # no point in searching further
|
||||||
|
|
||||||
|
if add_to_queue:
|
||||||
self.queue.put(
|
self.queue.put(
|
||||||
(
|
(
|
||||||
data['level'].lower(),
|
data['level'].lower(),
|
||||||
|
@ -53,5 +62,7 @@ class MQTTQueue:
|
||||||
text,
|
text,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
LOG.info(f'Ignoring message for {data["component"]} because it was filtered')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.exception(msg.payload)
|
LOG.exception(msg.payload)
|
||||||
|
|
Loading…
Reference in a new issue