Add Alert mail body different data sources

Hello,
I can only add one screen to the alert email screen.
I want to add images from different data sources to their respective screens. Could you help me with this?
I’ve been trying to do this in the template, but it didn’t work.

{{- /\* This is a copy of the "default.message". \*/ -}}

{{- /\* Edit the template name and template content as needed. \*/ -}}

{{ define "default.message.copy" }}

{{ if gt (len .Alerts.Firing) 0 }}

<b>Firing</b><br/>

{{ template "\__text_alert_list.copy" .Alerts.Firing }}

{{ end }}

 

{{ if gt (len .Alerts.Resolved) 0 }}

<b>Resolved</b><br/>

{{ template "\__text_alert_list.copy" .Alerts.Resolved }}

{{ end }}

 

<br/><br/>

<b>Ek Grafik / Detay Görünümü:</b><br/>

<img

  src="[http://grafana:3000/render/d-solo/\*\*\*\*orgId=2&timezone=browser&panelId=1&hideLogo=true&width=10…](http://ovrbabil:1763/render/d-solo/urxg8v?orgId=2&timezone=browser&panelId=1&hideLogo=true&width=1000&height=500&tz=Europe%2FIstanbul%22 "http://ovrbabil:1763/render/d-solo/urxg8v?orgid=2&timezone=browser&panelid=1&hidelogo=true&width=1000&height=500&tz=europe%2fistanbul%22")

  alt="Ek Grafik"

  style="max-width:100%; height:auto; border:1px solid #ddd;"

/>

{{ end }}

 

{{ define "\__text_alert_list.copy" }}

{{ range . }}

Value: {{ template "\__text_values_list.copy" . }}

Labels:

{{ range .Labels.SortedPairs }} - {{ .Name }} = {{ .Value }}

{{ end }}

Annotations:

{{ range .Annotations.SortedPairs }} - {{ .Name }} = {{ .Value }}

{{ end }}

{{ if gt (len .GeneratorURL) 0 }}Source: {{ .GeneratorURL }}

{{ end }}

{{ if gt (len .SilenceURL) 0 }}Silence: {{ .SilenceURL }}

{{ end }}

{{ if gt (len .DashboardURL) 0 }}Dashboard: {{ .DashboardURL }}

{{ end }}

{{ if gt (len .PanelURL) 0 }}Panel: {{ .PanelURL }}

{{ end }}

{{ end }}

{{ end }}

 

{{ define "\__text_values_list.copy" }}

{{ if len .Values }}

{{ $first := true }}

{{ range $refID, $value := .Values -}}

{{ if $first }}{{ $first = false }}{{ else }}, {{ end }}{{ $refID }}={{ $value }}

{{ end -}}

{{ else }}\[no value\]{{ end }}

{{ end }}

Firing

Value:
[no value]

Labels:

  • alertname = TestAlert
  • instance = Grafana

Annotations:

  • summary = Notification test

Silence: http://grafana:3000/alerting/silence/new?alertmanager=grafana&matcher=alertname%3DTestAlert&match…




Ek Grafik / Detay Görünümü:

<img
src=“http://grafana:3000/render/d-solo/****orgId=2&timezone=browser&panelId=1&hideLogo=true&width=10…”
alt=“Ek Grafik”
style=“max-width:100%; height:auto; border:1px solid #ddd;”
/>

Hi,

The image only shows once because your <img> tag is placed outside the alert loop (after the Firing/Resolved section), so it never varies per alert. To get a different image per data source, move it inside __text_alert_list.copy and build the URL from a label that differs per alert rule.

Add a label to each alert rule, e.g. →

dashboard_uid: urxg8v
panel_id: 1

(different values per data source)

Update the template →

gotemplate

{{ define "__text_alert_list.copy" }}
{{ range . }}
Value: {{ template "__text_values_list.copy" . }}
Labels:
{{ range .Labels.SortedPairs }} - {{ .Name }} = {{ .Value }}
{{ end }}
Annotations:
{{ range .Annotations.SortedPairs }} - {{ .Name }} = {{ .Value }}
{{ end }}
{{ if gt (len .GeneratorURL) 0 }}Source: {{ .GeneratorURL }}{{ end }}
{{ if gt (len .SilenceURL) 0 }}Silence: {{ .SilenceURL }}{{ end }}

{{ if and .Labels.dashboard_uid .Labels.panel_id }}
<br/><b>Ek Grafik / Detay Görünümü:</b><br/>
<img
  src="http://grafana:3000/render/d-solo/{{ .Labels.dashboard_uid }}?orgId=2&timezone=browser&panelId={{ .Labels.panel_id }}&hideLogo=true&width=1000&height=500&tz=Europe%2FIstanbul"
  alt="Ek Grafik"
  style="max-width:100%; height:auto; border:1px solid #ddd;"
/>
{{ end }}
{{ end }}
{{ end }}

Remove the old standalone <img> block from default.message.copy → the loop now handles it.

If your Grafana render endpoint requires login, the image won’t load in email at all, since email clients fetch it anonymously. Enable anonymous access for the render path, add a render token to the URL, or use Public Dashboards.
Test by Alerting → Contact points → Templates → Preview before relying on live alerts.