# alertmanager-dingding **Repository Path**: Davin168/alertmanager-dingding ## Basic Information - **Project Name**: alertmanager-dingding - **Description**: alertmanager通过钉钉报警的插件 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-08-17 - **Last Updated**: 2022-10-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # alertmanager-dingding 插件 AlertManager 钉钉报警示例 ![1](image/1.jpg) ## 运行 ### 使用`Docker`运行 git clone此源码到本地目录/data/alertmanager-dingding ```shell cd /data/alertmanager-dingding docker build -t cdwen/alertmanager-dingding:v1 . ``` ```shell docker run -p 5000:5000 --name dingding -e ding_token=<钉钉机器人TOKEN> -e ding_secret=<钉钉机器人安全SECRET> -e LOG_LEVEL=debug -v /etc/localtime:/etc/localtime -d cdwen/alertmanager-dingding:v1 ``` **环境变量配置**: * ding_token:钉钉机器人 TOKEN * LOG_LEVEL:日志级别,设置成 `debug` 可以看到 AlertManager WebHook 发送的数据,方便调试使用,不需调试可以不设置该环境变量 * ding_secret:为钉钉机器人的安全设置密钥,机器人安全设置页面,加签一栏下面显示的 SEC 开头的字符串 **添加钉钉机器人** ![2](image/2.jpg) **alertmanager配置** ```yaml global: resolve_timeout: 5m route: group_by: ['alertname'] group_wait: 60s group_interval: 5m repeat_interval: 1h receiver: 'web.hook' receivers: - name: 'web.hook' webhook_configs: - url: 'http://127.0.0.1:5000' send_resolved: true inhibit_rules: - source_match: severity: 'critical' target_match: severity: 'warning' equal: ['alertname', 'dev', 'instance'] ``` **prometheus的rules配置** ```yaml groups: - name: node_alerts rules: - alert: HostOutOfMemory expr: node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 < 1 for: 1m labels: severity: warning annotations: summary: "主机内存不足" description: "节点内存已满 (< 10% left)" value: "{{ $value }}" otherlabels: "{{ $labels }}" hosts: "{{ $labels.instance }}" - alert: HostHighCpuLoad expr: 100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[2m])) * 100) > 99 for: 1m labels: severity: warning annotations: summary: "Host high CPU load" hosts: "{{ $labels.instance }}" description: "CPU load is > 80%" value: "{{ $value }}" otherlabels: "{{ $labels }}" ``` 注意:annotations配置项内的value,hosts,otherlabels为自定义标签,在报警中需要使用到,所以这几个值一定要定义,否者无法正常报警。