I use grafana 9.3.2 and want add short alerts to slack.
Now I created this config:
{{ define "myalert" }}
[{{.Status}}] {{ .Labels.alertname }}
{{ range .Labels.SortedPairs }}
{{if eq .Name "ip"}} {{ .Name }}: {{ .Value }} {{end}}
{{ end }}
{{ end }}
{{ if gt (len .Alerts.Firing) 0 }}
{{ len .Alerts.Firing }} firing:
{{ range .Alerts.Firing }} {{ template "myalert" .}} {{ end }}
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
{{ len .Alerts.Resolved }} resolved:
{{ range .Alerts.Resolved }} {{ template "myalert" .}} {{ end }}
{{ end }}
And I had this result:
11 firing:
[firing] setup_unavailble
ip: 192.168.201.40
[firing] setup_unavailble
ip: 192.168.201.41
[firing] setup_unavailble
ip: 192.168.202.40
[firing] setup_unavailble
ip: 192.168.202.41
[firing] setup_unavailble
ip: 192.168.222.41
[firing] setup_unavailble
ip: 192.168.223.40
[firing] setup_unavailble
ip: 192.168.223.41
[firing] setup_unavailble
ip: 192.168.224.40
[firing] setup_unavailble
ip: 192.168.226.44
[firing] setup_unavailble
ip: 192.168.228.40
[firing] setup_unavailble
ip: 192.168.228.41
8 resolved:
[resolved] setup_unavailble
ip: 192.168.224.41
[resolved] setup_unavailble
ip: 192.168.224.42
[resolved] setup_unavailble
ip: 192.168.225.1
[resolved] setup_unavailble
ip: 192.168.225.40
[resolved] setup_unavailble
ip: 192.168.225.41
[resolved] setup_unavailble
ip: 192.168.225.42
[resolved] setup_unavailble
ip: 192.168.226.1
[resolved] setup_unavailble
ip: 192.168.226.40
How I can remove this empty lines?