feat(alertmanager): add more info in notifications

Map status, priority, tags and runbook.
This commit is contained in:
Khue Doan 2024-03-28 17:07:25 +07:00
parent 1dc01c2a82
commit 9438fe32d7

View File

@ -1,8 +1,44 @@
local get_tags(status, severity) =
// https://docs.ntfy.sh/emojis
if status == "resolved" then
["tada"]
else
std.get({
critical: ["rotating_light"],
warning: ["warning"],
info: ["newspaper"],
}, severity, ["question"]);
local get_priority(status, severity) =
// https://docs.ntfy.sh/publish/#message-priority
if status == "resolved" then
2
else
std.get({
critical: 5,
warning: 3,
info: 1,
}, severity, 3);
local get_actions(status, annotations) =
// https://docs.ntfy.sh/publish/#action-buttons
if status == "resolved" || !("runbook_url" in annotations) then
[]
else
[
{
action: "view",
label: "Open runbook",
url: annotations.runbook_url,
},
];
// TODO support multiple alerts
{
"topic": env.NTFY_TOPIC,
"title": body.alerts[0].labels.alertname, // TODO support multiple alerts
"message": body.alerts[0].annotations.description,
"tags": [],
"priority": 3,
"actions": []
topic: env.NTFY_TOPIC,
title: "[" + std.asciiUpper(body.status) + "] " + body.alerts[0].labels.alertname,
message: body.alerts[0].annotations.description,
tags: get_tags(body.status, body.alerts[0].labels.severity),
priority: get_priority(body.status, body.alerts[0].labels.severity),
actions: get_actions(body.status, body.alerts[0].annotations),
}