Enhance Telegram alert template: add handling for resolved alerts and improve message formatting
This commit is contained in:
@@ -1,4 +1,16 @@
|
|||||||
{{/* Always produce a non-empty message. Handles single or multiple firing alerts and missing username. */}}
|
{{- /* Resolved alerts (if any) */ -}}
|
||||||
|
{{- if gt (len .Alerts.Resolved) 1 -}}
|
||||||
|
<b>{{ len .Alerts.Resolved }} logins resolved</b> on {{ with .CommonLabels.cluster }}<b>{{ . }}</b>{{ else }}<b>unknown host</b>{{ end }}:
|
||||||
|
{{- range .Alerts.Resolved }}
|
||||||
|
• {{ with .Labels.username }}<b>{{ . }}</b>{{ else }}<i>unknown</i>{{ end }} — Source: <code>{{ with .Labels.source }}{{ . }}{{ else }}?{{ end }}</code>{{ with .Labels.method }}, Method: <code>{{ . }}</code>{{ else }}, Method: <code>?</code>{{ end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else if eq (len .Alerts.Resolved) 1 -}}
|
||||||
|
{{ $a := index .Alerts.Resolved 0 -}}
|
||||||
|
<b>Resolved login:</b> {{ with $a.Labels.username }}<b>{{ . }}</b>{{ else }}<i>unknown</i>{{ end }} on <b>{{ $a.Labels.cluster }}</b>
|
||||||
|
Source: <code>{{ with $a.Labels.source }}{{ . }}{{ else }}?{{ end }}</code>{{ with $a.Labels.method }}, Method: <code>{{ . }}</code>{{ else }}, Method: <code>?</code>{{ end }}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- /* Firing alerts (original logic) */ -}}
|
||||||
{{ if gt (len .Alerts.Firing) 1 -}}
|
{{ if gt (len .Alerts.Firing) 1 -}}
|
||||||
<b>{{ len .Alerts.Firing }} logins</b> on {{ with .CommonLabels.cluster }}<b>{{ . }}</b>{{ else }}<b>unknown host</b>{{ end }}:
|
<b>{{ len .Alerts.Firing }} logins</b> on {{ with .CommonLabels.cluster }}<b>{{ . }}</b>{{ else }}<b>unknown host</b>{{ end }}:
|
||||||
{{- range .Alerts.Firing }}
|
{{- range .Alerts.Firing }}
|
||||||
@@ -9,5 +21,8 @@
|
|||||||
<b>Login:</b> {{ with $a.Labels.username }}<b>{{ . }}</b>{{ else }}<i>unknown</i>{{ end }} on <b>{{ $a.Labels.cluster }}</b>
|
<b>Login:</b> {{ with $a.Labels.username }}<b>{{ . }}</b>{{ else }}<i>unknown</i>{{ end }} on <b>{{ $a.Labels.cluster }}</b>
|
||||||
Source: <code>{{ with $a.Labels.source }}{{ . }}{{ else }}?{{ end }}</code>{{ with $a.Labels.method }}, Method: <code>{{ . }}</code>{{ else }}, Method: <code>?</code>{{ end }}
|
Source: <code>{{ with $a.Labels.source }}{{ . }}{{ else }}?{{ end }}</code>{{ with $a.Labels.method }}, Method: <code>{{ . }}</code>{{ else }}, Method: <code>?</code>{{ end }}
|
||||||
{{ else -}}
|
{{ else -}}
|
||||||
|
{{- /* If there were resolved alerts above this will still show when no firing alerts exist. */ -}}
|
||||||
|
{{ if eq (len .Alerts.Resolved) 0 -}}
|
||||||
<b>Login detected</b> — details unavailable.
|
<b>Login detected</b> — details unavailable.
|
||||||
|
{{ end -}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
Reference in New Issue
Block a user