matrix-webhook/matrix_webhook/formatters.py
Guilhem Saurel 2d232fe1f7 add grafana formatter
This was initially designed and implemented in #4

Co-authored-by: Sven Seeberg <mail@sven-seeberg.de>
2021-08-01 13:19:58 +02:00

15 lines
458 B
Python

"""Formatters for matrix webhook."""
def grafana(data):
"""Pretty-print a grafana notification."""
text = ""
if "title" in data:
text = "### " + data["title"] + "\n"
if "message" in data:
text = text + data["message"] + "\n\n"
if "evalMatches" in data:
for match in data["evalMatches"]:
text = text + "* " + match["metric"] + ": " + str(match["value"]) + "\n"
data["body"] = text
return data