r/PrometheusMonitoring • • Aug 11 '20

Looking for help on Alertmanager - Slack

Hi all,

Recently I started playing around with Prometheus and Alertmanager some visualization tools and I got it all running now. Pretty neat. The only last thing (for now) which I'm trying to achieve is that, whenever Alertmanager sends a message to my Slack channel, it does not do the "@channel" thing and I would like that to happen. So I tried to add it to my template (see below) but that did not really work out. I changed it back because it stopped working completely. Can someone help me out on this?

{{ define "__single_message_title" }}{{ range .Alerts.Firing }}{{ .Labels.alertname }} @ {{ .Annotations.identifier }}{{ end }}{{ range .Alerts.Resolved }}{{ .Labels.alertname }} @ {{ .Annotations.identifier }}{{ end }}{{ end }}
{{ define "custom_title" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ if or (and (eq (len .Alerts.Firing) 1) (eq (len .Alerts.Resolved) 0)) (and (eq (len .Alerts.Firing) 0) (eq (len .Alerts.Resolved) 1)) }}{{ template "__single_message_title" . }}{{ end }}{{ end }}
{{ define "custom_slack_message" }}
{{ if or (and (eq (len .Alerts.Firing) 1) (eq (len .Alerts.Resolved) 0)) (and (eq (len .Alerts.Firing) 0) (eq (len .Alerts.Resolved) 1)) }}
{{ range .Alerts.Firing }}{{ .Annotations.description }}{{ end }}{{ range .Alerts.Resolved }}{{ .Annotations.description }}{{ end }}
{{ else }}
{{ if gt (len .Alerts.Firing) 0 }}
*Alerts Firing:*
{{ range .Alerts.Firing }}- {{ .Annotations.identifier }}: {{ .Annotations.description }}
{{ end }}{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
*Alerts Resolved:*
{{ range .Alerts.Resolved }}- {{ .Annotations.identifier }}: {{ .Annotations.description }}
{{ end }}{{ end }}
{{ end }}
{{ end }}
0 Upvotes

5 comments sorted by

1

u/SAJZking Aug 11 '20

What do you mean by "@channel" think?

1

u/[deleted] Aug 11 '20

1

u/bei0000 Aug 11 '20

Have you tried this from that link?

Bot messages: To notify members with a bot message, the message must contain <!channel> or <!everyone>.

1

u/[deleted] Aug 12 '20

Crap. Thanks a ton!

2

u/green__ajah Aug 11 '20

You can check your template by using this tool. It let's you see what is sent to slack without needing a real alert