Support Grafana v9.x messages, fixes #29

This commit is contained in:
Sven Seeberg 2022-09-07 15:01:45 +02:00
parent 3288c3ff5a
commit e139c3a61b
No known key found for this signature in database
GPG key ID: 29559DD5A83806B5
4 changed files with 157 additions and 1 deletions

View file

@ -4,8 +4,10 @@ import re
def grafana(data, headers):
"""Pretty-print a grafana notification."""
"""Pretty-print a Grafana (version 8 and older) notification."""
text = ""
if "ruleName" not in data and "alerts" in data:
return grafana_9x(data, headers)
if "title" in data:
text = "#### " + data["title"] + "\n"
if "message" in data:
@ -17,6 +19,17 @@ def grafana(data, headers):
return data
def grafana_9x(data, headers):
"""Pretty-print a Grafana newer than v9.x notification."""
text = ""
if "title" in data:
text = "#### " + data["title"] + "\n"
if "message" in data:
text = text + data["message"].replace("\n", "\n\n") + "\n\n"
data["body"] = text
return data
def github(data, headers):
"""Pretty-print a github notification."""
# TODO: Write nice useful formatters. This is only an example.