Skip to content

Instantly share code, notes, and snippets.

@cdalvaro
Forked from Himura2la/Grafana Alert Template.md
Created January 3, 2024 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdalvaro/f06bc39802417e3ab67542eb660a9260 to your computer and use it in GitHub Desktop.
Save cdalvaro/f06bc39802417e3ab67542eb660a9260 to your computer and use it in GitHub Desktop.
How to use Grafana Alerts with the Telegram
  • Template name: telegram.message

  • Content:

    {{ define "alert_list" }}{{ range . }}{{ .Labels.alertname }}
    {{ range .Annotations.SortedPairs }}<strong>{{ .Name }}</strong>: {{ .Value }}
    {{ end }}| {{ if gt (len .GeneratorURL) 0 }}<a href="{{ .GeneratorURL }}">source</a> | {{ end }}{{ if gt (len .SilenceURL) 0 }}<a href="{{ .SilenceURL }}">silence</a> | {{ end }}{{ if gt (len .DashboardURL) 0 }}<a href="{{ .DashboardURL }}">dashboard</a> | {{ end }}{{ if gt (len .PanelURL) 0 }}<a href="{{ .PanelURL }}">panel</a> |{{ end }}
    —
    {{ end }}{{ end }}
    {{ define "telegram.message" }}
    {{ if gt (len .Alerts.Firing) 0 }}<strong>FIRING!!!</strong>
    —
    {{ template "alert_list" .Alerts.Firing }}
    {{ if gt (len .Alerts.Resolved) 0 }}
    {{ end }}{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}<strong>Resolved</strong>
    —
    {{ template "alert_list" .Alerts.Resolved }}
    {{ end }}{{ end }}
    
  • Contact point | Optional Telegram settings | Message: {{ template "telegram.message" . }}

  • Add verbose annotations to your alerts. Example: The <code>{{ $labels.host }}</code> host is low on free space! Used: {{ $values.display.Value }}% (where display is one of the queries).

  • I usually add the following queries: data (the datasource query), metric (the reduce expression), condition, and display, which is round($metric). Multi-dimensional rules documentation.

Also, check out this fork by @gelldur, this templeate is much more cmprehensive.

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