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

告警消息如下:

相关推荐
夏日米米茶3 小时前
Windows系统下npm报错node-gyp configure got “gyp ERR“解决方法
前端·windows·npm
虾球xz5 小时前
CppCon 2015 学习:CLANG/C2 for Windows
开发语言·c++·windows·学习
码上库利南6 小时前
Windows开机自动启动中间件
windows
大咖分享课7 小时前
云原生监控体系建设:Prometheus+Grafana的企业级实践
云原生·grafana·prometheus
nenchoumi311912 小时前
AirSim/Cosys-AirSim 游戏开发(一)XBox 手柄 Windows + python 连接与读取
windows·python·xbox
love530love13 小时前
【PyCharm必会基础】正确移除解释器及虚拟环境(以 Poetry 为例 )
开发语言·ide·windows·笔记·python·pycharm
黄交大彭于晏15 小时前
发送文件脚本源码版本
java·linux·windows
vfvfb1 天前
bat批量去掉本文件夹中的文件扩展名
服务器·windows·批处理·删除扩展名·bat技巧
我命由我123451 天前
VSCode - VSCode 放大与缩小代码
前端·ide·windows·vscode·前端框架·编辑器·软件工具
欧先生^_^1 天前
ingress-nginx 开启 Prometheus 监控 + Grafana 查看指标
nginx·grafana·prometheus