You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Alertmanager配置多告警接收方?当前仅单个接收方生效

Alertmanager配置:同时启用Slack和邮件告警接收方

你的问题核心在于Alertmanager路由的默认匹配行为——路由默认匹配到第一个符合条件的规则后就停止后续匹配(continue: false是默认值),导致部分告警无法触发对应的接收方。以下是针对性的解决方案和配置修正:

问题分析

当前配置中:

  • 第一个路由匹配severity =~ 'critical|warning'的告警,发送到邮件接收方
  • 第二个路由匹配alertname =~ "InfoInhibitor|Watchdog"的告警,发送到Slack

如果某个告警同时满足两个路由的匹配条件(比如Watchdog告警的severity被标记为warning),它会被第一个路由拦截,无法触发Slack告警;反之如果要让符合第一个路由的告警同时发送邮件和Slack,默认配置也做不到。

解决方案

方案1:让告警匹配多个路由(同时触发多渠道)

如果需要让匹配第一个路由的告警同时触发Slack,只需在第一个路由中添加continue: true,允许告警继续匹配后续路由:

config:
  global:
    resolve_timeout: 5m
  route:
    group_by: ['job']
    group_wait: 30s
    group_interval: 5m
    repeat_interval: 12h
    receiver: 'null'
    routes:
    - receiver: 'email'
      matchers:
      - severity =~ 'critical|warning'
      continue: true  # 允许告警继续匹配后续路由
    - receiver: 'slack-notifications'
      matchers:
        - alertname =~ "InfoInhibitor|Watchdog" 
  receivers:
  - name: 'null'
  - name: 'email'
    email_configs:
    - to: 'xxx'
      from: xxx
      auth_username: xxx
      auth_password: xxx
      auth_identity: xxx
  - name: 'slack-notifications'
    slack_configs:
    - send_resolved: true
      api_url: 'https://hooks.slack.com/services/xxx'  
  templates:
  - '/etc/alertmanager/config/*.tmpl'

方案2:创建组合接收器(指定告警同时发送到多渠道)

如果需要特定类别的告警同时发送邮件和Slack,可以创建一个包含多个接收方的组合接收器:

config:
  global:
    resolve_timeout: 5m
  route:
    group_by: ['job']
    group_wait: 30s
    group_interval: 5m
    repeat_interval: 12h
    receiver: 'null'
    routes:
    - receiver: 'combined-alerts'  # 使用组合接收器
      matchers:
      - severity =~ 'critical|warning'
    - receiver: 'slack-notifications'
      matchers:
        - alertname =~ "InfoInhibitor|Watchdog" 
  receivers:
  - name: 'null'
  - name: 'email'
    email_configs:
    - to: 'xxx'
      from: xxx
      auth_username: xxx
      auth_password: xxx
      auth_identity: xxx
  - name: 'slack-notifications'
    slack_configs:
    - send_resolved: true
      api_url: 'https://hooks.slack.com/services/xxx'
  - name: 'combined-alerts'  # 新增组合接收器,包含邮件和Slack
    receivers:
    - name: 'email'
    - name: 'slack-notifications'
  templates:
  - '/etc/alertmanager/config/*.tmpl'

额外排查步骤

  1. 查看Alertmanager日志,确认告警的路由匹配情况
  2. 验证告警标签是否符合预期:通过Prometheus UI查看告警的severity、alertname等标签
  3. 手动模拟告警测试:使用amtool工具发送测试告警,验证接收方是否正常触发

内容的提问来源于stack exchange,提问作者AnmolDevops

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 21:00:06