Created
April 5, 2023 14:08
-
-
Save jidckii/5ac5f8f20368b56de72af70222509b7b to your computer and use it in GitHub Desktop.
Alertmanager telegram template
This file contains 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 "__yucca_text_alert_list" }}{{ range . }} | |
--- | |
πͺͺ <b>{{ .Labels.alertname }}</b> | |
{{- 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://yucca.app/">Grafana</a> π <a href="https://yucca.app/">Alertmanager</a> π <a href="https://yucca.app/">Prometheus</a> π | |
{{ end }} | |
{{ define "telegram.yucca.message" }} | |
{{ if gt (len .Alerts.Firing) 0 }} | |
π₯ Alerts Firing π₯ | |
{{ template "__yucca_text_alert_list" .Alerts.Firing }} | |
{{ end }} | |
{{ if gt (len .Alerts.Resolved) 0 }} | |
β Alerts Resolved β | |
{{ template "__yucca_text_alert_list" .Alerts.Resolved }} | |
{{ end }} | |
{{ end }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the template for "firing" and "resolved" alerts
`cat ../alertmanager/templates/telegram.tmpl
{{ define "telegram.default.message" }}
{{ if eq .Status "firing" }}
{{ if eq .CommonLabels.severity "critical" }}π΄ Alert: {{ .CommonLabels.alertname }}
{{ else if eq .CommonLabels.severity "warning" }}π Alert: {{ .CommonLabels.alertname }}
{{ else }}βͺοΈ Alert: {{ .CommonLabels.alertname }}
{{ end }}
Status: π₯ FIRING
Severity: {{ if eq .CommonLabels.severity "critical" }}π΄ {{ .CommonLabels.severity | title }}{{ else if eq .CommonLabels.severity "warning" }}π {{ .CommonLabels.severity | title }}{{ else }}βͺοΈ {{ .CommonLabels.severity | title }}{{ end }}
{{ else if eq .Status "resolved" }}
{{ if eq .CommonLabels.severity "critical" }}π’ π TRANSPORT Alert: {{ .CommonLabels.alertname }}
{{ else if eq .CommonLabels.severity "warning" }}π’ π TRANSPORT Alert: {{ .CommonLabels.alertname }}
{{ else }}βͺοΈ Alert: {{ .CommonLabels.alertname }}
{{ end }}
Status: β RESOLVED
Severity: {{ if eq .CommonLabels.severity "critical" }}π’ {{ .CommonLabels.severity | title }}{{ else if eq .CommonLabels.severity "warning" }}π’ {{ .CommonLabels.severity | title }}{{ else }}βͺοΈ {{ .CommonLabels.severity | title }}{{ end }}
{{ end }}
{{ range .Alerts }}
Instance: {{ .Labels.instance }}
{{ end }}
{{ end }}`
Example notification:
Firing
π Alert: HighMemoryUsage>90%
Status: π₯ FIRING
Severity: π Warning
Instance: server-1:9100
Resolved
π’ Alert: HighMemoryUsage>90%
Status: β RESOLVED
Severity: π’ Warning
Instance: server-1:9100