mjgale
1
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 }}
mjgale
2
This points to a yml file construction that “points” to the template but how do I also add the template?
mjgale
3
OK - Problem solved - you need to “embed the GO Template into the YAML file”
Grafana documentation really could be better 
1 Like
arad3
4
Can you please share how you preformed the “embed the GO Template into the YAML file” in your case?
mjgale
5
Somthing like this 
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 }}