I found a template for Prometheus Alert Manager for alerts, but I receive many unnecessary labels in notification. How to remove labels in template? This code is responsible for labels (look below). I tried to set conditions in If operator, but it didnt help. I dont have deep knowledge in Go Templating system & Json, so I'm asking for help. I use Amazon Prometheus.
{{ if gt (len $alerts.Labels.SortedPairs) 0 -}},
"labels":
{{ "{" }}
{{ range $index, $label := $alerts.Labels.SortedPairs }}
{{ if $index }},
{{ end }}
"{{ $label.Name }}": "{{ $label.Value }}"
{{ end }}
{{ "}" }}
{{- end }}
As seen here, you can filter labels by name something like this.
{{- range .CommonLabels.SortedPairs -}}
{{- if ne .Name "alertname" -}}
{{- .Name }}%3D"{{- .Value -}}"%2C%20
{{- end -}}
{{- end -}}