简体   繁体   English

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

[英]Prometheus alertmanager send notifications to multiple slack channel

We have two different teams working on different applications.I would like send alert notifications to different slack channels via using same alerts expressions.我们有两个不同的团队在处理不同的应用程序。我想通过使用相同的警报表达式将警报通知发送到不同的松弛通道。 I found some examples but not understand what is the main reason to use receiver: 'default' when try to add new route?我找到了一些示例,但不明白尝试添加新路由时使用receiver: 'default' What is the role of this and what if it affects if ı change this?这有什么作用,如果我改变它会影响什么?

Meanwhile will be appreciate if you can help how should I send the notifations to multiple slack channels.. New one is what I tried.同时,如果您能帮助我如何将通知发送到多个松弛通道,将不胜感激。我尝试过新的。

Current alertmanager.yml当前的 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]

New alertmanager.yml新的 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'

You need to set the continue property on your route to true.您需要将路线上的 continue 属性设置为 true。 By default it is false.默认情况下它是假的。

The default behaviour of AlertManager is to traverse your routes for a match and exit at the first node it finds a match at. AlertManager 的默认行为是遍历您的路由以进行匹配并在找到匹配项的第一个节点处退出。

What you want to do is fire an alert at the match and continue to search for other matches and fire those too.您想要做的是在比赛中发出警报,并继续搜索其他比赛并也解雇那些比赛。

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

An example using this: https://awesome-prometheus-alerts.grep.to/alertmanager.html使用此示例: https://awesome-prometheus-alerts.grep.to/alertmanager.html

In-lined the example above in case it ever breaks.内联上面的示例以防万一。

# 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM