设置 alertmanager 以按作业名称将警报分发到不同的通道

set alertmanager to distribute alerts to different channel by job name

我想将警报发送到 Alertmanager for Prometheus 中的两个不同的分发列表。区分我的警报的唯一方法是通过他们的工作名称。

我的警报名称如下:

样本 1:

Labels
alertname = SyslogErrors
instance = 22.32.23.32:2324
job = my-job-sample-service-dev
message = Exception raised during message subscription. Trying again in 60 seconds
monitor = server1
severity = critical
Annotations
description = Errors have been found for my-job-sample-service-dev application in /data/logs/messages/my-job-sample-service-dev syslog file
Source

样本 2:

Labels
alertname = SyslogErrors
instance = 22.32.23.32:2324
job = my-job-sample-service-pre-dev
message = Exception raised during message subscription. Trying again in 60 seconds
monitor = server1
severity = critical
Annotations
description = Errors have been found for my-job-sample-service-pre-dev application in /data/logs/messages/my-job-sample-service-pre-dev syslog file
Source

这是我的示例 alertmanager 配置文件:

global:
  smtp_smarthost: 'mail.server.com:25'
  smtp_from: 'dev@server.com'
  smtp_require_tls: false
templates:
- '/etc/alertmanager/template/*.tmpl'
route:
  receiver: mail-receiver-dev
  group_by: ['alertname']
  group_wait: 3s
  group_interval: 5s
  repeat_interval: 1h
  # All alerts that do not match the following child routes
  # will remain at the root node and be dispatched to 'default-receiver'.
  routes:
  - receiver: 'mail-pre-dev'
    group_wait: 10s
    match_re: 
    - job = .*pre-dev.*
  - receiver: 'mail-dev'
    group_wait: 10s
    match_re:
    - job = .*dev.*

receivers:
- name: 'mail-dev'
  email_configs:
  - to: 'dev-group@server.com'
    send_resolved: true
- name: 'mail-pre-dev'
  email_configs:
  - to: 'pre-dev-group@server.com'
    send_resolved: true

我使用以下 link 作为参考: reference

Testing config file link 使用上述 link 的测试脚本:{service="foo-service",severity="critical",job="my-job-sample-service-dev"}

所以问题是,如何使用 regexjob 标题发送警报到不同的频道?在我测试所有警报的那一刻转到 pre-dev.

更改以下内容:

match_re: 
- job = .*pre-dev.*

收件人:

matchers: 
- job =~ ".*pre-dev.*"

注:

"match_re" 已弃用,必须用 "matchers" 代替,但如果要使用它,正确的语法是:

match_re:
- job: ".*pre-dev.*"