HowTo use fields or labels in Alertmanager when using the webhook receiver

58 views
Skip to first unread message

Danny de Waard

unread,
Apr 17, 2020, 4:33:45 AM4/17/20
to Prometheus Users
I want to use a webhook to trigger a script with 3 variables.
These are
- severity
- host
- trigger

And i want them used in my webhook like:

How can i get the fields in the webhook config?

  - name: 'webhook'
    webhook_configs:
      - url: 'http://127.0.0.1:9000'

Brian Candler

unread,
Apr 17, 2020, 6:40:31 AM4/17/20
to Prometheus Users
You can't customise what the webhook sends, so you need to write a small proxy webserver which receives the webhook request, and re-POSTs a suitably modified upstream request.

Or use one of the existing integrations if that's suitable.

Danny de Waard

unread,
Apr 17, 2020, 9:41:34 AM4/17/20
to Prometheus Users
I have a wehook running that van recieve variables.

What i want to know is how i van het thema in the url

Brian Candler

unread,
Apr 17, 2020, 9:58:16 AM4/17/20
to Prometheus Users
The labels like severity are in the JSON body: see https://prometheus.io/docs/alerting/configuration/#webhook_config

It carries a group of alerts, so there are "commonLabels" which are common to them all, and "labels" which are distinct to each firing alert.

Danny de Waard

unread,
Apr 20, 2020, 8:37:42 AM4/20/20
to Prometheus Users
Okay,

I'm using this webhook on my server: https://github.com/adnanh/webhook

If i read correctly you refer to the payload which should contain fields i can get from the payload.
Is this an example of such a payload?? And if so, how do i extract a field like instance from this?

Here is a example:

{
  "receiver": "webhook",
  "status": "firing",
  "alerts": [
    {
      "status": "firing",
      "labels": {
        "alertname": "Test",
        "dc": "eu-west-1",
        "instance": "localhost:9090",
        "job": "prometheus24"
      },
      "annotations": {
        "description": "some description"
      },
      "startsAt": "2018-08-03T09:52:26.739266876+02:00",
      "endsAt": "0001-01-01T00:00:00Z",
      "generatorURL": "http://simon-laptop:9090/graph?g0.expr=go_memstats_alloc_bytes+%3E+0\u0026g0.tab=1"                                                                                  
    }
  ],
  "groupLabels": {
    "alertname": "Test",
    "job": "prometheus24"
  },
  "commonLabels": {
    "alertname": "Test",
    "dc": "eu-west-1",
    "instance": "localhost:9090",
    "job": "prometheus24"
  },
  "commonAnnotations": {
    "description": "some description"
  },
  "externalURL": "http://simon-laptop:9093",
  "version": "4",
  "groupKey": "{}:{alertname=\"Test\", job=\"prometheus24\"}"
}


Op vrijdag 17 april 2020 15:58:16 UTC+2 schreef Brian Candler:

Brian Candler

unread,
Apr 20, 2020, 1:37:55 PM4/20/20
to Prometheus Users
On Monday, 20 April 2020 13:37:42 UTC+1, Danny de Waard wrote:
If i read correctly you refer to the payload which should contain fields i can get from the payload.
Is this an example of such a payload??

It looks like it to me.  There's an official example in the documentation at https://prometheus.io/docs/alerting/configuration/#webhook_config
See under "The Alertmanager will send HTTP POST requests in the following JSON format to the configured endpoint:"

 

And if so, how do i extract a field like instance from this?

That's a programming question, i.e. how to extract fields from a JSON structure, and depends entirely on the programming language you're using.

The github repo you linked to seems to be using Go.  A good place to ask questions is on the "golang-nuts" group.  However you should start by looking at some existing examples of parsing JSON in Go.

Reply all
Reply to author
Forward
0 new messages