Commit 1038df60 authored by erdnaxe's avatar erdnaxe 🎇 Committed by Benjamin Graillot

[prometheus] meilleure gestion des alertes

parent 09de6c53
......@@ -8,11 +8,12 @@ import github
import wiki
import news
import phabricator
import prometheus
import ml
MAIL_SOURCES = [wiki.Wiki(), phabricator.Phabricator(), ml.Ml(), github.Github()]
SOURCES = [source.MailSources(MAIL_SOURCES), news.News()]
SOURCES = [source.MailSources(MAIL_SOURCES), news.News(), prometheus.Prometheus()]
if __name__ == "__main__":
with open(config.socket_path, 'w') as fifo:
......
......@@ -16,9 +16,27 @@ def foo():
print(notif)
data = json.loads(notif)
push_update = app.config['push_update']
push_update(data['commonLabels']['instance'], '\x0310{alertname}\x03 \x033{instance}\x03 {job}\x03'.format(**data['commonLabels']))
#push_update(data['commonLabels']['instance'], '\x0310{alertname}\x03 \x033{instance}\x03 {job}\x03'.format(**data['commonLabels']))
for alert in data['alerts']:
push_update(alert['labels']['instance'], '\x0310{alertname}\x03 \x033{instance}\x03 {job}\x03'.format(**alert['labels']))
# Retrieve metadata
status = alert.get('status', 'firing')
labels = alert.get('labels', {})
instance = labels.get('instance', '')
alertname = labels.get('alertname', '')
severity = labels.get('severity', 'unknown')
annotations = alert.get('annotations', {})
summary = annotations.get('summary', '')
description = annotations.get('description', '')
if status == 'resolved':
message = '\x0310{alertname}\x03 \x033resolved\x0315 {summary}\x03'.format(alertname=alertname, severity=severity, summary=summary)
push_update(instance, message)
else:
message = '\x0310{alertname}\x03 \x034{severity}\x03 {summary}\x03'.format(alertname=alertname, severity=severity, summary=summary)
push_update(instance, message)
if description:
push_update(instance, description)
return "OK"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment