Sobes.tech
Junior — Middle

How to configure routing of alert notifications to specific channels in Alertmanager from Prometheus?

sobes.tech AI

Answer from AI

Routing of alert notifications in Alertmanager is configured using the route section in the alertmanager.yml configuration file. The main idea is to define rules by which alerts are directed to different channels (e.g., email, Slack, PagerDuty).

Example of routing configuration:

route:
  receiver: 'default-receiver'
  routes:
  - match:
      severity: critical
    receiver: 'critical-channel'
  - match_re:
      service: '^(web|api)$'
    receiver: 'web-api-channel'

receivers:
- name: 'default-receiver'
  email_configs:
  - to: 'default@example.com'

- name: 'critical-channel'
  slack_configs:
  - channel: '#critical-alerts'

- name: 'web-api-channel'
  pagerduty_configs:
  - service_key: 'your-service-key'

In this example:

  • All alerts by default go to default-receiver.
  • Alerts with the label severity: critical are sent to the Slack channel #critical-alerts.
  • Alerts from web or api services are directed to PagerDuty.

Thus, using match and match_re rules, notifications can be flexibly routed to the desired channels.