Skip to content

Allow templating in the webhook URL #684

Closed

Description

@prasenforu

Alertmanager version: 0.5.1

My alert configure as follows ...

ALERT PoDHighCPUUsage
  IF sum(rate(container_cpu_usage_seconds_total{container_label_io_kubernetes_pod_namespace!=""}[2m])) BY (kubernetes_pod_name, kubernetes_io_hostname, container_label_io_kubernetes_pod_namespace) >= 0.2
  FOR 2m
  LABELS {severity="criticalup"}
  ANNOTATIONS {summary="CPU usage of POD {{ $labels.kubernetes_pod_name }} {{ $labels.container_label_io_kubernetes_pod_namespace }} utilization is  >= 0.4 cores (current value: {{ $value }}%)"}

webhooks setup as follows ..

- name: 'email-n-webhookup'
  email_configs:
  - to: 'mail-id'
    send_resolved: true

  webhook_configs:
  - url: http://<webhook_ip>:9000/hooks/ose-webhook?in1={{.Labels.container_label_io_kubernetes_pod_namespace}}&in2={{.Labels.kubernetes_pod_name}}&in3=plus

- name: 'email-n-webhookdn'
  email_configs:
  - to: 'mail-id'
    send_resolved: true

  webhook_configs:
  - url: http://<webhook_ip>:9000/hooks/ose-webhook?in1=tomi&in2=chat&in3=minus

In webhook server logs I am getting data as follows.

[webhook] 2017/04/03 10:03:17 2017-04-03T10:03:17Z | 200 |       194.078µs | 172.30.200.104:9000 | POST /hooks/ose-webhook
[webhook] 2017/04/03 10:03:17 executing /etc/webhook/ose.sh (/etc/webhook/ose.sh) with arguments ["/etc/webhook/ose.sh" "{{.labels.container_label_io_kubernetes_pod_namespace}}" "{{$labels.kubernetes_pod_name}}" "plus"] and environment [] using /etc/webhook as cwd

not as a data, its coming as a complete variable.

So I am not able to pass the value/data "labels.kubernetes_pod_name" & "labels.container_label_io_kubernetes_pod_namespace" in webhook_configs "email-n-webhookup"

Statically it worked as per "email-n-webhookdn"

I think its supported for Email as per https://www.robustperception.io/using-labels-to-direct-email-notifications/

not sure if I can use it in webhook as well ......

Please help ....

Activity

  1. juliusv commented on Apr 3, 2017

    @juliusv
    Member

    The webhook URL is not a templateable field. Instead the webhook notifier sends all metadata in the request body, as outlined in https://prometheus.io/docs/alerting/configuration/#<webhook_config>.

    You can grab the labels from there in your webhook implementation.

    Closing, as this is hopefully answered. If not, please ask questions on the users mailing list instead of opening an issue: https://prometheus.io/community/

  2. prasenforu commented on Apr 3, 2017

    @prasenforu
    Author

    Thanks.

    Don't you think its a enhancement.

  3. juliusv commented on Apr 3, 2017

    @juliusv
    Member

    I can reopen this as a feature request, but it started out as a question.

  4. reopened this on Apr 3, 2017
  5. changed the title [-]Using labels in Alertmanager webhook[/-] [+]Allow templating in the webhook URL[/+] on Apr 3, 2017
  6. brian-brazil commented on Apr 3, 2017

    @brian-brazil
    Contributor

    This wouldn't make sense feature wise. The webhook is meant to work in exactly one way, with the other end specifically designed to accept what we send.

    The other end already has all the information it needs.

  7. juliusv commented on Apr 3, 2017

    @juliusv
    Member

    That's what I thought too. Confirmed then...

  8. prasenforu commented on Apr 4, 2017

    @prasenforu
    Author

    Like other config where url used that all are customised template.

    Why not webhook? and can't be a static all time.

    Let it be open for further discussion..

  9. juliusv commented on Apr 4, 2017

    @juliusv
    Member

    @prasenforu The reasoning here goes:

    1. None of the other notification mechanisms have a templateable URL field.
    2. You get all the dynamic information that you need, just not in the URL of the request, but in the request body.
    3. Two Prometheus core developers have agreed here that we don't think adding this is a good idea, so I think we'll keep this closed.
  10. prasenforu commented on Apr 4, 2017

    @prasenforu
    Author

    OK.
    Thanks.

    Let me explain why ?

    I am using prometheus in containers platform (kubernetes) where things are changing very dynamically.

    I do agree your point.

    Can you please suggest any alternative solution where I can pass labels in that url.

    Otherwise I have to write for each conrainer separate webhook which is not a good idea.

    Basically I want to make global.

    Anyway thanks for your continuous support.

  11. brian-brazil commented on Apr 4, 2017

    @brian-brazil
    Contributor

    Can you please suggest any alternative solution where I can pass labels in that url.

    Uhm, write a webhook that does this and sends out the requests in the format you need.

  12. prasenforu commented on Apr 7, 2017

    @prasenforu
    Author

    Finally able to setup webhook without templating webhook url.

    Thanks all to rethink on this.

    Bydefault webhook resolve option is true.

    Is that mean when it resolve it will fire same webhook.

    Is that understanding correct?

  13. juliusv commented on Apr 7, 2017

    @juliusv
    Member
  14. 7 remaining items

  15. freeseacher commented on Oct 18, 2020

    @freeseacher

    @nehalraf Have you found a solution for templating opsgenie's heartbeats?

  16. mojitaleghani commented on Aug 26, 2024

    @mojitaleghani

    Finally able to setup webhook without templating webhook url.

    Thanks all to rethink on this.

    Bydefault webhook resolve option is true.

    Is that mean when it resolve it will fire same webhook.

    Is that understanding correct?

    Dear @brian-brazil
    Hi
    do you remember how did you do that template with webhook??

  17. nourspace commented on Nov 6, 2025

    @nourspace

    The solution is to create multiple routes with label matchers and receivers with different hardcoded urls. It gets messy. While allowing a templated url would allow using alert labels to construct the correct webhook url.

  18. waltherlee commented on Dec 2, 2025

    @waltherlee
    Member

    None of the other notification mechanisms have a templateable URL field.

    This isn't the case anymore. The alertmanager supports templating in some URL fields now, for example, SlackAction.URL and PushoverConfig.URL, so I think we should re-evaluate adding support for this.

    I'm reopening this issue as a feature request instead of creating a new one.

    I think this can be a small-ish change. I can try and send a PR in a few days.

  19. self-assigned this
    on Dec 2, 2025
  20. moved this from To triage to In progress in Alertmanager Bug Scrubon Dec 2, 2025
  21. moved this from In progress to In review in Alertmanager Bug Scrubon Dec 8, 2025
  22. waltherlee commented on Jan 5, 2026

    @waltherlee
    Member

    PR Merged ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions