Alertmanager Configuration for Routing Alerts via Telegram

46 views
Skip to first unread message

Alexander Varejão

unread,
Jun 20, 2024, 9:44:57 AMJun 20
to Prometheus Users
Hi,

I need help again :(

I am trying to configure my Alertmanager to send separate alerts without success.

Basically, I need to trigger two alerts for two different groups via Telegram.

So, I created two alerts (Alert1 and Alert2) and two teams (Team1 and Team2).

Team1 should only receive Alert1, while Team2 should receive both alerts (Alert1 and Alert2).

However, only Team 2 is receiving the alerts. I don't know what is wrong. Could someone help me find the error in my configuration?

[...]
route:
  group_by: ["instance"]
  receiver: 'Team2'
  routes:
    - matchers:
        - alertname = "InstanceDown"
      receiver: 'Team2'
      continue: true
    - matchers:
        - alertname = "SystemdUnitDown"    
        - alertname = "InstanceDown"  
      receiver: 'Team1'
      continue: true    

receivers:
    - name: 'Team1'
      email_configs:
       - to: 'email@domain'
         send_resolved: true
         html: ''
         text: "Summary: {{ .CommonAnnotations.summary }}\ndescription: {{ .CommonAnnotations.description }}\n\n"
      telegram_configs:
       - api_url: 'https://api.telegram.org'                            
         chat_id: -ID_HERE                                            
         bot_token: -TOKEN_HERE    
    - name: 'Team2'
      telegram_configs:
        - api_url: 'https://api.telegram.org'
          chat_id: -ID_HERE
          bot_token: -SAME_TOKEN_HERE
[...]

Tanks

Brian Candler

unread,
Jun 20, 2024, 1:04:40 PMJun 20
to Prometheus Users
If you put multiple matchers, they must all be true to match ("AND" semantics). So when you wrote

   - matchers:
        - alertname = "SystemdUnitDown"    
        - alertname = "InstanceDown"  

it means alertname must be simultaneously equal to both those values, which can never be true.

One solution is to rewrite your matchers, such as

   - matchers:
        - alertname =~ "SystemdUnitDown|InstanceDown"    

Personally though I find it easier to structure my rules the other way round: when a condition matches list all the receivers who should receive this alert. You can do this using nested routing rules ("routes" instead of "receiver").  For example, for the InstanceDown alert:

    - matchers:
        - alertname = "InstanceDown"
      routes: [ { receiver: Team1, continue: true }, { receiver: Team2 } ]
      #continue: true

The magic here is that the nested routes don't have any matchers, so they always match and deliver to the receiver.

You then don't need the top-level "continue: True" either (I've shown it commented out), since once this condition matches, you've finished all the processing for InstanceDown and you don't need to test any subsequent rules.

Alexander Varejão

unread,
Jun 20, 2024, 1:47:59 PMJun 20
to Prometheus Users
Dear Brian Candlers,

Thanks for answer :)

That's really solved my problem. Now I can proceed with testing alertmanager

Regards
Reply all
Reply to author
Forward
0 new messages