# alertmanager-wechatrobot-webhook **Repository Path**: cynen/alertmanager-wechatrobot-webhook ## Basic Information - **Project Name**: alertmanager-wechatrobot-webhook - **Description**: 企业微信的webhook. wechatrobot-webhook - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2023-08-04 - **Last Updated**: 2025-04-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # alertmanager-wechatrobot-webhook Convert alertmanger webhook messages to qiye WeChat robots that can receive messages # Dockerfile ``` # 带自编译的Dockerfile # alpine的源配置的是ustc.可以更换的. # complie FROM golang:1.19-alpine AS golang RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \ && apk add git \ && go env -w GOPROXY=https://goproxy.cn \ && git clone https://gitee.com/cynen/alertmanager-wechatrobot-webhook.git \ && cd alertmanager-wechatrobot-webhook \ && go build -o wechat-webhook # build images FROM alpine:3.17 ENV LANG C.UTF-8 ENV TZ=Asia/Shanghai RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \ && apk update && apk upgrade \ && apk add ca-certificates\ && update-ca-certificates \ && apk --no-cache add openssl wget \ && apk add --no-cache bash tzdata curl \ && set -ex \ && mkdir -p /usr/bin \ && mkdir -p /usr/sbin COPY --from=golang /go/alertmanager-wechatrobot-webhook/wechat-webhook /usr/bin/ CMD ["wechat-webhook"] ``` ## How use ``` ./bin/alertmanager-wechatbot-webhook --RobotKey="xxxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx" ``` or ``` go run alertmanager-wechatbot-webhook.go --RobotKey="xxxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx" ``` ## configure alertmanager.yml ``` receivers: - name: webhook-test webhook_configs: - url: 'http://127.0.0.1:8999/webhook?key=xxxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx' ``` prometheus rules configure ``` groups: - name: ansible managed alert rules rules: - alert: CriticalCPULoad expr: (100 * (1 - avg(irate(node_cpu_seconds_total{mode="idle"}[5m])) BY (instance))) > 96 for: 2m labels: severity: critical annotations: description: '{{ $labels.instance }} of mountpoint {{ $labels.mountpoint }} has Critical CPU load for more than 2 minutes.' summary: Instance {{ $labels.instance }} - Critical CPU load wechatRobot: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxx-xxxxxxxx-xxxxx-xxxxxx" ``` ## test ### 1、使用默认微信机器人发送消息 ``` curl 'http://127.0.0.1:8999/webhook' -H 'Content-Type: application/json' -d ' { "receiver": "webhook-test", "status": "firing", "alerts": [ { "status": "firing", "labels": { "alertname": "test alert1", "instance": "example1", "severity": "critical" }, "annotations": { "info": "Test message,ignore", "description": "This is test summary,ignore", "summary": "This is test message,ignore" }, "startsAt": "2019-07-24T02:38:30.763785079Z", "endsAt": "0001-01-01T00:00:00Z", "generatorURL": "critical" } ], "groupLabels": { "alertname": "test alert1" }, "commonLabels": { "alertname": "test alert1", "instance": "example1" }, "commonAnnotations": { "info": "Test message,ignore", "summary": "This is test summary,ignore" }, "externalURL": "http://localhost:9093", "version": "4", "groupKey": "{}/{alertname=~\"^(?:test.*)$\"}:{alertname=\"test alert1\"}" }' ``` ### 2、使用指定微信机器人发送消息 ``` curl 'http://127.0.0.1:8999/webhook?key=xxxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx' -H 'Content-Type: application/json' -d ' { "receiver": "webhook-test", "status": "firing", "alerts": [ { "status": "firing", "labels": { "alertname": "test alert1", "instance": "example1", "severity": "critical" }, "annotations": { "info": "Test message,ignore", "description": "This is test summary,ignore", "summary": "This is test message,ignore" }, "startsAt": "2019-07-24T02:38:30.763785079Z", "endsAt": "0001-01-01T00:00:00Z", "generatorURL": "critical" } ], "groupLabels": { "alertname": "test alert1" }, "commonLabels": { "alertname": "test alert1", "instance": "example1" }, "commonAnnotations": { "info": "Test message,ignore", "summary": "This is test summary,ignore" }, "externalURL": "http://localhost:9093", "version": "4", "groupKey": "{}/{alertname=~\"^(?:test.*)$\"}:{alertname=\"test alert1\"}" }' ``` ### 3、使用alert内容指定微信机器人发送消息 ``` curl 'http://127.0.0.1:8999/webhook' -H 'Content-Type: application/json' -d ' { "receiver": "webhook-test", "status": "firing", "alerts": [ { "status": "firing", "labels": { "alertname": "test alert1", "instance": "example1", "severity": "critical" }, "annotations": { "info": "Test message,ignore", "description": "This is test summary,ignore", "summary": "This is test message,ignore" }, "startsAt": "2019-07-24T02:38:30.763785079Z", "endsAt": "0001-01-01T00:00:00Z", "generatorURL": "critical" } ], "groupLabels": { "alertname": "test alert1" }, "commonLabels": { "alertname": "test alert1", "instance": "example1" }, "commonAnnotations": { "info": "Test message,ignore", "summary": "This is test summary,ignore", "wechatRobot": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx" }, "externalURL": "http://localhost:9093", "version": "4", "groupKey": "{}/{alertname=~\"^(?:test.*)$\"}:{alertname=\"test alert1\"}" }' ```