Prometheus发送报警1--如何发送报警到Teams

MS Teams中创建webhook

参考地址:
https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=newteams%2Cdotnet

配置AlertManager

分为两个版本,旧版本和新版本

老版本

老版本请参考这个工具
https://github.com/prometheus-msteams/prometheus-msteams

新版本

在新版本中,我们就可以直接使用teams配置来
https://prometheus.io/docs/alerting/latest/configuration/#msteams_config

配置receiver

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
      - name: 'teams'
msteams_configs:
- webhook_url: '{{ webhook_url }}'
title: '{{ template "teams_alert_title" . }}'
text: '{{ template "teams_alert_message" . }}'
templateFiles:
teams_alert_title.tmpl: |-
{{ define "teams_alert_title" }}[{{ .Status | toUpper }}] {{ .CommonLabels.alertname }}{{- end }}
teams_alert_message.tmpl: |-
{{ define "teams_alert_message" }}
{{ range .Alerts }}
*Environment:* megatron-dev-eks-cluster
*Namespace:* {{ .Labels.namespace }}
*Pod:* {{ .Labels.pod }}
*Summary:* {{ .Annotations.summary }}
*Description:* {{ .Annotations.description }}
*Runbook_Url:* {{ .Annotations.runbook_url }}
{{ end }}
{{- end }}

webhook_url 为在Teams中创建的webhook
我们可以直接使用这个template,也可以加一些其他的内容

配置route

  routes:
  - receiver: 'xxx'
    continue: true
  - receiver: 'teams'

测试是否可行

经过上面的配置,在Teams中我们确实可以收到对应的alert,因此配置成功