【问题标题】:Prometheus alertmanager 只发送邮件
【发布时间】:2022-01-16 21:05:50
【问题描述】:

我有 prometheus alertmanager 和简单的规则

prometheus.yml

  • job_name:“Host_PRO” 静态配置:

    • 目标:[“192.168.0.17:9100”] 标签: 组:“警报”
  • job_name:“Host_PRE” 静态配置:

    • 目标:["10.2.2.235:9100"] 标签: 组:'noalert' 名称:'PVE'

alertmanager.yml

global:
  # The smarthost and SMTP sender used for mail notifications.
  smtp_smarthost: 'example:587'
  smtp_from: 'example'
  smtp_auth_username: 'example'
  smtp_auth_password: 'example'
  smtp_require_tls: true
route:
  group_by: ['alertname']
  group_wait: 10s
  group_interval: 10s
  repeat_interval: 24h
  routes:
    - match:
        group: alert 
      receiver: mail
receivers:
- name: 'mail'
  email_configs:
  - to: 'example@gmail.com'

示例规则

- alert: NodeCPU_0_High
  expr: 100 - (avg by(instance, cpu) (irate(node_cpu_seconds_total{mode="idle", cpu="0"}[1m])) * 100) > 80
  for: 2m
  labels:
    severity: critical
    app_type: linux
    category: cpu
  annotations:
    summary: "Node CPU_0 usage is HIGH"
    description: "CPU_0 load for instance {{ $labels.instance }} has reached {{ $value }}%"

如何仅当组“警报”的主机为高时发送电子邮件?

【问题讨论】:

  • 已经这样配置了吧?
  • 不幸的是,我的配置不起作用 :( 仍然收到来自 noalert 组的电子邮件
  • 我唯一想出但有效的方法:) link

标签: prometheus prometheus-alertmanager


【解决方案1】:

在 alertmanager.yml 文件中设置如下:

route:

  ...

  routes:
    - receiver: none
      matchers:
      - group != alert

    - receiver: mail
      matchers:
      - group = alert 

receivers:
  - name: none

  - name: 'mail'
    email_configs:
      - to: 'example@gmail.com'

【讨论】:

    猜你喜欢
    • 2016-03-15
    • 2022-01-06
    • 2019-06-21
    • 2022-07-13
    • 1970-01-01
    • 2021-06-04
    • 2020-10-21
    • 1970-01-01
    • 2016-06-08
    相关资源
    最近更新 更多