Template "my_first_template" not defined

Hi Team, I am trying to add custom notification template to my contact point. All of the configuration for grafana are being handled using Helm Charts.

grafana:
  enabled: true
  sidecar:
    datasources:
      label: ""
      labelValue: ""
      enabled: true
      maxLines: 1000
  image:
    tag: 11.4.0
  ingress:
    enabled: true
    ingressClassName: shared-ingress-class
    annotations:
      nginx.ingress.kubernetes.io/enable-cors: "true"
      nginx.ingress.kubernetes.io/cors-allow-origin: "domain.cloud"
      cert-manager.io/cluster-issuer: shared-clusterissuer
      acme.cert-manager.io/http01-edit-in-place: "true"
    path: /
    pathType: Prefix
    hosts:
    - domain.cloud
    tls:
    - hosts:
        - domain.cloud
      secretName: shared-grafana-tls-secret
  initChownData:
    enabled: false
  persistence:
    enabled: true
  grafana.ini:
    smtp:
      enabled: true
      host: 
      user: 
      password: 
      from_address: domain@domain.cloud
      from_name: domain
      skip_verify: true
  alerting:
    contactpoints.yaml:
        contactPoints:
          - orgId: 1
            name: domain
            receivers:
              - uid: mail
                name: domain
                type: sns
                settings:
                  topic_arn:
                  region: <region>
                  subject: |
                    Error Alert
                  message: |
                    {{ template "my_first_template" }}
    templates.yaml:
      apiVersion: 1
      templates:
        - orgId: 1
          name: my_first_template
          template: |
            {{ `
            {{ define "my_first_template" }}
            Custom notification message
            {{ end }}
            ` }}
    policies.yaml:
      policies:
        - orgId: 1
          receiver: domain
          group_wait: 1m
          repeat_interval: 1m
          routes:
          - receiver: domain
  serviceAccount:
    create: false
    name: shared-grafana-serviceaccount
    annotations:
      eks.amazonaws.com/role-arn:

Helm Chart that I am currently utilizing is: loki-stack 2.10.2 · grafana/grafana
Since this chart is not managed in present days, I have updated the image tag for grafana to update it on version 11.4.0.

Here is my configuration for contactpoint:

        contactPoints:
          - orgId: 1
            name: domain
            receivers:
              - uid: mail
                name: domain
                type: sns
                settings:
                  topic_arn:
                  region: <region>
                  subject: |
                    Error Alert
                  message: |
                    {{ template "my_first_template" }}

Here is my configuration for notification template:

      apiVersion: 1
      templates:
        - orgId: 1
          name: my_first_template
          template: |
            {{ `
            {{ define "my_first_template" }}
            Custom notification message
            {{ end }}
            ` }}

The error that I am getting is template: gotpl:8:24: executing "gotpl" at <{{template "my_first_template"}}>: template "my_first_template" not defined

But when I looked into grafana UI my template was created.

If I want to use the created template manually I can now do it.

I need it all automatic. What can be the reason behind the error??

1 Like

There is a same syntax of using/defining templates for contact points/helm. So this is a command for helm. Of course that template is not defined on the helm level, so it wil fail. You need different syntax, so it won’t interpret it as a template command. I guess (test it and improve):

        message: |
                   {{ ` {{ template "my_first_template" }}` }} 

Thank you !!