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

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 }}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 Yolov5训练报错
  • ¥15 Unity发布gzip压缩的webgl之后让浏览器可以正常显示画面
  • ¥15 有没有人知道这种提示怎么关?现在不做ts项目了不知道咋关了,求解,现在我以前的js项目都是这种提示了
  • ¥15 为什么mysql做了碎片化处理data_free还是很高
  • ¥15 single positional indexer is out-of-bounds
  • ¥15 LSTM 模型数据量需要多少?
  • ¥15 mysql数据抓包开发报表
  • ¥15 linux系统下安装office打不开
  • ¥20 rsync脚本分发错误,文件不齐全
  • ¥15 labview顺序结构与时间延时