Skip to content

Instantly share code, notes, and snippets.

@noobogami
Last active September 17, 2025 14:58
Show Gist options
  • Select an option

  • Save noobogami/3c58c6934d10a261823044b83ea66120 to your computer and use it in GitHub Desktop.

Select an option

Save noobogami/3c58c6934d10a261823044b83ea66120 to your computer and use it in GitHub Desktop.
grafana telegram contact point message template
{{ define "telegram_message" }}
{{ if gt (len .Alerts.Firing) 0 }}
<b>🚨 {{ len .Alerts.Firing }} alert(s)</b>
{{ range .Alerts.Firing }} {{ template "telegram_alert_firing" .}} {{ end }} {{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
<b>✅ {{ len .Alerts.Resolved }} alert(s) resolved:</b>
{{ range .Alerts.Resolved }} {{ template "telegram_alert_resolved" .}} {{ end }} {{ end }}
{{ end }}
{{ define "telegram_alert_firing" }}
<b>🔴 {{ .Labels.alertname }}</b>
{{- if .Annotations.summary }}
<b>Summary:</b> {{ .Annotations.summary }}
{{- end }}
{{- if index .Labels "instance" }}
<b>Instance:</b> {{ index .Labels "instance" }}
{{- end }}
{{- if index .Labels "Severity" }}
<b>Severity:</b> {{ index .Labels "Severity" }}
{{- end }}
<b>Value:</b>
{{- $value := .Values }}
{{- if ne (printf "%.1f" $value.A) "0.0" }}
{{ printf "%.1f" $value.A }}
{{- end }}
{{- if ne (printf "%.1f" $value.B) "0.0" }}
{{ printf "%.1f" $value.B }}
{{- end }}
<a href="https://YOUR_GRAFANA_URL/alerting/silence/new?alertmanager=grafana&matcher=alertname%3D{{ .Labels.alertname }}&orgId=1">silence</a> | <a href="https://YOUR_GRAFANA_URL/d/dashboard_uid?from={{ .StartsAt.Unix }}000&orgId=1&to={{ .EndsAt.Unix }}000">dashboard</a> | <a href="https://YOUR_GRAFANA_URL/d/dashboard_uid?from={{ .StartsAt.Unix }}000&orgId=1&to={{ .EndsAt.Unix }}000&viewPanel=1">panel</a>
{{ end }}
{{ define "telegram_alert_resolved" }}
<b>🟢 {{ .Labels.alertname }}</b>
{{- if .Annotations.summary }}
<b>Summary:</b> {{ .Annotations.summary }}
{{- end }}
{{- if index .Labels "instance" }}
<b>Instance:</b> {{ index .Labels "instance" }}
{{- end }}
{{ end }}
{{ template "telegram_message" . }}
@noobogami
Copy link
Author

noobogami commented Sep 17, 2025

based on this answer you can use {{ .DashboardURL }} instead of harcoding url if you defined server url in env

GF_SERVER_ROOT_URL=https://my-domain.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment