1 添加钉钉机器人,获取webhook
参考 https://open-doc.dingtalk.com/docs/doc.htm?treeId=257&articleId=105735&docType=1
2 下载插件(二进制文件)
$ wget https://github.com/timonwong/prometheus-webhook-dingtalk/releases/download/v0.3.0/prometheus-webhook-dingtalk-0.3.0.linux-amd64.tar.gz
3 解压并move至/usr/local/prometheus目录下
$ tar zxvf prometheus-webhook-dingtalk-0.3.0.linux-amd64.tar.gz$ mv prometheus-webhook-dingtalk-0.3.0.linux-amd64/prometheus-webhook-dingtalk /usr/local/prometheus/alertmanager
4 编辑启动脚本(请替换为自己的webhook URL 及 ding.profile)
$ cat dingding_start.shnohup /usr/local/prometheus/alertmanager/prometheus-webhook-dingtalk --ding.profile="ops_dingding=https://oapi.dingtalk.com/robot/send?access_token=XXXXXXX" 2>&1 1>/usr/local/prometheus/alertmanager/dingding.log &$ sh dingding_start.sh
5 编辑alertmanager.yml,增加web_hook配置并重启alertmanager
- name: 'ops_dingding'webhook_configs:- url: 'http://127.0.0.1:8060/dingtalk/dingtalk_u/send'send_resolved: true
6.supervisor守护
[program:dingtalk]command=/opt/soft/monitor/prometheus-webhook-dingtalk/prometheus-webhook-dingtalk --ding.profile='dingtalk_u=https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxx' --ding.timeout=5s --log.level=info;process_name=%(program_name)s ; process_name expr (default %(program_name)s)numprocs=1 ; number of processes copies to start (def 1)directory=/opt/soft/monitor/prometheus-webhook-dingtalk;umask=022 ; umask for process (default None);priority=999 ; the relative start priority (default 999)autostart=true ; start at supervisord start (default: true)autorestart=unexpected ; whether/when to restart (default: unexpected)startsecs=1 ; number of secs prog must stay running (def. 1)startretries=3 ; max # of serial start failures (default 3)exitcodes=0,2 ; 'expected' exit codes for process (default 0,2)stopsignal=QUIT ; signal used to kill process (default TERM)stopwaitsecs=3 ; max num secs to wait b4 SIGKILL (default 10);stopasgroup=false ; send stop signal to the UNIX process group (default false);killasgroup=false ; SIGKILL the UNIX process group (def false)user=prometheusredirect_stderr=true ; redirect proc stderr to stdout (default false)stdout_logfile=/var/log/supervisor/dingtalk.log ; stdout log path, NONE for none; default AUTOstdout_logfile_maxbytes=10MB ; max # logfile bytes b4 rotation (default 50MB)stdout_logfile_backups=3 ; # of stdout logfile backups (default 10);stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0);stdout_events_enabled=false ; emit events on stdout writes (default false);stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB);stderr_logfile_backups=10 ; # of stderr logfile backups (default 10);stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0);stderr_events_enabled=false ; emit events on stderr writes (default false);environment=A="1",B="2" ; process environment additions (def no adds);serverurl=AUTO ; override serverurl computation (childutils)