Detailed instructions on how to manage alerts for "DataSourceNoData" errors?

  • What Grafana version and what operating system are you using?

    • Grafana 12.3.0 container on Ubuntu 24.04
  • What are you trying to achieve?

    • I’m using summaries to improve alerting in my Grafana setup, but when one of my datasources fails because of “NoData”, I get a normal summary with [no value] instead of labels and variables. I want to create customized alerts for the DatasourceNoData errors, and I understand that it creates a separate alert, but it’s not clear how to achieve it.
  • What happened?

    • These are the notifications I receive when there is NoData:

  • Can you copy/paste the configuration(s) that you are having problems with?

    • Notification template (for summary):

      {{ define "alert_summary" }}
        {{ if gt (len .Alerts.Firing) 0 }} 
          {{ len .Alerts.Firing }} firing: 
          {{ range .Alerts.Firing }} 
          {{ .Annotations.summary }} 
          {{ end }} 
        {{ end }} 
        {{ if gt (len .Alerts.Resolved) 0 }} 
          {{ len .Alerts.Resolved }} resolved: 
          {{ range .Alerts.Resolved }} 
          {{ .Annotations.summary }} 
          {{ end }} 
        {{ end }} 
      {{ end }}
      
    • Notification template (for title):

    { define "alert_title" }}
      🚨 {{ .Status | title }} Alert: {{ .CommonLabels.alertname }}
    {{ end }}
    
    
    

I’m hoping someone can explain to me how I define a generic alert for all the DatasourceNoData that applies for all my alerts, and that has it’s own format.

Thank you, @jangaraj. I am creating a notification policy, as you suggested. Would you, if possible, suggest a syntax that can be used in my scenario? I tried this in my notification template, but it isn’t working:

{{ define "test_summary" }}
  {{ if eq (index .Labels "alertname") "DatasourceNoData" }} 
    No data coming for alert: {{ .Labels.rulename }}
  {{ end }} 
  {{ if gt (len .Alerts.Firing) 0 }} 
    {{ len .Alerts.Firing }} firing: 
    {{ range .Alerts.Firing }} 
    {{ .Annotations.summary }} 
    {{ end }} 
  {{ end }} 
  {{ if gt (len .Alerts.Resolved) 0 }} 
    {{ len .Alerts.Resolved }} resolved: 
    {{ range .Alerts.Resolved }} 
    {{ .Annotations.summary }} 
    {{ end }} 
  {{ end }} 
{{ end }}

image

Sorry, you must say what is not working explicitly. Don’t think that someone will know that implicitly.