I am using grafana oncall 1.3.7 to send alert messages to telegram. It's installed on my server in docker containers. Image is official grafana/oncall. Setted up alertmanager integration. I am looking for a way to edit top part (first 4 lines in example bellow) of telegram message, or atleast to get rid of link and empty line after it.
In documentation (https://grafana.com/docs/oncall/latest/jinja2-templating/) it is mentioned as Source link, but when editing templates in grafana oncall you can use cheatsheet and in "Additional jinja2 variables" section find grafana_oncall_link. If you add it in your message part of template, you can see it's exactly the same link from the top part of message.
So far i've tried every possible way i could find to change it in grafana oncall jinja2 template for alerts:
- Empty alerts
- Things like
<a href="">{{grafana_oncall_link}}</a>
or{% set grafana_oncall_link = "" %}
in both title and message part of template - Tried creating grafana template, changing default from a link in documentatin (https://github.com/grafana/alerting/blob/main/templates/default_template.go), do not seem to be involved in telegram <-grafana_oncall <- alertmanager messages templating at all.
It seems it's some kind of default template that is applied before your custom one and i did not find where can i change it in web-ui. My last lead is:
grep -rn /opt -e grafana_oncall_link | grep alertmanager
output is around 40 .pyc (most of them) and .py files like:
/var/lib/docker/overlay2/be1...b2d/diff/etc/app/apps/alerts/incident_appearance/templaters/pycache/alert_templater.cpython-311.pyc: binary file matches
/var/lib/docker/overlay2/482c3186b5b57ca6d16f82e69be74930eb9743ac78d59dc9eba2a3b8259919ac/diff/etc/app/config_integrations/alertmanager.py:28
Looks like .py files contain default templates for alerts. I was thinking maybe template that is used for top part is defined by one of this files. But after trying to change a few of them in different placec and restarting containers i saw no changes at all.
Example telegram message:
#2347, TestAlert
Firing, alerts: 1
Source: AlertManager - Alertmanager
http://10.129.0.24:3000/a/grafana-oncall-app/alert-groups/IGM5XMP625L45
Проблема: This alert was sent by user for demonstration purposes
Сайт:
Адрес:
Экспортёр:
Typical payload from alertmanager:
{
"status": "resolved",
"labels": {
"alertname": "SSL CERT TEST",
"grafana_folder": "Test",
"instance": "https://***/",
"job": "blackbox"
},
"annotations": {
"description": "Не продлился сертификат, осталось меньше 8 дней",
"runbook_url": "https://letsencrypt.org/docs/",
"summary": "Что-то пошло не так"
},
"startsAt": "2022-12-08T10:21:00Z",
"endsAt": "2022-12-13T07:32:00Z",
"generatorURL": "http://grafana.***/alerting/grafana/FRjqFuKVk/view",
"fingerprint": "27d07fde7c9f6d5c",
"dashboardURL": "",
"panelURL": "",
"values": {
"B": 1678688994,
"C": 0
},
"valueString": "[ var='B' labels={__name__=probe_ssl_earliest_cert_expiry, instance=https://***/, job=blackbox} value=1.678688994e+09 ], [ var='C' labels={__name__=probe_ssl_earliest_cert_expiry, instance=https://***/, job=blackbox} value=0 ]"
}
jinja2 template from example message:
{{- payload.get("labels", {}).get("alertname", "No title (check Title Template)") -}}
<b>Проблема:</b> {{ payload["annotations"]["description"] }}
<b>Сайт:</b> {{ payload["labels"]["host"] }}
<b>Адрес:</b> {{ payload["labels"]["instance"] }}
<b>Экспортёр:</b> {{ payload["labels"]["job"] }}