feat: update alertmanager message template

This commit is contained in:
Ryan Yin
2025-09-18 18:38:41 +08:00
parent 070aeae8db
commit 95abfef3a9

View File

@@ -17,6 +17,11 @@
rule = [ rule = [
"${./alert_rules}/*.yml" "${./alert_rules}/*.yml"
]; ];
# https://docs.victoriametrics.com/victoriametrics/vmalert/#link-to-alert-source
# Set this two args to generate the correct `.GeneratorURL`
"external.url" = "https://grafana.writefor.fun";
"external.alert.source" =
''explore?left={"datasource":"{{ if eq .Type \"vlogs\" }}VictoriaLogs{{ else }}VictoriaMetrics{{ end }}","queries":[{"expr":{{ .Expr|jsonEscape|queryEscape }},"refId":"A"}],"range":{"from":"{{ .ActiveAt.UnixMilli }}","to":"now"}}'';
}; };
}; };
@@ -58,9 +63,9 @@
"type" "type"
"host" "host"
]; ];
group_wait = "5m"; group_wait = "3m"; # wait for other alerts to "group by" before send notification
group_interval = "5m"; group_interval = "5m"; # wait for an interval, before send a new alert in the same group
repeat_interval = "4h"; repeat_interval = "5h"; # avoiding repeating reminders too frequently
} }
# { # {
# # Route only prod env's critical alerts to email (most severe alerts) # # Route only prod env's critical alerts to email (most severe alerts)
@@ -102,28 +107,30 @@
send_resolved = true; send_resolved = true;
# Disable notifications for resolved alerts # Disable notifications for resolved alerts
disable_notifications = false; disable_notifications = false;
# Parse mode for the message # Telegram's MarkdownV2 & Markdown are all very painful, we use html instead.
parse_mode = "Markdown"; # https://core.telegram.org/bots/api#formatting-options
parse_mode = "HTML";
# Message template # Message template
message = '' message = ''
*Alert:* {{ .GroupLabels.alertname }} {{- if eq .Status "firing" }}
*Status:* {{ .Status }} 🟡 <b></b> {{ .CommonLabels.alertname }} [{{ index .CommonLabels "severity" | title }}]
*Severity:* {{ .CommonLabels.severity }} {{- else }}
{{ if .GroupLabels.namespace }}*Namespace:* {{ .GroupLabels.namespace }}{{ end }} 🟢 <b></b> {{ .CommonLabels.alertname }} [{{ index .CommonLabels "severity" | title }}]
{{ if .GroupLabels.pod }}*Pod:* {{ .GroupLabels.pod }}{{ end }} {{- end }}
{{ if .GroupLabels.job }}*Job:* {{ .GroupLabels.job }}{{ end }}
{{ if .GroupLabels.host }}*Host:* {{ .GroupLabels.host }}{{ end }}
{{ range .Alerts }} {{- range .Alerts }}
*Alert:* {{ .Annotations.summary }}
*Description:* {{ .Annotations.description }} 📊 <b>:</b>
{{ if .Labels.instance }}*Instance:* {{ .Labels.instance }}{{ end }} <b></b>: {{ .Labels.alertgroup }}
{{ if .Labels.container }}*Container:* {{ .Labels.container }}{{ end }} <b></b>: {{ if eq .Labels.severity "critical" }}🔴{{ else }}🟡 {{ end }} {{ .Labels.severity | title }}
*Started:* {{ .StartsAt.Format "2006-01-02 15:04:05" }} <b></b>: <a href="{{ .GeneratorURL }}">Grafana Explore</a>
{{ if .EndsAt }} <b></b>: {{ with .Annotations.value }}{{ . }}{{ else }}N/A{{ end }}
*Ended:* {{ .EndsAt.Format "2006-01-02 15:04:05" }} <b>Env</b>: {{ with .Labels.env }}{{ . }}{{ else }}N/A{{ end }}
{{ end }} <b>Cluster</b>: {{ with .Labels.cluster }}{{ . }}{{ else }}N/A{{ end }}
{{ end }} <b>Namespace</b>: {{ with .Labels.namespace }}{{ . }}{{ else }}N/A{{ end }}
<b></b>: {{ range .Labels.SortedPairs }}{{ .Name }}={{ .Value }},{{ end }}
<b></b>: {{ .StartsAt.Format "2006-01-02 15:04:05" }}
{{- end }}
''; '';
} }
]; ];