[Go template - Alertmanager] Unable to access template function

116 views
Skip to first unread message

Deepika

unread,
Jun 19, 2020, 1:21:01 PM6/19/20
to golang-nuts
Objective: To remove key/value pair from a go datastructure when a condition is met.
System Information: Alertmanager's email template (HTML in go) code. 
Code:

{{ if gt (len .Alerts.Firing) 0 }
        {{ range .Alerts.Firing }}
                    {{ $labels := .Labels }}
                    {{ range $labels.SortedPairs }}
                        {{ if and (match .Name "alertname") (match .Value "Consul-Agent-Unhealthy") }}
                                {{ $labels := $labels.Remove "status" }}
                        {{ end }}
                    {{ end }}
         {{ end }}
{{ end }}

Error:
 level=error ts=2020-06-19T16:48:26.364Z caller=notify.go:372 component=dispatcher msg="Error on notify" err="cancelling notify retry for \"email\" due to unrecoverable error: execute html template: template: email_template.tmpl:371:25: executing \"email_template.tmpl\" at <.Labels.Remove>: can't evaluate field Labels in type template.Pair" context_err=null


Reply all
Reply to author
Forward
0 new messages