From b6a7a8f49b6ec039ff2299093061a429a5d6f791 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Fri, 24 Jul 2026 22:57:13 +0800 Subject: [PATCH] feat(monitoring): restructure telegram alert template for readability - Show group-level labels (alertgroup/cluster/env/namespace) once in the header instead of repeating them per alert. - Use each rule's summary annotation as the per-alert headline (it already carries the distinguishing resource name), falling back to the instance label; show nodename on its own line when present. - Drop the noisy per-alert label dump and the always-N/A value line. Signed-off-by: Ryan Yin --- hosts/idols-aquamarine/monitoring/alert.nix | 25 ++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/hosts/idols-aquamarine/monitoring/alert.nix b/hosts/idols-aquamarine/monitoring/alert.nix index c046c158..8983e17e 100644 --- a/hosts/idols-aquamarine/monitoring/alert.nix +++ b/hosts/idols-aquamarine/monitoring/alert.nix @@ -128,25 +128,24 @@ # in a group and keep the fields minimal (no full label dump). message = '' {{- if eq .Status "firing" }} - 🟡 告警触发 {{ .CommonLabels.alertname }} [{{ index .CommonLabels "severity" | title }}] (共 {{ len .Alerts }} 条) + 🟡 告警触发 [{{ .CommonLabels.severity | title }}] {{ .CommonLabels.alertname }} (共 {{ len .Alerts }} 条) {{- else }} - 🟢 告警恢复 {{ .CommonLabels.alertname }} [{{ index .CommonLabels "severity" | title }}] + 🟢 告警恢复 [{{ .CommonLabels.severity | title }}] {{ .CommonLabels.alertname }} {{- end }} + • 告警组: {{ .CommonLabels.alertgroup }} + • Cluster: {{ with .CommonLabels.cluster }}{{ . }}{{ else }}N/A{{ end }} + • Env: {{ with .CommonLabels.env }}{{ . }}{{ else }}N/A{{ end }} + • Namespace: {{ with .CommonLabels.namespace }}{{ . }}{{ else }}N/A{{ end }} {{- range $i, $a := .Alerts }} {{- if lt $i 5 }} - 📊 详情: - • 告警组: {{ $a.Labels.alertgroup }} - • 等级: {{ if eq $a.Labels.severity "critical" }}🔴{{ else }}🟡 {{ end }} {{ $a.Labels.severity | title }} - • 实例: {{ with $a.Labels.instance }}{{ . }}{{ else }}N/A{{ end }} - • Pod: {{ with $a.Labels.pod }}{{ . }}{{ else }}N/A{{ end }} - • 查询: Grafana Explore - • 触发值: {{ with $a.Annotations.value }}{{ . }}{{ else }}N/A{{ end }} - • Env: {{ with $a.Labels.env }}{{ . }}{{ else }}N/A{{ end }} - • Cluster: {{ with $a.Labels.cluster }}{{ . }}{{ else }}N/A{{ end }} - • Namespace: {{ with $a.Labels.namespace }}{{ . }}{{ else }}N/A{{ end }} - • 触发时间: {{ $a.StartsAt.Format "2006-01-02 15:04:05" }} + ━━━━━━━━ + 📌 {{ with $a.Annotations.summary }}{{ . }}{{ else }}{{ $a.Labels.instance }}{{ end }} + {{- with $a.Labels.nodename }} + 🏠 {{ . }} + {{- end }} + 🔗 Grafana Explore · ⏱ {{ $a.StartsAt.Format "2006-01-02 15:04:05" }} {{- end }} {{- end }} {{- if gt (len .Alerts) 5 }}