Last active
June 5, 2025 01:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ 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