Send message via Alertmanager to two slack channels

8,144 views
Skip to first unread message

g...@recongate.com

unread,
Oct 8, 2017, 8:15:41 AM10/8/17
to Prometheus Users
Hello,

This is my alertmanager.yml file:

------------------------------------------------------------------------------------------
global:
  slack_api_url: '< slack_url >'

route:
  receiver: 'Monitorbot'
  # All alerts in a notification have the same value for these labels.
  group_by: [alertname, datacenter, app]

route:
  receiver: 'Production'
  # All alerts in a notification have the same value for these labels.
  group_by: [Env, alertname, datacenter, app]

receivers:
- name: 'Production'
  slack_configs:
  - channel: '#alerts'
    title: "{{ range .Alerts }}{{ .Annotations.summary }}\n{{ end }}"
    text: "{{ range .Alerts }}{{ .Annotations.description }}\n{{ end }}"

- name: 'Monitorbot'
  slack_configs:
  - channel: '#devops'
    title: "{{ range .Alerts }}{{ .Annotations.summary }}\n{{ end }}"
    text: "{{ range .Alerts }}{{ .Annotations.description }}\n{{ end }}"
------------------------------------------------------------------------------------------

My objective is to send alerts with the label {Env : 'production'} to the #alerts channel and all the alerts (including the ones with this label} to the #devops channel.

How should i change my configuration to achieve this?

jdbj...@gmail.com

unread,
Oct 8, 2017, 5:50:40 PM10/8/17
to g...@recongate.com, Prometheus Users
Don't use the global slack_api_url, instead use te api_url under slack_configs. Configuring two integrations on slack, one per channel, you can then use the specific integration on the receiver you want.


--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/7ad5a602-4ff1-4d9b-88dc-4f301830d0c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gil Goldberger

unread,
Oct 10, 2017, 4:32:40 AM10/10/17
to jdbj...@gmail.com, Prometheus Users
Thanks,

Do you have any more documentation for this or perhaps templates i could use?

Gil Goldberger

unread,
Oct 10, 2017, 6:45:19 AM10/10/17
to jdbj...@gmail.com, Prometheus Users
Also, where do i specify that alerts with the label {Env : 'production'} should be forwarded to a certain slack channel?

jdbj...@gmail.com

unread,
Oct 11, 2017, 7:01:32 PM10/11/17
to Gil Goldberger, Prometheus Users
Alertmanager config documentation -> https://prometheus.io/docs/alerting/configuration

example:

route:
  receiver: webhook
  routes:
    - match:
        env: production
      receiver: slack-production
    - match:
        env: staging
      receiver: slack-staging

receivers:
- name: slack-production
  slack_configs:
    channel: production
- name: slack-staging
  slack_configs:
    channel: staging
- name: webhook
  webhook_configs:
  - url: webhook_url

g...@recongate.com

unread,
Feb 28, 2018, 5:08:41 AM2/28/18
to Prometheus Users
Hi,

This is my alertmanager.yml file:

global:
route:
  receiver: 'default'
  routes:
  - match:
      env: 'production'
      receiver: "Alerts-production"
  - match:
      env: 'development'
      receiver: "Alerts-development"
receivers:
  - name: 'Alerts-production'
    slack_configs:
    - api_url: ''< slack_url >'
      channel: '#alerts'
  - name: 'Alerts-development'
    slack_configs:
    - api_url: ''< slack_url >'
      channel: '#alerts-development'
  - name: 'default'
    slack_configs:
    - api_url: ''< slack_url >'
      channel: '#devops'

No matter what the value of the label env is, the alert always goes to the default receiver.

I add the env label in the prometheus.yml file, it looks like this:

  - job_name: 'Dev'
    scrape_interval: 15s
    scrape_timeout: 10s
    static_configs:
      - targets: ['<host>:<port>']
        labels: {'env': 'production'}

Why isn't the alert redirected to the relevant receiver through the env label?

Thanks

Simon Pasquier

unread,
Feb 28, 2018, 5:30:11 AM2/28/18
to g...@recongate.com, Prometheus Users
I suspect that you have an indentation issue with in your YAML configuration file. The "receiver" key should be at the same level as "match":

[...]
route:
  receiver: 'default'
  routes:
  - receiver: "Alerts-production"
    match:
      env: 'production'
  - receiver: "Alerts-development"
    match:
      env: 'development'
[...]



--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.

g...@recongate.com

unread,
Feb 28, 2018, 7:28:51 AM2/28/18
to Prometheus Users
That was the problem, Thank you!

Ali Kahoot

unread,
Jul 23, 2018, 8:49:52 AM7/23/18
to Prometheus Users
Hi, I also want to send alerts to multiple slack channels bases on the labels defined on pods and this is my config but it is not sending notifications. only the default route receiver is working, can anyone tell what am I missing:

global:


  resolve_timeout
: 5m


templates
:


- '/etc/alertmanager/template/*.tmpl'


route
:


  group_by
: ['alertname', 'cluster', 'service']


  group_wait
: 30s


  group_interval
: 5m


  repeat_interval
: 1h


  receiver
: 'default-receiver'



  routes
:


 
- match:


      env
: 'production'



    receiver
: 'alerts-receiver'


 
- match:


      alertname
: DeadMansSwitch


    receiver
: 'null'


 
- match:


      env
: 'development'


    receiver
: 'alerts-receiver'
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To post to this group, send email to promethe...@googlegroups.com.

Simon Pasquier

unread,
Jul 23, 2018, 9:35:07 AM7/23/18
to Ali Kahoot, Prometheus Users
It is definitely possible to achieve this.
Can you share the AlertManager's log files?
Are you 100% sure that the alerts have the "env" label set with the expected value?

To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/4a572c88-c4fe-45c6-8294-f1aa3c7f84e7%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages