Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow templating in the webhook URL #684

Closed
prasenforu opened this issue Apr 3, 2017 · 20 comments
Closed

Allow templating in the webhook URL #684

prasenforu opened this issue Apr 3, 2017 · 20 comments

Comments

@prasenforu
Copy link

prasenforu commented Apr 3, 2017

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 ....

@juliusv
Copy link
Member

juliusv commented Apr 3, 2017

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/

@juliusv juliusv closed this as completed Apr 3, 2017
@prasenforu
Copy link
Author

Thanks.

Don't you think its a enhancement.

@juliusv
Copy link
Member

juliusv commented Apr 3, 2017

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

@juliusv juliusv reopened this Apr 3, 2017
@juliusv juliusv changed the title Using labels in Alertmanager webhook Allow templating in the webhook URL Apr 3, 2017
@brian-brazil
Copy link
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.

@juliusv
Copy link
Member

juliusv commented Apr 3, 2017

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

@juliusv juliusv closed this as completed Apr 3, 2017
@prasenforu
Copy link
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..

@juliusv
Copy link
Member

juliusv commented Apr 4, 2017

@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.

@prasenforu
Copy link
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.

@brian-brazil
Copy link
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.

@prasenforu
Copy link
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?

@juliusv
Copy link
Member

juliusv commented Apr 7, 2017 via email

@rajkiran616
Copy link

rajkiran616 commented Oct 3, 2017

I have small question. Lets say we need to call API endpoint based on alert. If alert is about a particular docker service. How can we pass the service name as part of webhook url?

I am able to call the endpoint with hardcoded service name. http://url/api/coreservice/scaleup/. And configure the url in alertmanager.yml.

webhook_configs:

How can we get he service name?

Can we use {{.Labels.container_label_com_docker_swarm_service_name}} ?

@brian-brazil
Copy link
Contributor

@rajkiran616 Please don't put support requests on closed issues. The Prometheus users list is the best place for such questions.

@nehalraf
Copy link

@brian-brazil If we allow templating in url we can use opegenie to track heatbeats (via DeadmanSwitch) in case of alerts coming from multiple clusters. Ops genie will create seperate heartbeat for each cluster.

route:
routes:
- receiver: 'opsgenie-heartbeat'
match:
alertname: DeadMansSwitch

receivers:

@sevagh
Copy link

sevagh commented Sep 24, 2019

We allow users to specify their slack, email, and pagerduty from the alert file itself:

$ cat example_alert.yml
groups:
- name: example
  rules:
  - alert: ExampleAlert
    expr: up{job="myjob"} == 0
    for: 5m
    labels:
      slack: '#my-slack-channel'
      email: '@my-email'
      pagerduty: 'my-pagerduty-service-id'
    annotations:
      description: 'foo'
      summary: 'foo'

These get expanded in the alertmanager config, e.g.

- name: generic_email
  email_configs:
  - to: "{{ .GroupLabels.email }}"

That way, team-specific configs stay out of the alertmanager config. I prefer to have teams put their own configs in their own files, and I (as a sysadmin/ops/whatever) maintain the alertmanager config.

The one exception I've run into so far is that webhooks aren't templateable, so I need to allow people to write to the alertmanager config.

This describes a usecase where I'd be happy if webhooks became templateable.

@abhishekjiitr
Copy link

@brian-brazil If we allow templating in url we can use opegenie to track heatbeats (via DeadmanSwitch) in case of alerts coming from multiple clusters. Ops genie will create seperate heartbeat for each cluster.

route:
routes:

  • receiver: 'opsgenie-heartbeat'
    match:
    alertname: DeadMansSwitch

receivers:

* name: 'opsgenie-heartbeat'
  webhook_configs:
  
  * url: '[https://api.opsgenie.com/v2/heartbeats/{{](https://api.opsgenie.com/v2/heartbeats/%7B%7B) .GroupLabels.ClusterID }}/ping?apiKey=*******'
    send_resolved: true

+1, need templating in webhook URL for OpsGenie HeartBeat

@jangrewe
Copy link

+1, this would be the only way (i can think of) to make prometheus-msteams usable with MS Teams stupid decision to require a separate webhook for every. single. channel., by using a K8s namespace <-> webhook mapping config for it.

@Yzzzi
Copy link

Yzzzi commented Aug 21, 2020

I have another example where templatable urls can be usefull:
Im using alertmanager to send notifications about my jenkins slaves (ex. disk space usege). And i wanted to implement job triggering on alert to automaticly clear slaves disk. Templatable url would be helpful here, because i can create job to trigger with parameters in Jenkins, and use slave hostname as a parameter. Jenkins require parameter to be in a url.

@freeseacher
Copy link

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

@mojitaleghani
Copy link

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??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests