低版本Grafana使用原生webhook实现企业微信告警

公司现有生产环境普遍使用的还是Grafana7版本,而Grafana9版本才支持企业微信告警。钉钉倒是支持,但是公司不用钉钉,不想就为了这个下一个软件。且Grafana的版本升级太激进,每个大版本之间的差异巨大,我也不想升级,于是另辟蹊径,整了个脚本接收Grafana的POST请求,把请求内容发送到我的企业微信。
具体代码见:https://github.com/Charramma/sendtoWeCom

使用方法:

  1. 在sendtoWeCom.py同级目录下创建配置文件config.json,添加响应的配置项
配置项 说明
bind 监听IP
port 监听端口
route url路由
wecom.agentid 应用ID
wecom.secret 应用ID对应的Secret
wecom.cropid 企业ID
wecom.touser 接收人
wecom.toparty 部门ID

示例配置:

{
  "bind": "0.0.0.0",
  "port": "5000",
  "route": "/sendinfo",
  "wecom": {
    "agentid": "1000002",
    "secret": "cJPP.....3UFokA0",
    "cropid": "ww....89",
    "touser": "@all",
    "toparty": 1
  }
}
  1. 下载依赖库文件
pip install -r requirements.txt
  1. 运行
python sendtoWeCom.py
  1. Grafana配置

创建应用,获取agentid、cropid、Secret方法可以参考我以前的博文:https://www.cnblogs.com/CharrammaBlog/p/14873207.html

posted @ 2023-05-18 16:15  Charramma  阅读(617)  评论(0编辑  收藏  举报