CAN I CONFIGURE TWO EMAIL RECIEVER FOR ALERTMANAGER

541 views
Skip to first unread message

Chinelo Ufondu

unread,
Oct 10, 2024, 4:54:51 AM10/10/24
to Prometheus Users
Hello everyone

I am currently trying to configure two email receiver in my alertmanager config file, of which i did but only one works fine, I wanted to ask if its possible to have two email receivers, if so, please i need an example template, because i have tried all i could get my hands on, but to no avail.

Brian Candler

unread,
Oct 10, 2024, 6:13:51 AM10/10/24
to Prometheus Users
Please show the configuration you have tried, to make it clearer what you're trying to do, and then we can help you correct it.

email_configs takes a YAML list of email_config entries (see docs), so a single receiver can have multiple E-mail destinations:

receivers:
- name: foobar
  email_configs:
  - to: f...@example.com
    send_resolved: true
  - to: b...@example.com
    send_resolved: true

(and indeed it could include other types of transport; e.g.  the same foobar receiver could also have a 'slack_config' section, a 'webhook_config' section, etc)

The corresponding alerting rule is then very simple: e.g.

  routes:
  - matchers:
    - severity=critical
    receiver: foobar

If you have some rules that want to send only to foo or only to bar, then you'd need to create additional named receivers, with just foo and just bar.

*OR*

You can create separate receivers, and then create routing rules which send to more than one receiver. For example, you could have these two separate receivers:

receivers:
- name: foo
  email_configs:
  - to: f...@example.com
    send_resolved: true
- name: bar
  email_configs:
  - to: b...@example.com
    send_resolved: true

However, the way you get a single alerting rule to send to multiple receivers is non-obvious. It requires a nested branch of the routing tree:

  routes:
    - matchers:
      - severity = "critical"
      routes: [ { receiver: foo, continue: true }, { receiver: bar } ]

Note that the top-level route contains "routes" rather than "receiver". Within that list, the first route matches always (because it has no "match" or "matchers" condition) and sends to "foo", but "continue: true" makes it carry on to the second rule; that also always matches, and sends to "bar".  Repeat as many times as necessary.  All except the last need "continue: true" - and it doesn't harm to set it there as well.

"receiver" is only used when no child routes match. Since all alerts passed to the child "routes" are matched and consumed, it never falls back to "receiver", meaning there's no need to set "receiver" as well on this rule.

Chinelo Ufondu

unread,
Oct 10, 2024, 8:13:11 AM10/10/24
to Brian Candler, Prometheus Users
Okay, this is the config file i have tried

receivers:
  - name: send_email
    email_configs:
      - to: em...@valucid.com
        from: em...@valucid.com
        smarthost: smtp.zoho.com:587
        auth_username: em...@valucid.com
        auth_password: pass
        
   - name: send_email2
     email_configs:
        - to: em...@valucid.com
          from: em...@valucid.com
          smarthost: smtp.zoho.com:587
          auth_username: em...@valucid.com
          auth_password: pass
        
route:
  receiver: send_email
   routes:
     - receiver: send_email2

inhibit_rules:
  - source_match:
      severity: critical
    target_match:
      severity: warning
    equal:
      - alertname
      - dev
      - instance

--
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-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/389dba7f-8dfe-4f94-b648-99071478a703n%40googlegroups.com.

Brian Candler

unread,
Oct 10, 2024, 8:32:04 AM10/10/24
to Prometheus Users
route:
  receiver: send_email
  routes:
    - receiver: send_email2

That route will only ever send to send_mail2. Why?

"routes" are child routes of this route. When processing a given routing rule, alertmanager scans through all the child routes in turn, and the first one which matches is used. Only if *none* of them match, does it fall back to using the "receiver" at the top level of the routing rule.

In your case, there is one child rule, and it always matches (because it has no conditions). It sends the mail to send_email2, and then terminates. Nothing more happens, and the fallback "receiver" is never used.

If you want to send to both, then you would have two child routes:

route:
  receiver: dontcare    # you can omit this line entirely (it's never used)
  routes:
    - receiver: send_email
      continue: true
    - receiver: send_email2

"continue: true" is required so that after matching the first route, it continues to the next one instead of giving up immediately.

You can write this in a more compact one-line form where [ ... ] is a list and { ... } is an object:

route:
  routes: [ { receiver: send_email, continue: true}, { receiver: send_email2 } ]


...and that's what I showed before.

But if all your alerts need to go to both E-mail addresses, it would be simpler to have a single "send_email" receiver with two E-mail addresses.

Chinelo Ufondu

unread,
Oct 11, 2024, 9:54:01 AM10/11/24
to Brian Candler, Prometheus Users
Thank you for your email, I had omitted the receiver and tried this below and it came up with an error message that i must specify a default receiver 
route:
  routes: [ { receiver: send_email, continue: true}, { receiver: send_email2 } ]

Plus in your last statement, is it possible to have just one send_email reciever configured for two email addresses?

--
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-use...@googlegroups.com.

Brian Candler

unread,
Oct 11, 2024, 10:58:00 AM10/11/24
to Prometheus Users
Ah right: at the very top level you must specify a catch-all receiver (in case no route matches). At lower levels in the tree you don't need to.

So just include one:

route:
  receiver: send_mail    # just to keep alertmanager happy, this will never be used

  routes:
    - receiver: send_email
      continue: true
    - receiver: send_email2

> is it possible to have just one send_email reciever configured for two email addresses?

Yes, as I showed in my first response.

receivers:
- name: send_email
  email_configs:
    send_resolved: true
  - to: b...@example.com
    send_resolved: true

Chinelo Ufondu

unread,
Oct 14, 2024, 10:01:56 AM10/14/24
to Brian Candler, Prometheus Users
Thank you so much Brian, the solution works out fine and mails are being sent after testing. I am glad i came across this group

Reply all
Reply to author
Forward
0 new messages