Day6-03 Prometheus之钉钉报警配置

一、概述

本文将介绍通过prometheus + alertmanager的方式实现钉钉报警。

二、获取自定义机器人webhook

操作方法引自钉钉官方开发文档:https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq

  • 打开PC端钉钉,点击头像,选择“机器人管理”。

  • 在机器人管理页面选择“自定义”机器人,输入机器人名字并选择要发送消息的群,同时可以为机器人设置机器人头像。

  • 完成必要的安全设置(至少选择一种),勾选 我已阅读并同意《自定义机器人服务及免责条款》,点击“完成”。安全设置目前有3种方式,设置说明见下文介绍。

  • 完成安全设置后,复制出机器人的Webhook地址,可用于向这个群发送消息,格式如下:

https://oapi.dingtalk.com/robot/send?access_token=XXXXXX

三、将钉钉接入 Prometheus AlertManager WebHook

官方GitHub地址:https://github.com/timonwong/prometheus-webhook-dingtalk

  • 下载二进制安装包
shell> wget https://github.com/timonwong/prometheus-webhook-dingtalk/releases/download/v1.4.0/prometheus-webhook-dingtalk-1.4.0.linux-amd64.tar.gz
shell> tar zxvf prometheus-webhook-dingtalk-1.4.0.linux-amd64.tar.gz
shell> mv prometheus-webhook-dingtalk-1.4.0.linux-amd64 /usr/local/dingtalk/
  • 配置钉钉告警文件
shell> cd /usr/local/dingtalk/
# 替换 config.yml 文件中的 url 后面的值信息为 复制出机器人的Webhook地址
shell> cp config.example.yml config.yml
  • 启动 prometheus-webhook-dingtalk
shell> /usr/local/dingtalk/prometheus-webhook-dingtalk --log.level=info > dingding.log 2>&1 &
  • 配置系统服务
shell> vim /etc/systemd/system/prometheus-webhook-dingtalk.service
[Unit]
Description=prometheus-webhook-dingtalk
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/usr/local/dingtalk/prometheus-webhook-dingtalk
[Install]
WantedBy=multi-user.target

shell> chmod u+x /etc/systemd/system/prometheus-webhook-dingtalk.service
shell> systemctl daemon-reload
shell> systemctl start prometheus-webhook-dingtalk
shell> systemctl status prometheus-webhook-dingtalk

四、配置 alertmanager webhook

    receivers:
    - name: 'default'
      webhook_configs:
      - url: 'http://10.65.24.200:8060/dingtalk/sre/send'
        send_resolved: true

五、配置 prometheus

见《Day5-06 部署Alertmanager》,这里不再赘述。

六、查看告警

posted @ 2020-11-25 18:12  龍龍小宝  阅读(889)  评论(0编辑  收藏  举报