配置入口如下:
代码配置:
{{ $var := .externalURL}} {{ range $k,$v:=.alerts }} {{if eq $v.status "resolved"}}[PROMETHEUS-恢复信息]({{$v.generatorURL}}) > **[{{$v.labels.alertname}}]({{$var}})** > <font color="info">开始时间:</font> {{ TimeFormat $v.startsAt "2006-01-02 15:04:05" }} > <font color="info">结束时间:</font> {{ TimeFormat $v.endsAt "2006-01-02 15:04:05" }} > <font color="info">故障主机:</font> {{- if $v.labels.instance }} {{ $v.labels.instance }} {{- end }} > <font color="info">**{{$v.annotations.description}} {{- if $v.labels.biz_no }} {{ $v.labels.biz_no }} {{- end }}**</font> {{else}}[PROMETHEUS-告警信息]({{$v.generatorURL}}) > **[{{$v.labels.alertname}}]({{$var}})** > <font color="warning">开始时间:</font> {{ TimeFormat $v.startsAt "2006-01-02 15:04:05" }} > <font color="warning">结束时间:</font> {{ TimeFormat $v.endsAt "2006-01-02 15:04:05" }} > <font color="warning">故障主机:</font> {{- if $v.labels.instance }} {{ $v.labels.instance }} {{- end }} > <font color="warning">**{{$v.annotations.description}} {{- if $v.labels.biz_no }} {{ $v.labels.biz_no }} {{- end }}**</font> {{end}} {{ end }}
校验示例:
{ "receiver": "email_and_weixin", "status": "firing", "alerts": [{ "status": "firing", "labels": { "alertname": "K8S Pod节点监控告警", "condition": "true", "env": "test", "instance": "10.42.172.136:8080", "job": "kubernetes-service-endpoints", "kubernetes_name": "kube-state-metrics", "kubernetes_namespace": "kube-system", "label": "3", "namespace": "default", "pod": "xinao-planet-product-6b5746c67-n2kcl", "severity": "critical", "uid": "f284b05a-bd06-450a-a3e4-5fa7b514cbb7" }, "annotations": { "description": "Pod has been in a non-ready state for longer than 2 seconds.", "summary": "Kubernetes Pod not healthy (instance 10.42.172.136:8080)" }, "startsAt": "2023-03-27T02:47:59.695Z", "endsAt": "0001-01-01T00:00:00Z", "generatorURL": "http://prometheus-c56654849-6447l:9090/graph?g0.expr=kube_pod_status_ready%7Bcondition%3D%22true%22%2Cpod%3D~%22.%2Aplanet.%2A%22%7D+%3D%3D+0&g0.tab=1", "fingerprint": "5c721c56bb727fd4" }], "groupLabels": {}, "commonLabels": { "alertname": "K8S Pod节点监控告警", "condition": "true", "env": "test", "instance": "10.42.172.136:8080", "job": "kubernetes-service-endpoints", "kubernetes_name": "kube-state-metrics", "kubernetes_namespace": "kube-system", "label": "3", "namespace": "default", "pod": "xinao-planet-product-6b5746c67-n2kcl", "severity": "critical", "uid": "f284b05a-bd06-450a-a3e4-5fa7b514cbb7" }, "commonAnnotations": { "description": "Pod has been in a non-ready state for longer than 2 seconds.", "summary": "Kubernetes Pod not healthy (instance 10.42.172.136:8080)" }, "externalURL": "http://za-monitor-test-0001:9093", "version": "4", "groupKey": "{}/{severity=\"critical\"}:{}", "truncatedAlerts": 0 }
可以在PrometheusAlert的MarkDown入口进行校验。
标签:01,end,kubernetes,示例,微信,labels,PrometheusAlert,instance,Pod From: https://www.cnblogs.com/huajun0525/p/17277223.html