Remove Selective Labels : Slack Alerts

80 views
Skip to first unread message

ABHAY VERMA

unread,
Jun 26, 2020, 8:36:34 AM6/26/20
to Prometheus Users
Hi Team,

Is there a way we can drop selective label names when routing alerting to slack, pagerduty etc. In a way, I am trying to find some working examples of Remove func in alertmanager so that while iterating over a range of alert labels, I should be able to drop some pre-defined label names.

I am finding it difficult to dec a list a names and use it with Remove func. I was following this article - link . I am doing something like this to drop unnecessary labels - 

```                {{- range .Labels.SortedPairs -}}
                  {{- if (and (ne .Name "name1") (ne .Name "name2") ) -}}
                  • *{{- .Name }}:* `{{- .Value }}`
                  {{ end -}}
                {{- end -}}
              {{ end }}
```
Is there a better way to implement this using Remove func in alertmanager.

Thanks,

Harald Koch

unread,
Jun 26, 2020, 1:37:05 PM6/26/20
to Prometheus Users
The Go template 'eq' function has a special feature that lets you list multiple arguments, so you can change your if statement to:

    {{-if (eq .Name "name1" "name2" "name3" }}{{ else -}}
    • *{{- .Name }}:* `{{- .Value }}`
    {{ end -}}

As you add more exclusions this gets more concise and easier to read.

--
Harald

ABHAY VERMA

unread,
Jun 26, 2020, 3:38:05 PM6/26/20
to Prometheus Users
Thanks for the suggestion. This will actually help in maintaining clarity. 

But just out of curiosity can't the remove KV method of alert manager be used that returns a copy of key/value map without the given keys(selective labels to drop) as it takes list of keys to be removed and then we iterate over it to display the useful labels?
Reply all
Reply to author
Forward
0 new messages