# alertManagerWxhook **Repository Path**: brian_he/alert-manager-wxhook ## Basic Information - **Project Name**: alertManagerWxhook - **Description**: 通过AlertManager发送告警消息给企业微信机器人的项目 - **Primary Language**: Go - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 3 - **Created**: 2025-11-13 - **Last Updated**: 2025-11-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 1、启动服务 ## 1.1 手动运行 ```shell # 命令行启动,如需指定端口 --port 8080 go run main/main.go # 编译,注意windows编译的不适用于linux,需在linux编译 go build -o wxworkAlert main/main.go ``` ## 1.2 加入开机自启 ```shell mv wxworkAlert /usr/local/bin/ chmod +x /usr/local/bin/wxworkAlert # 编辑启动脚本 vim /usr/lib/systemd/system/wxworkalert.service [Unit] Description=webhook_wechat Documentation=https://prometheus.io/ After=network.target [Service] ExecStart=/usr/local/bin/wxworkAlert --port 8082 ExecReload=/bin/kill -HUP TimeoutStopSec=20s Restart=always [Install] WantedBy=multi-user.target # 配置开机自启动 systemctl daemon-reload systemctl restart wxworkalert systemctl enable wxworkalert systemctl status wxworkalert ``` # 2、docker方式 ```shell # 创建镜像 docker build -t alert:diy-wxwork-v1.0 . # 运行 docker run -itd -p8082:8082 --name wxwork_alert_server alert:diy-wxwork-v1.0 ``` # 3、测试调用 ```shell curl -X POST http://192.168.26.1:8082/alert?token=42c42314-ed25-4452-afe4-0b5338aa9a0f \ -H "Content-Type: application/json" \ -d '{ "alerts": [ { "status": "firing", "labels": { "severity": "critical", "alertname": "HighCPUUsage", "instance": "192.168.1.1:9100", "job": "node_exporter" }, "annotations": { "summary": "High CPU usage detected", "description": "CPU usage on instance 192.168.1.1 is above 90% for the last 5 minutes" }, "startsAt": "2025-03-03T03:00:00Z", "generatorURL": "http://prometheus:9090/graph?g0.expr=xxx" }, { "status": "resolved", "labels": { "severity": "critical", "alertname": "HighCPUUsage", "instance": "192.168.1.1:9100", "job": "node_exporter" }, "annotations": { "summary": "High CPU usage detected", "description": "CPU usage on instance 192.168.1.1 is above 90% for the last 5 minutes" }, "startsAt": "2025-03-03T03:00:00Z", "endsAt": "2025-03-03T03:15:00Z", "generatorURL": "http://prometheus:9090/graph?g0.expr=xxx" } ] }' ``` # 4、效果 ![img_3.png](img_3.png) ![img_2.png](img_2.png)