How to remove grafana labels when alerts are send via external alertmanager?

Currently, I use external alertmanager to send email notifications. When alert is send, a mail arrive and in labels section are some additional things that were added by grafana, e.g.:

Labels
alertname = Out of disk space on VM
__ alert_rule_namespace_uid __ = Yj9eVzC7z
__ alert_rule_uid __ = 0k3Cgijnz
instance = 1.2.3.4:9182
job = Windows Nodes
name = Windows Share
volume = E:

To display this section in email, I use following statement:
{{ range .Alerts.Firing }}{{ range .Labels.SortedPairs }}{{ .Name }} = {{ .Value }}{{ end }}{{ end}}

Is it possible to ommit somehow these key that were added by grafana (alert_rule_namespace_uid, alert_rule_uid) ? I saw Notification template reference (KV methods) contains something like Remove option, but I’m not sure how should look like the go templating code.

I’ve tried to create my own silenceurl, but if link contain these two keys, nothing is shown on grafana side (I must to delete them directly on web so affected alert instance will be shown).

welcome to the :grafana: community @mariachini!

Alert templates have changed recently, to give you the right information can you share:

  • Grafana version
  • Type of grafana alerting (Unified Alerting (default in Grafana 9) or Legacy alerting)?
  • Are you using message templates in Grafana?

Hi, I have the same question and it is related to the usage of the Remove method for the SortedPairs.

We can loop over sorted pairs and display them all like this:

{{ range .Labels.SortedPairs }}{{ .Name }}: {{ .Value }}{{ end }}

This shows all labels however. Let’s say I want a specific set of labels. According to the docs we can use the Remove method to remove certain keys from the SortedPairs. It requires a list as input. But how does one use this method inside the Grafana templating language?

I am on Grafana 9.1.0 and using Unified Alerting.

1 Like

I wonder about the same question, would be nice to get an example of how to use Remove function with arbitrary list of values.