add option to filter alerts by component

This commit is contained in:
Franzi 2024-02-11 14:31:34 +01:00
parent 52cb7b2a90
commit 1088341426
Signed by: kunsi
GPG key ID: 12E3D2136B818350
3 changed files with 23 additions and 6 deletions

View file

@ -45,6 +45,7 @@ def load_and_validate_config(path):
),
alerts=ConfigWrapper(
brightness=max(int(config.get('alerts', {}).get('brightness', 255)), 10),
filters=sorted(config.get('alerts', {}).get('filters', set())),
),
rainbow=ConfigWrapper(
enable=bool(config.get('rainbow', {}).get('enable', True) is True),

View file

@ -30,6 +30,11 @@ universe = 1
# rainbow brightness (see below).
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]
# Wether to enable the rainbow 'no alerts' loop. If false, all other

View file

@ -46,12 +46,23 @@ class MQTTQueue:
text = re.sub(r'\<[a-z\/]+\>', '', data['msg'])
self.queue.put(
(
data['level'].lower(),
data['component'],
text,
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(
(
data['level'].lower(),
data['component'],
text,
)
)
)
else:
LOG.info(f'Ignoring message for {data["component"]} because it was filtered')
except Exception as e:
LOG.exception(msg.payload)