Prometheus配置飞书告警

管理员
 
 
 
1、通过 PrometheusAlert全家桶对接飞书告警,PrometheusAlert全家桶安装步骤 https://github.com/feiyu563/PrometheusAlert
 
 
2、配置 alermanager告警服务
[root@iZwz9ixflmggrbc154y075Z prometheus]# vim prometheus-alert-conf.yaml
 
kind: ConfigMap
apiVersion: v1
metadata:
name: alermanager
namespace: prometheus
data:
config.yml: |-
global:
resolve_timeout: 30s
route:
receiver: webhook
group_wait: 10s
group_interval: 20s
repeat_interval: 30m
group_by: [alertname]
routes:
- receiver: webhook
group_wait: 10s
match:
team: node
receivers:
- name: webhook
webhook_configs:
- url: 'http://47.106.204.250:8080/prometheusalert?type=fs&tpl=prometheus-fs&fsurl=https://open.feishu.cn/open-apis/bot/v2/hook/327baeb5-2c41-4924-aab8-948ab9b4a92c&at=zhangsan@xxx.com'
send_resolved: true
- url: 'http://47.106.204.250:8080/prometheusalert?type=fs&tpl=prometheus-fs&fsurl=https://open.feishu.cn/open-apis/bot/v2/hook/327baeb5-2c41-4924-aab8-948ab9b4a92c&at=zhangsan@xxx.com'
send_resolved: true
 
3、启动 alermanager
[root@iZwz9ixflmggrbc154y075Z prometheus]# kubectl create -f prometheus-alert-conf.yaml
 
4、查看alermanager是否启动
 
 
 
5、告警模板
 
{{ range $k,$v:=.alerts }}
{{- if eq $v.status "firing" }}
**[Pod状态] 告警**
告警类型: {{$v.labels.alertname}}
命名空间: {{$v.labels.namespace}}
服务名称: {{$v.annotations.summary}}
告警级别: {{$v.labels.severity}}
告警时间: {{GetCSTtime $v.startsAt}}
{{else}}
**[Pod状态] 恢复**
告警类型: {{$v.labels.alertname}}
命名空间: {{$v.labels.namespace}}
服务名称: {{$v.annotations.summary}}
告警级别: {{$v.labels.severity}}
告警时间: {{GetCSTtime $v.startsAt}}
恢复时间: {{GetCSTtime $v.endsAt}}
{{ end }}
{{ end }}