prometheus-webhook-dingtalk 安装
1、编译安装
------------------------ 安装 go 环境 ---------------------------
yum -y install go
# 在GOPATH下新建目录
cd /srv
------------------------- 安装钉钉插件 -----------------------------
git clone https://github.com/timonwong/prometheus-webhook-dingtalk.git
------------------------ 安装nodejs -------------------------------
wget https://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.xz
tar xf node-v12.16.1-linux-x64.tar.xz -C /usr/local/
cd /usr/local && mv node-v12.16.1-linux-x64 nodejs
vim /etc/profile.d/nodejs.sh
export NODE_HOME=/usr/local/nodejs
export PATH=$PATH:$NODE_HOME/bin
source /etc/profile
-------------------------- 安装yarn环境 ---------------------------
cd /srv/prometheus-webhook-dingtalk
make build
-------------------------- 启动配置 -------------------------------
mkdir /data/dingtalk
cp config.example.yml /data/dingtalk/config.yml
ln -s /root/go/src/github.com/timonwong/prometheus-webhook-dingtalk/prometheus-webhook-dingtalk /usr/local/bin/
# 下载并安装
wget https://github.com/timonwong/prometheus-webhook-dingtalk/releases/download/v0.3.0/prometheus-webhook-dingtalk-0.3.0.linux-amd64.tar.gz
tar -zxf prometheus-webhook-dingtalk-0.3.0.linux-amd64.tar.gz -C /opt/
mv /opt/prometheus-webhook-dingtalk-0.3.0.linux-amd64 /opt/prometheus-webhook-dingtalk
----------------------------------- 单文件模式
vim /etc/systemd/system/prometheus-webhook-dingtalk.service
#添加如下内容
[Unit]
Description=prometheus-webhook-dingtalk
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/opt/prometheus-webhook-dingtalk/prometheus-webhook-dingtalk --ding.profile=ops_dingding=自己钉钉机器人的Webhook地址
[Install]
WantedBy=multi-user.target
#命令行启动
systemctl daemon-reload
systemctl start prometheus-webhook-dingtalk
ss -tnl | grep 8060
#测试
curl -H "Content-Type: application/json" -d '{ "version": "4", "status": "firing", "description":"description_content"}' http://localhost:8060/dingtalk/ops_dingding/send
---------------------------------------------------------- 配置文件模式
[root@SVR-Prometheus01 prometheus-webhook-dingtalk]# cat dingtalk-webhook.yml
## Request timeout
timeout: 5s
## Customizable templates path
templates:
- contrib/templates/legacy/template.tmpl
## You can also override default template using `default_message`
### The following example to use the 'legacy' template from v0.3.0
## default_message:
## title: '{{ template "legacy.title" . }}'
## text: '{{ template "legacy.content" . }}'
## Targets, previously was known as "profiles"
targets:
webhook1:
url:
# secret for signature
secret: SEC000000000000000000000
webhook2:
url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
webhook_legacy:
url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
# Customize template content
message:
# Use legacy template
title: '{{ template "legacy.title" . }}'
text: '{{ template "legacy.content" . }}'
webhook_mention_all:
url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
mention:
all: true
webhook_mention_users:
url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
mention:
mobiles: ['156xxxx8827', '189xxxx8325']
-----------------------------------
--------------------------- 配置告警
cat /opt/alertmanager/alertmanager.yml
global:
resolve_timeout: 1m
route:
group_by: ['alertname']
group_wait: 30s
group_interval: 5m
repeat_interval: 1h
receiver: 'ops_dingding'
routes:
- match:
team: node
receivers:
- name: 'ops_dingding'
webhook_configs:
- url: 'http://x.x.x.x:8060/dingtalk/ops_dingding/send'
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'dev', 'instance']
-----------------------------------
cat /opt/prometheus/rules/node_down.yml
groups:
- name: Node_Down
rules:
- alert: Node实例宕机
expr: up == 0
for: 10s
labels:
user: prometheus
severity: Warning
annotations:
summary: "{{ $labels.instance }} 服务宕机"
description: "{{ $labels.instance }} of job {{ $labels.job }} has been Down."
修改Prometheus配置文件
cat /opt/prometheus/prometheus.yml
# 修改以下内容
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets: ["x.x.x.x:9093"]
rule_files:
- ./rules/*.yml
#重启
systemctl restart prometheus