MogDB/openGauss 自定义snmptrapd告警信息
MogDB/openGauss 自定义 snmptrapd 告警信息
在实际使用中,默认的报警规则信息并不能很好的满足 snmp 服务端的需求,需要定制化报警信息,这里以添加 ip 为例,看似一个简单的将 IP 一行信息单独在报警展示出来,涉及到的配置文件修改还是挺多的。
修改 prometheus.yml 文件
首先需要修改 prometheus.yml 文件,在对应的实例下添加 ip 标签
修改规则报警文件
对应的报警规则文件也同样需要修改,我这里使用的是服务器磁盘使用率做报警测试,所以直接修改 node_rules.yml 文件,添加 ip 信息。
查看 alertmanager web 界面
现在我们就可以在 alertmanager 的界面上看到我们新添加的 ip 标签了,同时报警信息里也带了 ip。
修改 snmp_notifier 模版
altermanager 模块将报警消息推送到 snmp_notifier 后,还需要需改 snmp_notifier 的描述模版 description-template.tpl。
snmptrapd 服务器接受报警信息
添加额外的模版
默认情况下,snmptrapd 只会输出三行模版信息,要添加额外的版本信息需要使用–snmp.extra-field-template 参数,比如添加第 4 行模版则在 snmp_notifier 启动时指定参数–snmp.extra-field-template=4=/opt/snmp_notifier/extra-field-template.tpl,模版 extra-field-template.tpl 可以参考 description-template.tpl 的格式
{{- if .Alerts -}}
{{- range $severity, $alerts := (groupAlertsByLabel .Alerts "severity") -}}
{{- range $index, $alert := $alerts }}
{{ $alert.Annotations.ip }}
{{ end }}
{{ end }}
{{- end -}}
启动 snmp_notifier
nohup /opt/snmp_notifier/snmp_notifier --snmp.trap-description-template=/opt/snmp_notifier/description-template.tpl --snmp.extra-field-template=4=/opt/snmp_notifier/extra-field-template.tpl > /opt/snmp_notifier/snmp_notifier.log 2>&1 &
再次查看 snmptrapd 服务器接受报警信息
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了