简体   繁体   English

Prometheus 和 Alertmanager - 基于 env label 的路由

[英]Prometheus and Alertmanager - route based on env label

I'm trying to configure alertmanager so that it sends alerts to the right channels, based on value of a specific label.我正在尝试配置警报管理器,以便它根据特定 label 的值将警报发送到正确的通道。 I have 3 slack channels - dev/staging/prod and I want the alerts coming from instances that have "env" label set to dev to be sent to the dev slack channel.我有 3 个松弛通道 - dev/staging/prod,我希望来自将“env”label 设置为 dev 的实例发送到 dev 松弛通道的警报。 Staging and prod would obviously work in the same manner. Staging 和 prod 显然会以相同的方式工作。 Here is part of my config:这是我的配置的一部分:

global:
  resolve_timeout: 1m
  slack_api_url: 'https://slack-url'

route:
  group_by: [...]
  receiver: 'default'
  routes:
  - match:
      env: 'prod'
    receiver: 'slack-notifications-prod'
  - match:
      env: 'staging'
    receiver: 'slack-notifications-staging'
  - match:
      env: 'dev'
    receiver: 'slack-notifications-dev'

receivers:
- name: 'default'
- name: 'slack-notifications-prod'
...
- name: 'slack-notifications-staging'
...
- name: 'slack-notifications-dev'
...

The slack-notifications receivers are all the same and they only differ in one thing, which is the appropriate channel name. slack-notifications 接收器都是相同的,它们只有一件事不同,那就是适当的频道名称。

Current behaviour: All alerts are sent to the prod slack channel当前行为:所有警报都发送到 prod slack 通道

Expected behaviour: Alerts from "dev" env are sent to dev channel, "staging" to staging channel, and "prod" to prod channel.预期行为:来自“dev”env 的警报被发送到 dev 频道,“staging”到 staging 频道,“prod”到 prod 频道。

Alertmanager sees these labels just fine (judging from the info from alertmanager webUI). Alertmanager 可以很好地看到这些标签(从 alertmanager webUI 的信息来看)。

Turns out my config was fine and I was using a webhook URL which was tied only to one slack channel, I wasn't aware of that.结果我的配置很好,我使用了一个只与一个松弛通道相关联的 webhook URL,我不知道这一点。

You have to add continue: true attribute on the first match:您必须在第一场比赛中添加continue: true属性:

global:
  resolve_timeout: 1m
  slack_api_url: 'https://slack-url'

route:
  group_by: [...]
  receiver: 'default'
  routes:
  - match:
      env: 'prod'
    receiver: 'slack-notifications-prod'
    continue: true
  - match:
      env: 'staging'
    receiver: 'slack-notifications-staging'
  - match:
      env: 'dev'
    receiver: 'slack-notifications-dev'

receivers:
- name: 'default'
- name: 'slack-notifications-prod'
...
- name: 'slack-notifications-staging'
...
- name: 'slack-notifications-dev'
...

The AlertManager will evaluate children routes until there are no routes left or no routes for a given level are matching the current alert. AlertManager 将评估子路由,直到没有路由或给定级别的路由与当前警报匹配。

In that case, the AlertManager will take the configuration of the current node evaluated.在这种情况下,AlertManager 将采用评估的当前节点的配置。

The continue attribute is a value used to define if you want to evaluate route siblings (belonging to the same level) if a route on the same level was already matching. continue 属性是一个值,用于定义如果同一级别的路由已经匹配,是否要评估路由兄弟(属于同一级别)。

https://devconnected.com/alertmanager-and-prometheus-complete-setup-on-linux/ https://devconnected.com/alertmanager-and-prometheus-complete-setup-on-linux/

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

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