{{ 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。我能看到的只有这个模板渲染的结果。请看下面。
1 回答

九州编程
TA贡献1785条经验 获得超4个赞
只是 relealize 它不能通过零对象来解决。因为:
无法在微信中保留最后一个“已解析”的主机 232.20。
下次原始数据仍包含“已解析”主机 232.20,因此无法以任何方式将其删除。
所以输出也不能改变。
谢谢。
- 1 回答
- 0 关注
- 61 浏览
添加回答
举报
0/150
提交
取消