Skip to content

Instantly share code, notes, and snippets.

@sanchpet
Last active June 5, 2025 01:57
Show Gist options
  • Save sanchpet/7641275a42243d3667b3146c5402be40 to your computer and use it in GitHub Desktop.
Save sanchpet/7641275a42243d3667b3146c5402be40 to your computer and use it in GitHub Desktop.
Telegram message template for Alertmanager & how to add it to your receiver in alertmanager.yml
receivers:
- name: 'Default'
telegram_configs:
- bot_token: <token>
api_url: https://api.telegram.org
chat_id: <chat_id>
message_thread_id: <message_thread_id> # for supergroups with threads
parse_mode: 'HTML'
message: '{{ template "telegram.message". }}'
templates:
- '../message_templates/telegram.tmpl' # path to our telegram.tmpl
{{ define "alert_list" }}{{ range . }}
---
πŸͺͺ <b>{{ .Labels.alertname }}</b>
{{- if eq .Labels.severity "critical" }}
🚨 CRITICAL 🚨 {{ end }}
{{- if eq .Labels.severity "warning" }}
⚠️ WARNING ⚠️{{ end }}
{{- if .Annotations.summary }}
πŸ“ {{ .Annotations.summary }}{{ end }}
{{- if .Annotations.description }}
πŸ“– {{ .Annotations.description }}{{ end }}
🏷 Labels:
{{ range .Labels.SortedPairs }} <i>{{ .Name }}</i>: <code>{{ .Value }}</code>
{{ end }}{{ end }}
πŸ›  <a href="https://grafana.prod.global:3000">Grafana</a> πŸ’Š <a href="https://alertmanager.prod.global:9093">Alertmanager</a> πŸ’Š <a href="https://">Any other link</a> πŸ› 
{{ end }}
{{ define "telegram.message" }}
{{ if gt (len .Alerts.Firing) 0 }}
πŸ”₯ Alerts Firing πŸ”₯
{{ template "alert_list" .Alerts.Firing }}
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
βœ… Alerts Resolved βœ…
{{ template "alert_list" .Alerts.Resolved }}
{{ end }}
{{ end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment