Prometheus alertmanager 向多个 slack 通道发送通知

Posted

技术标签:

【中文标题】Prometheus alertmanager 向多个 slack 通道发送通知【英文标题】:Prometheus alertmanager send notifications to multiple slack channel 【发布时间】:2020-10-21 15:48:51 【问题描述】:

我们有两个不同的团队在处理不同的应用程序。我想通过使用相同的警报表达式将警报通知发送到不同的松弛通道。我找到了一些示例,但不明白尝试添加新路由时使用receiver: 'default' 的主要原因是什么?这有什么作用,如果我改变它会影响什么?

同时,如果您能帮助我如何将通知发送到多个松弛通道,将不胜感激。我尝试过新的通道。

当前的 alertmanager.yml

receivers:
  - name: 'team-1'
    slack_configs:
    - api_url: 'https://hooks.slack.com/services/1'
      channel: '#hub-alerts'
route:
  group_wait: 10s
  group_interval: 5m
  receiver: 'team-1'
  repeat_interval: 1h
  group_by: [datacenter]

新的 alertmanager.yml

alertmanager.yml:
    receivers:
      - name: 'team-1'
        slack_configs:
        - api_url: 'https://hooks.slack.com/services/1'
          channel: '#channel-1'
          send_resolved: true
      
      - name: 'team-2'
        slack_configs:
        - api_url: 'https://hooks.slack.com/services/2'
          channel: '#channel-2'
          send_resolved: true

route:
  group_wait: 10s
  group_interval: 5m
  repeat_interval: 1h
  group_by: [datacenter]
  receiver: 'default'
  routes:
  - receiver: 'team-1'
  - receiver: 'team-2'

【问题讨论】:

【参考方案1】:

您需要将路线上的 continue 属性设置为 true。默认为假。

AlertManager 的默认行为是遍历您的路由进行匹配并在找到匹配项的第一个节点处退出。

您想要做的是在匹配时发出警报,然后继续搜索其他匹配并也触发它们。

相关文档部分:https://prometheus.io/docs/alerting/latest/configuration/#route

一个使用这个的例子: https://awesome-prometheus-alerts.grep.to/alertmanager.html

内联上面的例子,以防万一它坏了。

# alertmanager.yml

route:
  # When a new group of alerts is created by an incoming alert, wait at
  # least 'group_wait' to send the initial notification.
  # This way ensures that you get multiple alerts for the same group that start
  # firing shortly after another are batched together on the first
  # notification.
  group_wait: 10s

  # When the first notification was sent, wait 'group_interval' to send a batch
  # of new alerts that started firing for that group.
  group_interval: 5m

  # If an alert has successfully been sent, wait 'repeat_interval' to
  # resend them.
  repeat_interval: 30m

  # A default receiver
  receiver: "slack"

  # All the above attributes are inherited by all child routes and can
  # overwritten on each.
  routes:
    - receiver: "slack"
      group_wait: 10s
      match_re:
        severity: critical|warning
      continue: true

    - receiver: "pager"
      group_wait: 10s
      match_re:
        severity: critical
      continue: true

receivers:
  - name: "slack"
    slack_configs:
      - api_url: 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/xxxxxxxxxxxxxxxxxxxxxxxxxxx'
        send_resolved: true
        channel: 'monitoring'
        text: " range .Alerts <!channel>  .Annotations.summary \n .Annotations.description \n end "

  - name: "pager"
    webhook_config:
      - url: http://a.b.c.d:8080/send/sms
        send_resolved: true

【讨论】:

以上是关于Prometheus alertmanager 向多个 slack 通道发送通知的主要内容,如果未能解决你的问题,请参考以下文章

Prometheus+alertmanager告警配置-2

Prometheus Alertmanager Slack 配置:send_resolved 作为灵活值

prometheus 与 alertmanager 结合 发送邮件报警

linux(centos8):prometheus使用alertmanager发送报警邮件(prometheus 2.18.1/alertmanager 0.20.0)

linux(centos8):prometheus使用alertmanager发送报警邮件(prometheus 2.18.1/alertmanager 0.20.0)

Prometheus配合Alertmanager报警系统