How to disable the annotaion description from the alerts in Prometheus

10/16/2018

I have a running Prometheus and configured alerts by alertmanager to my slack. and I am able to get the triggered alerts with its Description. For that I have added the following in my config file.

      Summary: '{{ range .Alerts }}{{ .Annotations.summary }} {{ end }}'

      Description: '{{ range .Alerts }}{{ .Annotations.description }} {{ end }}'

But now my issue is, the same description is generating, when the alerts are resolved. Is there any way to disable the Alert description for the resolved message?

-- manu thankachan
kubernetes
prometheus
prometheus-alertmanager

1 Answer

10/16/2018

You will need to use the template to check the status of the alert (whether it is firing or resolved), and then set the content of the message conditionally based on that.

For example, the title field of my alerts gets set like this:

{{ define "templatenamehere.title" }}
  {{- .Status | title }}
  {{- if eq .Status "firing" }} {{ .Alerts.Firing | len }}{{ else }} {{ .Alerts.Resolved | len }}{{ end }}
  {{- printf " - " }}
  {{- if gt (len .Alerts.Firing) 1 }}
  {{- .CommonLabels.alertname }}
  {{- else }}
  {{- .CommonAnnotations.summary }}
  {{- end }}
{{- end }}
-- wbh1
Source: StackOverflow