{{ define "default.message" }}
{{- if gt (len .Alerts.Firing) 0 -}}
{{- range $index, $alert := .Alerts.Firing -}}
{{- if eq $index 0 -}}
Detail: {{ $alert.Labels.alertname }}
# Here I'm going to zero $alert
{{- end }}
{{- end }}
{{- end }}
{{- end }}
你好,我想歸零.Alerts.Firing,這也是$alert在迭代之后。我是golang的新手,請幫忙,謝謝。
補充:其實是一個Prometheusalert的模板。原始日期由(微信)創建alertmanager并發送至receiver(微信)。這是微信模板
{{ define "wechat.default.message" }}
{{- if gt (len .Alerts.Firing) 0 -}}
{{- range $index, $alert := .Alerts.Firing -}}
{{- if eq $index 0 -}}
Detail: {{ $alert.Labels.alertname }}
{{- end }}
---- Problem started ------
Message: {{ $alert.Annotations.description }}
Time: {{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
{{ if gt (len $alert.Labels.instance) 0 }}ip: {{ $alert.Labels.instance }};{{- end }}
{{- if gt (len $alert.Labels.namespace) 0 }}namespace: {{ $alert.Labels.namespace }};{{- end }}
{{- if gt (len $alert.Labels.node) 0 }}Node: {{ $alert.Labels.node }};{{- end }}
{{- if gt (len $alert.Labels.pod_name) 0 }}Pod: {{ $alert.Labels.pod_name }}{{- end }}
-----------------
{{ $alert :="" }}
{{- end }}
{{- end }}
{{- if gt (len .Alerts.Resolved) 0 -}}
{{- range $index, $alert := .Alerts.Resolved -}}
{{- if eq $index 0 }}
!!!! Problem resolved !!!!!
Detail: {{ $alert.Labels.alertname }}
{{- end }}
Started_at: {{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
Resolved_at: {{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
-------
{{ if gt (len $alert.Labels.instance) 0 -}}ip: {{ $alert.Labels.instance }};{{- end }}
{{- if gt (len $alert.Labels.namespace) 0 -}}namespace: {{ $alert.Labels.namespace }};{{- end }}
{{- if gt (len $alert.Labels.node) 0 -}}Node: {{ $alert.Labels.node }};{{- end }}
{{- if gt (len $alert.Labels.pod_name) 0 -}}Pod: {{ $alert.Labels.pod_name }}{{- end }}
{{ $alert :="" }}
-----------------
{{- end }}
{{- end }}
{{- end }}
所以很難看到alertmanager. 我只能看到這個模板呈現的結果。請看下文。
################# The first alert #########
##### As we can see 232.20 is in the state of 'resolved' ###
Detail: Node is down
---- Problem started ------
Message: Node is down
VALUE = 0
LABELS = 172.16.232.18:9100
Time: 2022-06-02 14:47:51
ip: 172.16.232.18:9100;
-----------------
!!!! Problem resolved !!!!!
Detail: Node is down
Started_at: 2022-06-02 14:47:21
Resolved_at: 2022-06-02 14:47:21
-------
ip: 172.16.232.20:9100;
-----------------
##################### The second alert #######
####### 232.20 is still in the state of resolved, it seems it's duplicated, that's why I'm going to zero it ####
!!!! Problem resolved !!!!!
Detail: Node is down
Started_at: 2022-06-02 14:47:51
Resolved_at: 2022-06-02 14:47:51
-------
ip: 172.16.232.18:9100;
-----------------
Started_at: 2022-06-02 14:47:21
Resolved_at: 2022-06-02 14:47:21
-------
ip: 172.16.232.20:9100;
-----------------
供應:
- 第一次警報的原始資料。
[FIRING:1] Node is down (powerdns prod node_exporter critical)
instance is down.
Alerts Firing:
Labels:
- alertname = Node is down
- app = powerdns
- env = prod
- instance = 172.16.232.18:9100
- job = node_exporter
- severity = critical
Annotations:
- description = Node is down
VALUE = 0
LABELS = 172.16.232.18:9100
- summary = instance is down.
Source: http://pt-prometheus-server-85944ccff6-qvtc4:9090/graph?g0.expr=up{job="node_exporter"} == 0&g0.tab=1
Alerts Resolved:
Labels:
- alertname = Node is down
- app = powerdns
- env = prod
- instance = 172.16.232.20:9100
- job = node_exporter
- severity = critical
Annotations:
- description = Node is down
VALUE = 0
LABELS = 172.16.232.20:9100
- summary = instance is down.
Source: http://pt-prometheus-server-85944ccff6-qvtc4:9090/graph?g0.expr=up{job="node_exporter"} == 0&g0.tab=1
AlertmanagerUrl:
http://alertmgr.pacific-textiles.com/#/alerts?receiver=wechat
2. 第二次警報的
原始資料。
[RESOLVED] Node is down (powerdns prod node_exporter critical)
instance is down.
Alerts Resolved:
Labels:
- alertname = Node is down
- app = powerdns
- env = prod
- instance = 172.16.232.18:9100
- job = node_exporter
- severity = critical
Annotations:
- description = Node is down
VALUE = 0
LABELS = 172.16.232.18:9100
- summary = instance is down.
Source: http://pt-prometheus-server-85944ccff6-qvtc4:9090/graph?g0.expr=up{job="node_exporter"} == 0&g0.tab=1
Labels:
- alertname = Node is down
- app = powerdns
- env = prod
- instance = 172.16.232.20:9100
- job = node_exporter
- severity = critical
Annotations:
- description = Node is down
VALUE = 0
LABELS = 172.16.232.20:9100
- summary = instance is down.
Source: http://pt-prometheus-server-85944ccff6-qvtc4:9090/graph?g0.expr=up{job="node_exporter"} == 0&g0.tab=1
AlertmanagerUrl:
http://alertmgr.pacific-textiles.com/#/alerts?receiver=wechat
uj5u.com熱心網友回復:
只是意識到它不能通過零一個物件來解決。因為:
- 無法在微信中保留最后一個“已解決”的主機 232.20。
- 下次原始資料仍然包含“已決議”的主機 232.20,因此無法通過任何方式將其洗掉。
- 所以輸出也不能改變。
謝謝。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/486488.html
