diff --git a/terraform/apps/prod-01/resources/telegram.tpl b/terraform/apps/prod-01/resources/telegram.tpl index 88a6606..bdcfbfa 100644 --- a/terraform/apps/prod-01/resources/telegram.tpl +++ b/terraform/apps/prod-01/resources/telegram.tpl @@ -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 -}} +{{ len .Alerts.Resolved }} logins resolved on {{ with .CommonLabels.cluster }}{{ . }}{{ else }}unknown host{{ end }}: +{{- range .Alerts.Resolved }} +• {{ with .Labels.username }}{{ . }}{{ else }}unknown{{ end }} — Source: {{ with .Labels.source }}{{ . }}{{ else }}?{{ end }}{{ with .Labels.method }}, Method: {{ . }}{{ else }}, Method: ?{{ end }} +{{- end }} +{{- else if eq (len .Alerts.Resolved) 1 -}} +{{ $a := index .Alerts.Resolved 0 -}} +Resolved login: {{ with $a.Labels.username }}{{ . }}{{ else }}unknown{{ end }} on {{ $a.Labels.cluster }} +Source: {{ with $a.Labels.source }}{{ . }}{{ else }}?{{ end }}{{ with $a.Labels.method }}, Method: {{ . }}{{ else }}, Method: ?{{ end }} +{{- end -}} + +{{- /* Firing alerts (original logic) */ -}} {{ if gt (len .Alerts.Firing) 1 -}} {{ len .Alerts.Firing }} logins on {{ with .CommonLabels.cluster }}{{ . }}{{ else }}unknown host{{ end }}: {{- range .Alerts.Firing }} @@ -9,5 +21,8 @@ Login: {{ with $a.Labels.username }}{{ . }}{{ else }}unknown{{ end }} on {{ $a.Labels.cluster }} Source: {{ with $a.Labels.source }}{{ . }}{{ else }}?{{ end }}{{ with $a.Labels.method }}, Method: {{ . }}{{ else }}, Method: ?{{ end }} {{ else -}} +{{- /* If there were resolved alerts above this will still show when no firing alerts exist. */ -}} +{{ if eq (len .Alerts.Resolved) 0 -}} Login detected — details unavailable. +{{ end -}} {{ end -}} \ No newline at end of file