File Provisioning template files

Hi

I’ve got the following template that I’d like to provision using file based provisioning - but how do I do that?

I’ve got contact-points, notification-policies, data-sources etc all working as YAML.

For this template I’ve tried “.tmpl" and ".go” - but it never works:

level=warn msg=“file has invalid suffix '***” (.yaml,.yml,.json accepted), skipping"

This isn’t yaml / json - so how can I provision the template?

{{ define "teams.default.title" }}
{{ .CommonLabels.alertname }}
{{ .CommonLabels.type }}

[{{ .Status | toUpper }}
		{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}]
				{{ if gt (.Alerts.Resolved | len) 0 }}, RESOLVED:{{ .Alerts.Resolved | len }} - {{ .CommonLabels.alertname }}
				{{ end }}
		{{ end }}
{{ end }}

{{ define "teams.default.text" }}
{{ range .Alerts }}
{{ if gt (len .Annotations) 0 }}
{{ .Annotations.Summary }}
{{ end }}
{{ end }}
{{ end }}

This points to a yml file construction that “points” to the template but how do I also add the template?

OK - Problem solved - you need to “embed the GO Template into the YAML file”

Grafana documentation really could be better :roll_eyes:

1 Like

Can you please share how you preformed the “embed the GO Template into the YAML file” in your case?

Somthing like this :smiley:

apiVersion: 1
templates: 
  
- orgID: 1
  name: teams-simple
  # <string, required> content of the the template
  template: |
    {{ define "teams.default.title" }}
    {{ .CommonLabels.alertname }} {{ "\n" }}
    {{ .CommonLabels.type }}

    [{{ .Status | toUpper }}
         {{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}]
              {{ if gt (.Alerts.Resolved | len) 0 }}, RESOLVED:{{ .Alerts.Resolved | len }} - {{ .CommonLabels.alertname }}
              {{ end }}
        {{ end }}
    {{ end }}

    {{ define "teams.default.text" }}
    {{ range .Alerts }}
    {{ if gt (len .Annotations) 0 }}
    {{ .Annotations.Summary }}
    {{ end }}
    {{ end }}
    {{ end }}