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

告警消息如下:

相关推荐
sukalot6 小时前
Windows 驱动实例分析系列:libwdi 驱动分析 - 应用篇(一)
windows·驱动开发
小道士写程序7 小时前
Windows Rust 环境安装指导
开发语言·windows·rust
传奇开心果编程7 小时前
【Compose Multiplatform 跨端开发学与练】第4课 导航与路由
android·windows·学习·ui·ios·kotlin·composer
Tisfy7 小时前
两台旧电脑修复 —— 绕过WinXP密码登录、备份和恢复Win7数据、安装Win10
windows·数据恢复·系统重装
传奇开心果编程7 小时前
【Compose Multiplatform 跨端开发学与练】第2课 Compose 基础语法
android·windows·学习·ui·ios·kotlin·composer
supabc1238 小时前
Celium:连接 Windows、Mac、Linux 与 Android,让远程访问和设备管理更简单
android·linux·windows·macos·远程访问·网络管理·celium
2401_872418788 小时前
Windows服务器:错误 403 - 禁止访问:本地 FTP 上传文件到网站服务器后提示无访问权限
运维·服务器·windows
YCOSA202519 小时前
Windows11_InsiderPreview_EnterpriseVL_x64_zh-cn_29680_1000.iso 官方直链
windows
怎么没有名字注册了啊21 小时前
Windows Server 2008 R2 如何开启Aero
windows
lingchen19061 天前
Windows CMD 的 `cd`(change directory,切换目录)命令
windows·命令模式