Prometheus Alertmanager路由异常:winB告警未匹配对应接收器
Alertmanager路由规则排查:winB告警走默认接收器问题
核心问题定位
你的配置中使用了match_re(正则匹配)来匹配alertname,但对于精确匹配的场景,更适合用match(精确匹配),这是导致winB告警未正确路由的关键原因。同时可通过配置校验、标签验证等步骤排查其他潜在问题。
排查与修复步骤
替换正则匹配为精确匹配
把routes中的match_re改为match,因为你的需求是精确匹配alertname=winA和alertname=winB,match_re是正则匹配,虽写法上看似能工作,但可能存在隐式匹配逻辑问题(比如意外匹配到包含目标字符串的其他alertname)。修改后的路由段如下:route: group_by: ['alertname', 'instance'] group_wait: 10s group_interval: 5m repeat_interval: 30m receiver: 'default' routes: - receiver: 'winA' match: alertname: winA - receiver: 'winB' match: alertname: winB校验配置文件语法
执行Alertmanager配置校验命令,确保yaml格式、配置逻辑无错误:alertmanager --config.check-config --config.file=alertmanager.yml即使无报错,也能确认缩进、引号等细节是否符合规范。
确认告警标签的精确性
登录Alertmanager UI(默认端口9093)或Prometheus的Alerts页面,查看winB告警的实际alertname标签值,确保无大小写错误、空格或其他特殊字符(比如是否是WinB而非winB)。验证路由匹配逻辑
Alertmanager路由是从上到下顺序匹配,匹配到第一个符合条件的规则后默认停止(continue: false)。当前winA的规则不会匹配winB的告警,顺序无问题;若后续有复杂路由规则,可通过添加continue: true让告警继续匹配后续规则,当前场景无需修改。
修复后的完整配置
route: group_by: ['alertname', 'instance'] group_wait: 10s group_interval: 5m repeat_interval: 30m receiver: 'default' routes: - receiver: 'winA' match: alertname: winA - receiver: 'winB' match: alertname: winB receivers: - name: 'winA' email_configs: - to: 'A@A.com' send_resolved: true from: 'fromA@A.com' - name: 'winB' email_configs: - to: 'B@B.com' send_resolved: true from: 'fromB@B.com' - name: 'default'
内容的提问来源于stack exchange,提问作者Jagadish Kumar
相关产品推荐
相关产品推荐

