# am-dingtalk-webhook **Repository Path**: foxpast/am-dingtalk-webhook ## Basic Information - **Project Name**: am-dingtalk-webhook - **Description**: 支持发送 Prometheus 2.0 告警消息到钉钉的webhook - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2023-10-27 - **Last Updated**: 2024-10-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Alertmanager Dingtalk Webhook 对接alertmanager组件,支持发送 Prometheus 2.0 告警消息到钉钉的webhook。 #@ 1 Docker运行方式 1. 修改 buildImage.sh 中的IMG,然后执行 ```shell sh buildImage.sh ``` 2. 在要部署的服务器上,准备启动脚本 ```shell [root@jh-monitor webhook]# cat start.sh # 若钉钉机器人加密方式为:加签 #./am-dingtalk-webhook -defaultRobot=https://oapi.dingtalk.com/robot/send?access_token=XXX \ # -robotType=sign \ # -secret=xxxxxx \ # -env=上海临港 # 若钉钉机器人加密方式为:关键字 # ./am-dingtalk-webhook -defaultRobot=https://oapi.dingtalk.com/robot/send?access_token=XXX -env=亲清测试 docker rm -f am-ding-webhook sleep 2 docker run -d -p 8890:8888 --restart=always --name=am-ding-webhook \ harbor.hzxingzai.cn/dev/am-webhook:0.2.14 \ ./webhook \ -defaultRobot=https://oapi.dingtalk.com/robot/send?access_token=xxxxx \ -robotType=sign \ -secret=xxxxx \ -env=金华 \ -includeSeverities=严重,警告,warning,critical \ -atAll=true ``` 3. 启动docker ```shell sh start.sh ``` ## 二进制启动方式 #### 编译二进制程序 ```shell $ go build # 指定编译X64架构程序 $ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build webhook.go # 指定编译ARM架构程序 $ CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build webhook.go ``` #### 启动程序 1. 如果钉钉机器人验证为加签方式,本程序启动实例如下: ```shell $ ./am-dingtalk-webhook -defaultRobot=https://oapi.dingtalk.com/robot/send?access_token= \ -robotType=sign \ -secret=SEC2d87a5c8098fada6c67a944602cfd6190c35c16da32543c99cf8a10514d83498 \ -env=亲清测试 ``` 2. 如果钉钉机器人验证为关键字方式,本程序启动实例如下: (钉钉机器人关键字可选用:巡检、告警) ```shell $ ./am-dingtalk-webhook -defaultRobot=https://oapi.dingtalk.com/robot/send?access_token= -env=亲清测试 ``` #### 启动参数介绍 - -defaultRobot: 默认的钉钉告警 webhook 地址, 所有altermanage的通知到会发送到此地址 - -env: 环境名,用去区分多个不同alernmanager所处的环境,告警信息会带此标签 ```shell ./webhook -h Usage of ./webhook: -atAll 钉钉消息是否At所有人 -defaultRobot string global dingtalk robot webhook, you can overwrite by alert rule with annotations dingtalkRobot -env string 告警标题显示所属的业务环境线 (default "默认环境") -h help -includeSeverities string 发送严重等级列表,多个用逗号隔开,不填则默认发送全部。示例:"critical,严重" -port int 服务端口 (default 8888) -robotType string 钉钉机器人类型,枚举:sign/keywords (default "keywords") -secret string 如果机器人使用加签方式,这里填写密钥 ``` #### Prometheus Rule示例 ```yaml groups: - name: hostStatsAlert rules: - alert: hostCpuUsageAlert expr: sum(avg without (cpu)(irate(node_cpu{mode!='idle'}[5m]))) by (instance) > 0.85 for: 1m labels: severity: page annotations: summary: "Instance {{ $labels.instance }} CPU usgae high" description: "{{ $labels.instance }} CPU usage above 85% (current value: {{ $value }})" ```