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" .}}

告警消息如下:

相关推荐
std8602120 小时前
微软解除 Win11 限制,“毛玻璃”效果将无处不在
windows
csdn_aspnet20 小时前
如何在 Mac、Ubuntu、CentOS、Windows 上安装 MySQL 客户端
linux·windows·mysql·macos·centos
24kHT20 小时前
conda以及Jupyter notebook的使用
windows·jupyter·conda
CHN悠远21 小时前
debian13 安装钉钉后,钉钉无法运行问题的解决办法
linux·运维·服务器·钉钉·debian13
alphaTao1 天前
LeetCode 每日一题 2025/11/3-2025/11/9
windows·leetcode
习惯就好zz1 天前
WSL2 安装Ubuntu卡在安装进度0%无响应问题解决
linux·windows·ubuntu·wsl·wsl2
仰望—星空2 天前
MiniEngine学习笔记 : CommandListManager
c++·windows·笔记·学习·cg·direct3d
ue星空2 天前
Windows内核函数使用
windows
业余幻想家2 天前
Windows10/Windows11家庭版系统关闭自动更新
运维·windows
阿猿收手吧!2 天前
windows本机vscode通过ssh免密登录远程linux服务器 && git push/pull 免密
服务器·windows·vscode