prometheus 对接飞书告警
prometheus对接飞书告警
- 环境
名称 | ip地址 | cpu | 内存 |
---|---|---|---|
yz-feishu | 10.65.6.91 | 4c | 8G |
- 飞书创建群组机器人,参考飞书官网
#备注:自定义机器人要增加ip 白名单限制
#还要复制 webhook 地址,后续要和 PrometheusAlert 中的路径进行拼接
https://open.feishu.cn/open-apis/bot/v2/hook/23b75d6axxxxxxxxxxxxxxxxxxxxx
- prometheus、alertmanager 部署
- docker 启动安装 PrometheusAlert
#百度网盘提取docker 镜像压缩包
链接:https://pan.baidu.com/s/1T4YL64Ni8ZfEo9oXJrFW6Q
提取码:0035
#下载并启动docker
docker load -i prome.tgz
docker tag feiyu563/prometheus-alert:latest feiyu563/prometheus-alert:feishu
docker run -d -p 8080:8080 -e PA_LOGIN_USER=prometheusalert -e PA_LOGIN_PASSWORD=prometheusalert -e PA_TITLE=PrometheusAlert -e PA_OPEN_FEISHU=1 feiyu563/prometheus-alert:feishu
#查看docker
docker ps
- 配置模板
#访问
http://10.65.6.91:8080/
#添加并创建模板,模板内容
{{ $var := .externalURL}}{{ range $k,$v:=.alerts }}
{{if eq $v.status "resolved"}}
**[Prometheus恢复信息]({{$v.generatorURL}})**
*[{{$v.labels.alertname}}]({{$var}})*
告警级别:{{$v.labels.severity}}
运维团队:{{$v.labels.team}}
pod 命名空间:{{$v.labels.namespace}}
pod名称:{{$v.labels.pod}}
开始时间:{{TimeFormat $v.startsAt "2006-01-02 15:04:05"}}
结束时间:{{TimeFormat $v.endsAt "2006-01-02 15:04:05"}}
故障主机IP:{{$v.labels.instance}}
**{{$v.annotations.description}}**
{{else}}
**[Prometheus告警信息]({{$v.generatorURL}})**
*[{{$v.labels.alertname}}]({{$var}})*
告警级别:{{$v.labels.severity}}
运维团队:{{$v.labels.team}}
pod 命名空间:{{$v.labels.namespace}}
pod名称:{{$v.labels.pod}}
开始时间:{{TimeFormat $v.startsAt "2006-01-02 15:04:05"}}
结束时间:{{TimeFormat $v.endsAt "2006-01-02 15:04:05"}}
故障主机IP:{{$v.labels.instance}}
**{{$v.annotations.description}}**
{{end}}
{{ end }}
#复制创建模板的路径,并和飞书中创建机器人的url 进行拼接
- alertmanager 对接PrometheusAlert
#修改 alertmanager 中的 webhook_configs地址,将钉钉信息修改为 飞书, fsurl=https://open.feishu.cn/open-apis/bot/v2/hook/23b75d6axxxxxxxxxxxxxxxxxxxxx,这个地址为上面自定义机器人生成的 webhook 地址。
cat alert-config.yaml
apiVersion: v1
data:
config.yml: |-
global:
smtp_smarthost: 'smtp.feishu.cn:465'
smtp_from: 'xxxx'
smtp_auth_username: 'xxx'
smtp_auth_password: 'xxx'
smtp_require_tls: false
route:
group_by: ['alertname', 'cluster']
group_wait: 30s
group_interval: 1m
repeat_interval: 50m
receiver: default
routes:
- receiver: email
group_wait: 10s
match:
team: node
#- receiver: agcm-platform
# group_wait: 10s
# match:
# user: agcm-platform
receivers:
- name: 'default'
email_configs:
- to: 'gixxx@movie.cn'
- to: 'wisd@movie.cn'
send_resolved: true
webhook_configs:
- url: 'http://10.65.6.91:8080/prometheusalert?type=fs&tpl=prometheus-k8s&fsurl=https://open.feishu.cn/open-apis/bot/v2/hook/23b75d6axxxxxxxxxxxxxxxxxxxxx'
send_resolved: true
- name: 'email'
email_configs:
- to: 'gixxx@movie.cn'
- to: 'wisd@movie.cn'
send_resolved: true
webhook_configs:
- url: 'http://10.65.6.91:8080/prometheusalert?type=fs&tpl=prometheus-k8s&fsurl=https://open.feishu.cn/open-apis/bot/v2/hook/23b75d6axxxxxxxxxxxxxxxxxxxxx'
send_resolved: true
kind: ConfigMap
metadata:
name: alert-config
namespace: prometheus
# 更新alert-config.yaml
kubectl apply -f alert-config.yaml
#查看飞书告警群,对接飞书告警完成!