Prometheus之 PrometheusAlert 企微告警

前言:我们部署的prometheus外加alertmanager可以做告警推送,但是会比较麻烦,钉钉和邮箱还好。企业微信的话还需要配置企业ID非常不方便,新建一个机器人也用不了,登录企业不是管理员也看不到企业ID。我们现在有个新的告警推送平台是PrometheusAlert .可以兼容各种推送告警电话、短信、云平台、邮件、企微等等。

1、介绍部署方法

容器部署

# git clone https://github.com/feiyu563/PrometheusAlert.git
# mkdir /etc/prometheusalert-center/
# cp PrometheusAlert/conf/app.conf /etc/prometheusalert-center/
# docker run -d -p 8080:8080 -v /etc/prometheusalert-center:/app/conf --name prometheusalert-center feiyu563/prometheus-alert:latest

Linux部署

# git clone https://github.com/feiyu563/PrometheusAlert.git
# cd PrometheusAlert/example/linux/

# 后台运行请执行 nohup ./PrometheusAlert &
# ./PrometheusAlert

Windows 系统部署

# git clone https://github.com/feiyu563/PrometheusAlert.git
# cd PrometheusAlert/example/windows/


双击运行 PrometheusAlert.exe 即可

K8S部署

# kubectl app -n 命名空间 -f https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/example/kubernetes/PrometheusAlert-Deployment.yaml
这里我用的是k8s部署的方式
wget https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/example/kubernetes/PrometheusAlert-Deployment.yaml
这里我打开了ingress方便页面测试,和修改的微信的地址具体看下面截图
vim PrometheusAlert-Deployment.yaml
kubectl apply -n public-service -f PrometheusAlert-Deployment.yaml

页面登录查看启动情况(访问ingress地址:alert-center.local)

可以点击测试看看企微通不通

证明可以通过

修改alertmanager的配置文件配置PrometheusAlert的地址

可以参考以下配置文件

global:
  resolve_timeout: 5m
route:
  group_by: ['instance']
  group_wait: 10m
  group_interval: 10s
  repeat_interval: 10m
  receiver: 'web.hook.prometheusalert'
  routes:
  - receiver: 'prometheusalert-weixin'
    group_wait: 10s
    match:
      level: '1'
  - receiver: 'prometheusalert-dingding'
    group_wait: 10s
    match:
      level: '2'
  - receiver: 'prometheusalert-feishu'
    group_wait: 10s
    match:
      level: '3'
  - receiver: 'prometheusalert-all'
    group_wait: 10s
    match:
      level: '4'
receivers:
- name: 'web.hook.prometheusalert'
  webhook_configs:
  - url: 'http://[prometheusalert_url]:8080/prometheus/alert'
- name: 'prometheusalert-weixin'
  webhook_configs:
  - url: 'http://[prometheusalert_url]:8080/prometheus/router?wxurl=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxx'
- name: 'prometheusalert-dingding'
  webhook_configs:
  - url: 'http://[prometheusalert_url]:8080/prometheus/router?ddurl=https://oapi.dingtalk.com/robot/send?access_token=xxxxx'
- name: 'prometheusalert-feishu'
  webhook_configs:
  - url: 'http://[prometheusalert_url]:8080/prometheus/router?fsurl=https://open.feishu.cn/open-apis/bot/hook/xxxxxxxxx'
- name: 'prometheusalert-all'
  webhook_configs:
  - url: 'http://[prometheusalert_url]:8080/prometheus/router?wxurl=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxx&ddurl=https://oapi.dingtalk.com/robot/send?access_token=xxxxx&phone=15395105573'

 

配置完成后我们测试告警是否能发到企微

# stress -c 4
提高CPU使用率

等待几分钟后企微收到告警

posted @ 2022-05-07 16:28  Throb_JL  阅读(2246)  评论(0编辑  收藏  举报