Hi, I was wondering if it's possible to add an if statement to an alertmanager.yml. I'm thinking of something like this:
receivers:
- name: blackbox
slack_configs:
- send_resolved: true
channel: prometheus
text: "{{if .Status eq 'firing'}} {{ .CommonLabels.instance }} is down! \nPlease contact the team right away! {{else}} {{ .CommonLabels.instance }} is back up again! You can now relax! {{end}}"
But it seems that alertmanager does not recognize 'firing' word.
Have you tried turning your single quotes into regular quotes (")?
Tried changing the text to:
text: '{{if .Status eq "firing"}} {{ .CommonLabels.instance }} is down! \nPlease contact the team right away! {{else}} {{ .CommonLabels.instance }} is back up again! You can now relax! {{end}}'
But I ended up getting this error:
33mWARN[0m[0200] Notify attempt 9 failed: template: :1:5: executing "" at <.Status>: Status has arguments but cannot be invoked as function [33msource[0m=notify.go:193
Go templates are a prefix language. Try eq .Status "firing"
Pardon my ignorance but I just started learning go templates. Much more haven't learned go language yet. Anyhow, should I replace the if statement with the one you are giving? What will happened to the else statement?
text: '{{eq .Status "firing"}} {{ .CommonLabels.instance }} is down! \nPlease contact the team right away! {{else}} {{ .CommonLabels.instance }} is back up again! You can now relax! {{end}}'
Is that the correct format?
Brian just meant that you should swap eq and .Status – not to drop the if.
So {{ if eq .Status "firing" }}.
Assuming this is resolved.
Most helpful comment
Go templates are a prefix language. Try
eq .Status "firing"