To remove key/value pair from a go datastructure when a condition is met.
{{ 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