grafana配置钉钉告警模版(一)

1、配置钉钉告警模版

创建钉钉告警模版,然后在创建钉钉告警时调用模版。


定义发送内容具体代码
my_text_alert_list 是模版名称后面再配置钉钉告警时需要调用。

复制代码
{{/* 定义消息体片段 */}}
{{ define "my_text_alert_list" }}{{ range . }}

告警名称:
{{ index .Labels.alertname }}

告警机器:
{{ index .Labels.env }} {{ index .Labels.device }}

告警级别:
{{ index .Annotations.level }}

告警详情:
{{ index .Annotations.summary }}

触发阀值:
{{ index .Annotations.description }}

发生时间: {{ .StartsAt }} \n
{{ if eq .Status "resolved" }}
恢复时间: {{ .EndsAt }}
{{ end }}
{{ end }}{{ end }}

{{/* 定义消息体 */}}
{{ define "my.message" }}
{{ if gt (len .Alerts.Firing) 0 }}**--------发生告警---------**
{{ template "my_text_alert_list" .Alerts.Firing }}
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}**-------恢复告警------**
{{ template "my_text_alert_list" .Alerts.Resolved }}
{{ end }}
{{ end }}

在创建一个标题模版

定义标题具体代码
my.title 是模版名称后面再配置钉钉告警时需要调用。

复制代码
{{ define "my.title" }}[监控报警]: [{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ if gt (.Alerts.Resolved | len) 0 }}, RESOLVED:{{ .Alerts.Resolved | len }}{{ end }}{{ end }}]{{ end }}

创建完成

2、添加钉钉告警

首先在钉钉群添加一个机器人,拿到Webhook地址,使用关键字匹配告警。

选择自定义机器人

钉钉机器人配置完成后grafan添加钉钉告警

Message 调用上面配置的模版名称:{{ template "my.title" .}}{{template "my.message" .}}

告警消息如下:

相关推荐
liliangcsdn2 小时前
mstsc不在“C:\Windows\System32“下在C:\windows\WinSxS\anmd64xxx“问题分析
开发语言·windows
低频电磁之道2 小时前
解决 Windows C++ DLL 导出类不可见的编译错误
c++·windows
IDC02-阿杰4 小时前
Windows WSL2安装Ubuntu24.04全攻略
linux·windows
勤自省6 小时前
Windows 文件无法粘贴到 Linux(Ubuntu)系统的解决方案
linux·windows·ubuntu
国产化创客7 小时前
ESP32 (ESPectre)+Grafana构建专业级CSI监控面板
物联网·grafana·信息与通信·智能硬件
张赐荣7 小时前
为资源管理器文件右键菜单增加 使用 Web 搜索 功能
windows
以太浮标7 小时前
华为eNSP模拟器综合实验之- DHCP、DNS、HTTP和FTP服务器配置案例Client-Server
linux·服务器·windows·http·华为·信息与通信
帕里亚8 小时前
ubuntu18.04 APT升级 glibc2.28 (Jetson)
linux·运维·windows
charlie1145141919 小时前
通用GUI编程技术——图形渲染实战(二十八)——图像格式与编解码:PNG/JPEG全掌握
开发语言·c++·windows·学习·图形渲染·win32
2601_955781989 小时前
OpenClaw Windows 部署全程图文教程 | 免代码
windows