Integration with prometheus - mapping parameters to alert fields




im search for a way to convert the prometheus labels into opsgenie tags. Is there any to convert during alert creation the labels into tags? Or make at least the labels viewable in the opsgenie alert message?


Hi Sven,

Normally that would be possible via the dynamic fields if the integration parameter mapping is done on our side. However, for Prometheus, we are providing a generic API endpoint and the customization is done in the Alertmanager on the other side.

I’m nowhere near familiar with Prometheus, but I believe you have the ability to map labels to the tags parameter in the Receiver settings.

I found this looking for customization options:

Based on this, probably you could do something like:

- name: "opsgenie" 
- api_key: xxx 
teams: TeamA 
tags: '{{ range .Alerts }}{{ .Labels.instance }} {{ end }}'

This will take the instance label and add it as a tag. You can play around with those Go templates to get all the labels you are interested.

You think this is enough to get you started?


Thanks for this, I’ve spent some time on this today and struggling to get include multiple labels to tags.

Has anyone accomplished this?


Our config looks like this

- name: opsgenie
  - api_key: KEY
    tags: "{{ range .Alerts }}{{ .Labels.severity}},{{ end }}, {{ range .Alerts }}{{ .Labels.alertname}},{{ end }},  {{ range .Alerts }}{{ .Labels.instance }},{{ end }}, {{ range .Alerts  }}{{ .Labels.role }},{{ end }}, {{ range .Alerts }}{{ .Labels.job}},{{ end }},{{ range .Alerts }}{{ .Labels.application}},{{ end }}, "
    source: alertmanager
    message: |-
      {{ range .Alerts }}{{ .Annotations.summary }}
      {{ end }}
    description: |-
      {{ range .Alerts }}
       <b>Alert:</b> {{ .Annotations.summary }} - {{ .Labels.severity }}
       <b>Description:</b> {{ .Annotations.description }}
       <b>Graph:</b> <a href="{{ .GeneratorURL }}">📈 Graph</a>
       <b>Source:</b> <a href="http://prometheus.local.domain/graph?g0.expr=ALERTS%7Balertname%3D%22{{ .Labels.alertname }}%22%7D&">prometheus</a>
       <b>Runbook:</b> <a href="https://wiki.local.domain/{{ .Labels.alertname }}">wiki</a>
        {{ range .Labels.SortedPairs }} • <b>{{ .Name }}:</b> {{ .Value }}
        {{ end }}
      {{ end }}

This will add some tags to the OpsGenie Alert itself, the description it self has in Details als available tags.

I hope this helps