text: >- {{ range .Alerts }} *Alert:* {{ .Annotations.summary }} - `{{ .Labels.severity }}` {{ if ( ne ( .Annotations.description | len ) 0 ) and ( ne ( .Annotations.grafana | len ) 0 ) }} *Grafana:* <{{ .Annotations.grafana }}|:chart_with_upwards_trend:> *Description:* {{ .Annotations.description }} {{ else if ( ne ( .Annotations.grafana | len ) 0 ) and ( eq ( .Annotations.description | len ) 0 ) }} *Grafana:* <{{ .Annotations.grafana }}|:chart_with_upwards_trend:> {{ else if ( ne ( .Annotations.description | len ) 0 ) and ( eq ( .Annotations.grafana | len ) 0 ) }} *Description:* {{ .Annotations.description }} {{ end }} *Details:* {{ range .Labels.SortedPairs }} • *{{ .Name }}:* `{{ .Value }}` {{ end }} {{ end }}I've got a Slack receiver setup in Alertmanager and it uses an if statement to determine if a particular annotation is in use, and if so to change the output. The issue here is that the if statement seems to add a newline and thus makes the Slack message untidy. This is obviously not a huge issue in the grand scheme of things but I'm curious as to whether there is a way around this or if it's an issue with how it generates the output.
This is the relevant part of the receiver config:text: >-{{ range .Alerts }}*Alert:* {{ .Annotations.summary }} - `{{ .Labels.severity }}`{{ if ( ne ( .Annotations.description | len ) 0 ) and ( ne ( .Annotations.grafana | len ) 0 ) }}*Grafana:* <{{ .Annotations.grafana }}|:chart_with_upwards_trend:>*Description:* {{ .Annotations.description }}{{ else if ( ne ( .Annotations.grafana | len ) 0 ) and ( eq ( .Annotations.description | len ) 0 ) }}*Grafana:* <{{ .Annotations.grafana }}|:chart_with_upwards_trend:>{{ else if ( ne ( .Annotations.description | len ) 0 ) and ( eq ( .Annotations.grafana | len ) 0 ) }}*Description:* {{ .Annotations.description }}{{ end }}*Details:*{{ range .Labels.SortedPairs }} • *{{ .Name }}:* `{{ .Value }}`{{ end }}{{ end }}and this is what the output looks like:
--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/60e85748-3905-4b2a-968c-4aa21fba0921%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On 7 February 2018 at 14:35, <matthew...@anatwine.com> wrote:I've got a Slack receiver setup in Alertmanager and it uses an if statement to determine if a particular annotation is in use, and if so to change the output. The issue here is that the if statement seems to add a newline and thus makes the Slack message untidy. This is obviously not a huge issue in the grand scheme of things but I'm curious as to whether there is a way around this or if it's an issue with how it generates the output.Newer versions of Go have a way to make this a bit easier, see https://golang.org/pkg/text/template/#hdr-Text_and_spacesBrian
--Brian Brazil