- Template name:
telegram.message
- Content:
{{- /* Telegram message to use: {{ template "telegram.message2" . }} */ -}}
{{ define "__alerts_list" -}}
{{ range . }}
{{if ne (index .Labels "alertname") "" -}}
{{ if eq .Status "firing" }}π΄{{ else }}π’{{ end }}
{{- if ne (index .Labels "severity") "" -}}
<u><b>P{{ index .Labels "severity" }}</b></u> {{ end -}}
<b>{{ index .Labels "alertname" }}</b> π {{ .StartsAt.Format "15:04:05 ποΈ 2006-01-02" }}{{ end -}}
{{ if len .Annotations }}
<i>Annotations:</i>
{{ range .Annotations.SortedPairs -}}
- {{ .Name }}: {{ .Value }}
{{ end -}}
{{ end }}
{{ if len .Labels -}}
<i>Labels:</i>
{{ range .Labels.SortedPairs -}}
- {{ .Name }}: {{ .Value }}
{{ end -}}
{{ end }}
<i>Value:</i> <pre>{{ .ValueString }}</pre>
{{- 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 -}}
<pre>--------</pre>
{{- end -}} {{- /* range */ -}}
{{- end -}} {{- /* define __alerts_list */ -}}
{{ define "__telegram.title" -}}
{{ if ne (index .CommonLabels "severity") "" }} <u><b>P{{ index .CommonLabels "severity" }}</b></u> {{ end -}}
{{ if ne (index .CommonLabels "alertname") "" -}}
[{{ index .CommonLabels "alertname" }}]
{{- end -}}
{{- end -}}{{- /* define __telegram */ -}}
{{ define "telegram.message" }}
{{ if gt (len .Alerts.Firing) 0 }}
π¨ <b>ALARM</b> (#{{ .Alerts.Firing | len }})
{{- template "__alerts_list" .Alerts.Firing }}{{ end -}}
{{ if gt (len .Alerts.Resolved) 0 }}
β
<b>RESOLVED</b>{{ template "__telegram.title" . }} (#{{ .Alerts.Resolved | len }})
{{- template "__alerts_list" .Alerts.Resolved }}{{ end }}
<a href="{{ .ExternalURL }}">π² Grafana</a>
{{- 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](https://grafana.com/docs/grafana/next/alerting/alerting-rules/create-grafana-managed-rule).
thanks a lot for the developed template. this is very useful.
just a question, the "href"s, they are not shown as links in my telegram channel, even tho i have set the parse mode to HTML in the contact point telegram optional settings. i am getting just texts
source | π silence | π dashboard | panel
can you guys tell me where and what settings i need to apply to get as hyperlinks? i have two channels (webhook + telegram) and in my webhook it is properly received as hyperlinks, but not in telegram
thanks in advance