How to remove indent in Slack alert?

I’m trying to format my Slack alerts (which is a horrible experience compared to the good old days of just typing the text you want for the alert), and I keep getting a strange indent in the alert text.

Screenshot from 2022-11-04 08-13-05

My Slack Contact Point template:

{{ define "slack.default.title" }}
  [ Alerting ] 
{{ end }}

{{ define "slack.default.message" }}
    {{ range . }}
        {{ if gt (len .Annotations.summary) 0 }}{{ .Annotations.summary }} {{ end }}
        {{ if gt (len .DashboardURL) 0 }}Dashboard: {{ .DashboardURL }}{{ end }}
    {{ end }}
{{ end }}

{{ define "slack.resolved.message" }}
    {{ range . }}
        {{ .Labels.alertname }} on {{ .Labels.node_name }}
        {{ if gt (len .DashboardURL) 0 }}Dashboard: {{ .DashboardURL }}
        {{ end }}
    {{ end }}
{{ end }}


{{ define "slack" }}
        {{ if gt (len .Alerts.Firing) 0 }}Alerting{{ template "slack.default.message" .Alerts.Firing }}{{ end }}
        {{ if gt (len .Alerts.Resolved) 0 }}OK{{ template "slack.resolved.message" .Alerts.Resolved }}{{ end }}
{{ end }}

The body of the contact point:
Screenshot from 2022-11-04 08-19-35

I don’t understand why this indent is showing up and it’s driving me crazy!

1 Like

There was a rogue whitespace in my template. I didn’t notice it. All better now.

1 Like