【问题标题】:Customizing Prometheus AlertManager notifications in Slack在 Slack 中自定义 Prometheus AlertManager 通知
【发布时间】:2018-10-21 18:02:52
【问题描述】:

我很少有安装和配置 WMI 的 Win 服务器(如 Build、DB、App 等),并且能够在我的 Prometheus 仪表板上读取指标(基于磁盘空间 >90 等规则)。

在同一个盒子上设置一个 Altermanager,我正在将 Metrics (Diskspace >90) 详细信息写入我的 Slack Channel。

route:
 group_by: [cluster]
 # If an alert isn't caught by a route, send it slack.
 receiver: slack
 routes:
  # Send severity=slack alerts to slack.
  - match:
      severity: critical
    receiver: slack
receivers:
- name: slack
  slack_configs:
  - api_url: 'https://hooks.slack.com/services/Token'
    channel: '#alerts'

Slack 通知的输出是 - 实际

有没有一种方法可以让我准备好 Machine Name - 以及将其与 Tag Name 区分开来 - 比如 Build 、 Db 等?

我希望通知更具可读性,如下所示,(我从一些博客中得到)你能建议吗?

预期

非常感谢任何输入。

谢谢,

【问题讨论】:

  • 我认为分享警报规则很好......会有标签可以给你机器名称。警报管理器只是按原样传递标签和内容。

标签: yaml slack prometheus prometheus-alertmanager


【解决方案1】:

你可以从这个很好的例子开始。在slack_configs下添加这个:

        text: >-
          {{ range .Alerts }}
             *Alert:* {{ .Annotations.summary }} - `{{ .Labels.severity }}`
            *Description:* {{ .Annotations.description }}
            *Graph:* <{{ .GeneratorURL }}|:chart_with_upwards_trend:> *Runbook:* <{{ .Annotations.runbook }}|:spiral_note_pad:>
            *Details:*
            {{ range .Labels.SortedPairs }} • *{{ .Name }}:* `{{ .Value }}`
            {{ end }}
          {{ end }}

【讨论】:

  • 您在哪里找到 .GeneratorURL ?警报在哪里?
  • The generatorURL field is a unique back-link which identifies the causing entity of this alert in the client. - 我找到了here
  • 我发现您在 Prometheus 中使用 --web.externalurl 标志设置了它。
【解决方案2】:

在接收者部分添加一个“文本”字段。这将允许您从prometheus-rules.yaml 文件中提取信息。

receivers:
- name: slack
  slack_configs:
  - api_url: 'https://hooks.slack.com/services/Token'
    channel: '#alerts'
    text: "<!channel> \n summary: {{ .CommonAnnotations.summary }}\n description: {{ .CommonAnnotations.description }}"

【讨论】:

    猜你喜欢
    • 2021-11-25
    • 2020-10-21
    • 2019-03-28
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 2020-01-30
    • 1970-01-01
    相关资源
    最近更新 更多