微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何查看`.GroupLabels`数据结构来开发自定义`__subject`

如何解决如何查看`.GroupLabels`数据结构来开发自定义`__subject`

我无法找到有关 alertmanager 模板对象的可靠文档,无法为我的用例正确开发自定义模板。例如,我不得不查看认的 alertmanager 模板,以了解现有的 __subject 是如何生成的。然而,我正在重构它。认看起来像 (https://github.com/prometheus/alertmanager/blob/release-0.22/template/default.tmpl#L4):

{{ 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 }}

对于我们的用例的警报,乍一看,这通常会产生一个令人沮丧的复杂、丑陋且几乎无用的摘要

我想将其重构为更接近于:

[.Status][<SEVERITY>] <Alert Name> (count: #; cluster: <cluster>; ns: <namespace>; pod: <pod>)

使用 https://prometheus.io/docs/alerting/latest/notifications/,我相信我正在正确消化,我目前正在尝试,但不幸的是失败了:

{{ define "__subject" -}}
  [{{ .Status | toupper }}][{{ .GroupLabels.severity | toupper }}] {{ .GroupLabels.alertname -}} {{ `"(count: "` }}{{ .Alerts.Firing | len -}}; {{ `"cluster: "` }}{{ .CommonLabels.cluster }}; {{ `"namespace: "` }}{{ .CommonLabels.namespace }}; {{ `"pod: "` }}{{ .CommonLabels.pod }})                                                                                                                                                                                                   
{{ end }}

我最终得到的是:

[FIRING]Test-IGnorE_ME warning      (health; test.example.com; fake; pod-d34db3ef-12345; monitoring/kube-prometheus-stack-prometheus) 

我期待的是:

[FIRING][WARNING] Test-IGnorE_ME (count: 1; cluster: dev; ns: fake; pod: health)

这甚至不符合我的定义。非常混乱。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。