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

告警消息如下:

相关推荐
帅得不敢出门2 小时前
macOS苹果电脑运行向日葵远程控制软件闪退
windows·macos·远程控制·向日葵
索迪迈科技8 小时前
记一次 .NET 某中医药附属医院门诊系统 崩溃分析
windows·c#·.net·windbg
十八旬8 小时前
苍穹外卖项目实战(day7-2)-购物车操作功能完善-记录实战教程、问题的解决方法以及完整代码
java·开发语言·windows·spring boot·mysql
_何同学11 小时前
Spring Boot 监控实战:集成 Prometheus 与 Grafana,打造全方位监控体系
spring boot·grafana·prometheus
Clownseven13 小时前
阿里云ECS安装Windows Server 2022教程 | 纯文字分步指南
windows·阿里云·云计算
T0uken13 小时前
【C++】LLVM-mingw + VSCode:Windows 开发攻略
c++·windows·vscode
能摆一天是一天20 小时前
JAVA stream().flatMap()
java·windows
JosieBook21 小时前
【远程运维】Linux 远程连接 Windows 好用的软件:MobaXterm 实战指南
linux·运维·windows
该用户已不存在1 天前
你没有听说过的7个Windows开发必备工具
前端·windows·后端