have been trying to create a notification template from values but it doesn't seem to be working.
Code:
alerting:
rules.yaml:
apiVersion: 1
templates:
- orgID: 1
name: Slack Template
template: |
{{ define "alert_severity_prefix_emoji" }}
{{- if ne .Status "firing" }}
:white_check_mark:
{{- else if eq .CommonLabels.severity "critical" }}
:red_circle:
{{- else if eq .CommonLabels.severity "warning" }}
:warning:
{{ end }}
{{ end }}
{{ define "slack.print_alert" }}
{{ template "alert_severity_prefix_emoji" . }}
[{{.Status}}] {{ .Labels.alertname }}
*Labels*:
{{ range .Labels.SortedPairs }}
- {{ .Name }}: {{ .Value }}
{{ end }}
{{ if .Annotations }}
*Annotations*:
{{ range .Annotations.SortedPairs }}
- {{ .Name }}: {{ .Value }}
{{ end }}
{{ end }}
{{ if .SilenceURL }}
*Silence*: {{ .SilenceURL }}
{{ end }}
{{ if .DashboardURL -}}
*Go to dashboard*: {{ .DashboardURL }}
{{ end }}
{{ end }}
{{ define "slack.message" -}}
{{ if .Alerts.Firing -}}
{{ len .Alerts.Firing }} firing alert(s):
{{ range .Alerts.Firing }}
{{ template "slack.print_alert" . }}
{{ end }}
{{ end }}
{{ if .Alerts.Resolved }}
{{ len .Alerts.Resolved }} resolved alert(s):
{{ range .Alerts.Resolved }}
{{ template "slack.print_alert" .}}
{{ end }}
{{ end }}
{{ end }}'
The issue here is we have to pass this template in yaml file and yaml thinks {} are structs and because of that it is ignoring the whole template. Is there any way that I can pass this whole template as it is?
One way i tried is giving \
escape character that this '' is being reflected in the final template as well which we don't want.
Thanks in advance