{{ 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 :="" }}
所以很难看到发送的原始数据alertmanager。我能看到的只有这个模板渲染的结果。请看下面。
胡说叔叔
九州编程
随时随地看视频慕课网APP
相关分类