当前位置: 首页 > news >正文

钉钉告警+prometheus+alertmanager【prometheus-webhook-dingtalk】

背景

业务需要,项目部署了prometheus作为监控,想把告警接入企业钉钉

现有环境

prometheus+node_exporter+redis_exporter+blackbox_exporter+mysql_expoort+alertmanager

钉钉告警程序包(prometheus-webhook-dingtalk)

gitlab

https://github.com/timonwong/prometheus-webhook-dingtalk

下载地址

https://github.com/timonwong/prometheus-webhook-dingtalk/releases/download/v2.1.0/prometheus-webhook-dingtalk-2.1.0.linux-amd64.tar.gz

config.yml

#web:
#  listen_address: ":8060"
## Request timeout
# timeout: 5s## Uncomment following line in order to write template from scratch (be careful!)
#no_builtin_template: true## Customizable templates path
templates:- /apps/apps/prometheus-webhook-dingtalk/webhook.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: https://oapi.dingtalk.com/robot/send?access_token=667xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx# secret for signaturesecret: SEC8e0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#  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']

prometheus-webhook-dingtalk.service

[Unit]
Description=Prometheus Webhook DingTalk
After=network.target[Service]
Type=simple
User=prometheus
Group=prometheus# 代理配置
Environment="HTTP_PROXY=http://10.0.0.100:3128"
Environment="HTTPS_PROXY=http://10.0.0.100:3128"# 启动命令 - 使用配置文件
ExecStart=/app/prometheus-webhook-dingtalk/prometheus-webhook-dingtalk \--config.file=/app/prometheus-webhook-dingtalk/prometheus-webhook-dingtalk/config.yml \--web.listen-address=:8060Restart=always
RestartSec=10[Install]
WantedBy=multi-user.target
##webhook.tmpl
webhook.tmpl
{{ define "__subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }} {{ if gt (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ .Values | join " " }}{{ end }}){{ end }}{{ end }}
{{ define "__alertmanagerURL" }}{{ $alertURL := "http://192.168.64.158:9093" }} {{- $alertURL -}}/#/alerts?receiver={{ .Receiver }}&tmp={{ .ExternalURL }}{{ end }}{{ define "__text_alert_list" }}{{ range . }}
**Labels**
{{ range .Labels.SortedPairs }}> - {{ .Name }}: {{ .Value | markdown | html }}
{{ end }}
**Annotations**
{{ range .Annotations.SortedPairs }}> - {{ .Name }}: {{ .Value | markdown | html }}
{{ end }}
**Source:** [{{ .GeneratorURL }}]({{ .GeneratorURL }})
{{ end }}{{ end }}{{/* Firing */}}{{ define "default.__text_alert_list" }}{{ range . }}**触发时间:** {{ dateInZone "2006.01.02 15:04:05" (.StartsAt) "Asia/Shanghai" }}**摘要:** {{ .Annotations.summary }}**描述:** {{ .Annotations.description }}**监控:** [grafana](http://localhost:3000)**详情:**
{{ range .Labels.SortedPairs }}{{ if and (ne (.Name) "severity") (ne (.Name) "summary") }}> - {{ .Name }}: {{ .Value | markdown | html }}
{{ end }}{{ end }}
{{ end }}{{ end }}{{/* Resolved */}}{{ define "default.__text_resolved_list" }}{{ range . }}**触发时间:** {{ dateInZone "2006.01.02 15:04:05" (.StartsAt) "Asia/Shanghai" }}**解除时间:** {{ dateInZone "2006.01.02 15:04:05" (.EndsAt) "Asia/Shanghai" }}**摘要:** {{ .Annotations.summary }}**监控:** [grafana](http://localhost:3000)**详情:**
{{ range .Labels.SortedPairs }}{{ if and (ne (.Name) "severity") (ne (.Name) "summary") }}> - {{ .Name }}: {{ .Value | markdown | html }}
{{ end }}{{ end }}
{{ end }}{{ end }}{{/* Default */}}
{{ define "default.title" }}{{ template "__subject" . }}{{ end }}
{{ define "default.content" }}#### \[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}\] **[{{ index .GroupLabels "alertname" }}]({{ template "__alertmanagerURL" . }})**
{{ if gt (len .Alerts.Firing) 0 -}}![Firing-img](https://pic.rmb.bdstatic.com/bjh/news/10977507ae0edad0c17c820ff5d80f5e.png)**告警通知**
{{ template "default.__text_alert_list" .Alerts.Firing }}
{{- end }}
{{ if gt (len .Alerts.Resolved) 0 -}}![Resolved-img](https://pic.616pic.com/ys_img/00/06/20/64dXxVfv6k.jpg)**告警解除**
{{ template "default.__text_resolved_list" .Alerts.Resolved }}
{{- end }}
{{- end }}{{/* Legacy */}}
{{ define "legacy.title" }}{{ template "__subject" . }}{{ end }}
{{ define "legacy.content" }}#### \[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}\] **[{{ index .GroupLabels "alertname" }}]({{ template "__alertmanagerURL" . }})**
{{ template "__text_alert_list" .Alerts.Firing }}
{{- end }}{{/* Following names for compatibility */}}
{{ define "ding.link.title" }}{{ template "default.title" . }}{{ end }}
{{ define "ding.link.content" }}{{ template "default.content" . }}{{ end }}

创建钉钉建群并创建机器人

image
image
image
image

获取Webhook地址和加签的一串秘钥

配置config.yml和prometheus-webhook-dingtalk.service,并启动

image

配置alertmanager并启动

global:resolve_timeout: 5m
templates:- templates/wechat.tmpl
route:group_by: ['alertname']group_wait: 10sgroup_interval: 10srepeat_interval: 10mreceiver: 'webhook'
receivers:
- name: 'webhook'webhook_configs:- url: http://192.168.60.185:8060/dingtalk/webhook1/sendsend_resolved: true
inhibit_rules:
- equal: ['alertname', 'cluster', 'service']source_match:severity: 'high'target_match:severity: 'warning'

数据流

prometheus----->alertmanager----->prometheus-webhook-dingtalk----->钉钉告警

效果

image

image

http://www.gsyq.cn/news/81663.html

相关文章:

  • 1001110
  • 1000011
  • 1000111
  • 1001000
  • za宝可梦定制04
  • 2025年滗水器实力厂家推荐品牌:滗水器供应商/刮泥机优质厂家/吸泥机源头工厂哪家好?哪家强? - 品牌推荐大师1
  • vuex版本问题
  • 专业价值与跨界融合:中国十大论坛网站的核心竞争力图谱 - 品牌推荐大师1
  • 2025年国产水质检测仪品牌推荐:多参数/便携式/COD水质检测仪靠谱供应商/余氯检测仪采购推荐 - 品牌推荐大师1
  • 2025年国产COD测定仪品牌推荐:水质COD测定仪/便携式COD测定仪/快速COD测定仪知名品牌哪家好? - 品牌推荐大师1
  • 召唤星座圣衣的魔法
  • UE5导入的CAD材料零件如何被Merge?
  • 第一次搭建个人主页+GitHub部署全记录:HTML/CSS/JS前端完成+留言板踩坑
  • flask项目配置
  • 2025年质量好的河南led显示屏 河南液晶拼接屏 河南广告机 河南会议一体机 厂家最新推荐权威榜 (2) - 朴素的承诺
  • 基于STM32芯片与ST7789驱动芯片实现2.8寸TFT屏幕控制
  • AI+SIP・用实时音视频连接一切 | RTSCon2025 报名进行中
  • 2025十大水务品牌厂家推荐榜 最新权威测评出炉!安全与市场双维度优选指南 - 品牌推荐排行榜
  • 2025十大水务品牌厂家推荐榜,权威测评+安全认证,全国市场数据揭晓 天津高通阀门登顶榜首 - 品牌推荐排行榜
  • 2025年高速离心机/低速离心机/冷冻离心机品牌TOP6:优质厂家选购指南 - 品牌推荐大师
  • 【GitHub每日速递 20251210】独立浏览器 Ladybird 来袭!多进程架构+多系统兼容,开发必备!
  • 祝贺东航首飞全球最长单程航线!通义千问和 AI 网关助力推出首个行程规划 Agent
  • pyenv-win安装初步使用
  • 刚刚,IDEA 免费版发布!终于不用破解了
  • iOS SwiftUI 动画开发指南 - 教程
  • Python 学习笔记(02)
  • 内网对抗-隧道技术篇防火墙组策略HTTP反向SSH转发出网穿透CrossC2解决方案 - 实践
  • 2025年12月上海真空冲洗设备、门式冲洗设备、水力翻斗设备、智能喷射器、电动限流设备厂家综合评估TOP5 - 2025年11月品牌推荐榜
  • 2025年油瓶加工厂权威推荐榜单:橄榄油瓶/茶油瓶/香油瓶源头生产厂家精选 - 品牌推荐官
  • 2025实验室规划设计公司哪家好:一站式实验室建设专家——看迅领实验室如何引领行业新标准 - 深度智识库