douhang8991 2019-05-08 12:25
浏览 309
已采纳

Prometheus警报管理器模板更改

I have prometheus alert manager running with a template, and im getting email subject as following

[FIRING:6] Unusual network throughput out (thanos group_b aws_us_b instance_191 infrastructure monitoring-prometheus-node warning)

all the values after the alert name are labels. here is the template subject code

{{ define "__subject" }}[{{ .Status | toUpper }} {{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}]  {{ .GroupLabels.SortedPairs.Values | join " " }}  {{ if gt (len .CommonLabels) (len .GroupLabels) }} ({{ with .CommonLabels.Remove .GroupLabels.Names }}   {{ .Values | join " " }}   {{ end }}) {{ end }}{{ end }}

I would like to modify this only to get following

[FIRING:6] Unusual network throughput out (group_b instance_191) only group name and instance name

how can I achieve this?

  • 写回答

1条回答 默认 最新

  • du8828 2019-05-08 14:58
    关注

    You could replace your template with something like this:

    {{ define "__subject" }}[{{ .Status | toUpper }} {{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.alertname }} ({{ .GroupLabels.group }} {{ .GroupLabels.instance }})
    

    Not sure what will happen if the group or instance labels are not common across all alerts (e.g. if you have an alert firing across multiple groups and/or instances). Maybe you'll just get an empty string, maybe null. According to some brief testing in the Go playground, it would seem you may get <no value>. If you don't want that, you can play around with Go template's {{if }} action.

    Something like

    {{ if .GroupLabels.group }}{{ .GroupLabels.group }}{{ end }}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 51单片机C语言数码管驱动单片机为AT89C52
  • ¥100 只改动本课件的 cal_portfolio_weight_series(decision_date), 跑完本课件。设计一个信息比率尽量高的策略。
  • ¥20 如何在visual studio 2022中添加ImageMagick库
  • ¥50 如何实现uniapp编译的微信小程序做可回溯视频
  • ¥15 求Houdini使用行家,付费。价格面议。
  • ¥15 前端高拍仪调用问题报错
  • ¥15 想用octave解决这个数学问题
  • ¥15 Centos新建的临时ip无法上网,如何解决?
  • ¥15 海康威视如何实现客户端软件对设备语音请求的处理。
  • ¥15 支付宝h5参数如何实现跳转