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 <xiaoyin_c@qq.com>
This commit is contained in:
Ryan Yin
2026-07-24 22:57:13 +08:00
parent 35d41a4391
commit b6a7a8f49b
+12 -13
View File
@@ -128,25 +128,24 @@
# in a group and keep the fields minimal (no full label dump).
message = ''
{{- if eq .Status "firing" }}
🟡 <b></b> {{ .CommonLabels.alertname }} [{{ index .CommonLabels "severity" | title }}] ( {{ len .Alerts }} )
🟡 <b></b> [{{ .CommonLabels.severity | title }}] <b>{{ .CommonLabels.alertname }}</b> ( {{ len .Alerts }} )
{{- else }}
🟢 <b></b> {{ .CommonLabels.alertname }} [{{ index .CommonLabels "severity" | title }}]
🟢 <b></b> [{{ .CommonLabels.severity | title }}] <b>{{ .CommonLabels.alertname }}</b>
{{- end }}
<b></b>: {{ .CommonLabels.alertgroup }}
<b>Cluster</b>: {{ with .CommonLabels.cluster }}{{ . }}{{ else }}N/A{{ end }}
<b>Env</b>: {{ with .CommonLabels.env }}{{ . }}{{ else }}N/A{{ end }}
<b>Namespace</b>: {{ with .CommonLabels.namespace }}{{ . }}{{ else }}N/A{{ end }}
{{- range $i, $a := .Alerts }}
{{- if lt $i 5 }}
📊 <b>:</b>
<b></b>: {{ $a.Labels.alertgroup }}
<b></b>: {{ if eq $a.Labels.severity "critical" }}🔴{{ else }}🟡 {{ end }} {{ $a.Labels.severity | title }}
<b></b>: {{ with $a.Labels.instance }}{{ . }}{{ else }}N/A{{ end }}
<b>Pod</b>: {{ with $a.Labels.pod }}{{ . }}{{ else }}N/A{{ end }}
<b></b>: <a href="{{ $a.GeneratorURL }}">Grafana Explore</a>
<b></b>: {{ with $a.Annotations.value }}{{ . }}{{ else }}N/A{{ end }}
<b>Env</b>: {{ with $a.Labels.env }}{{ . }}{{ else }}N/A{{ end }}
<b>Cluster</b>: {{ with $a.Labels.cluster }}{{ . }}{{ else }}N/A{{ end }}
<b>Namespace</b>: {{ with $a.Labels.namespace }}{{ . }}{{ else }}N/A{{ end }}
<b></b>: {{ $a.StartsAt.Format "2006-01-02 15:04:05" }}
📌 {{ with $a.Annotations.summary }}<b>{{ . }}</b>{{ else }}<b>{{ $a.Labels.instance }}</b>{{ end }}
{{- with $a.Labels.nodename }}
🏠 {{ . }}
{{- end }}
🔗 <a href="{{ $a.GeneratorURL }}">Grafana Explore</a> · {{ $a.StartsAt.Format "2006-01-02 15:04:05" }}
{{- end }}
{{- end }}
{{- if gt (len .Alerts) 5 }}