【问题标题】:How to discard alert summary when alert status is RESOLVED in Prometheus Alertmanager?Prometheus Alertmanager中警报状态为RESOLVED时如何丢弃警报摘要?
【发布时间】:2021-04-11 05:45:01
【问题描述】:

考虑一个简单的警报:

      - alert: SomeAlert
      expr: SomeExpression > SomeValue
      labels:
        severity: notification
        slack: SomeSlackChannel
      annotations:
        summary: "This alert was fired!"

现在我只想在警报状态为 FIRING 时显示summary。如果是 RESOLVED 状态,我想从 slack 通知中丢弃警报摘要。

如何根据警报状态选择性地显示/隐藏警报摘要?

我尝试了以下方法:

      - alert: SomeAlert
      expr: SomeExpression > SomeValue
      labels:
        severity: notification
        slack: SomeSlackChannel
      {{ if eq .Status "firing }}
      annotations:
        summary: "This alert was fired!"
      {{ end }}

但是没有用。似乎无法访问 .Status 以有条件地显示/隐藏警报摘要。

【问题讨论】:

  • “隐藏警报摘要”是什么意思,您希望通过它实现什么?
  • 我希望显示 RESOLVED 警报,但没有我在 FIRING 类型的警报中看到的任何详细信息。

标签: prometheus go-templates prometheus-alertmanager


【解决方案1】:

您需要在 Alertmanager 模板级别执行此操作。

  1. 配置您的模板。无论是用于电子邮件的 HTML,还是用于 Slack 的文本等。

{{ define "simply.resolved" }}The alert is resolved.{{ end}}

  1. 配置 alertmanager 接收器以使用此模板。
  name: my_receiver
  slack_configs:
  - send_resolved: true
    text: '{{ template "simply.resolved" . }}'

更多信息:https://prometheus.io/docs/alerting/latest/notification_examples/

【讨论】:

    猜你喜欢
    • 2021-12-11
    • 2022-07-13
    • 1970-01-01
    • 2016-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多