亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 Golang 模板中的對象置零

將 Golang 模板中的對象置零

Go
胡說叔叔 2022-12-19 17:57:00
{{ 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 它不能通過零對象來解決。因為:

  1. 無法在微信中保留最后一個“已解析”的主機 232.20。

  2. 下次原始數據仍包含“已解析”主機 232.20,因此無法以任何方式將其刪除。

  3. 所以輸出也不能改變。

謝謝。


查看完整回答
反對 回復 2022-12-19
  • 1 回答
  • 0 關注
  • 78 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號