-
Incident report
-
Resolution: Unresolved
-
Trivial
-
None
-
None
-
None
-
None
I have 2 problems with telegram notifications from Zabbix, which I fixed for my installation, so I propose you do the same for everyone
Feel free to divide it into 2 separate tasks or convert 2nd one to a feature request (even though I think it's a bug - because it does not work)
I've tried template v 7.4 from GitLab (https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/telegram/media_telegram.yaml) - it has the same issues as my 7.2.6 Debian distro.
Problem #1
Telegram notification script doesn't work without tags in the event, for example in autodiscovery
2.1 Autodiscovery
In zbx_es_execute() param:{"alert_message":"Host name: nettools.home.lab\r\nHost IP: 192.168.100.142\r\nAgent port: 10050","alert_subject":"Autoregistration: nettools.home.lab","api_chat_id":"---CUT---","event_nseverity":"{EVENT.NSEVERITY}","event_severity":"{EVENT.SEVERITY}","event_source":"2","event_tags":"{EVENT.TAGSJSON}","event_update_nseverity":"{EVENT.UPDATE.NSEVERITY}","event_update_severity":"{EVENT.UPDATE.SEVERITY}","event_update_status":"{EVENT.UPDATE.STATUS}","event_value":"{EVENT.VALUE}","api_parse_mode":"MarkdownV2","api_token":"---CUT---"} [Telegram Webhook] notification failed: Webhook processing failed: Value "event_tags" contains invalid JSON.
This can be fixed by defining the event_tags = [] in the settings, but in this case, message quotation will not work, and it's a very useful feature.
2.2 In the test window
Fill in the test data with `alert_message, event_source, event_value, event_update_status`, but leave `event_tags` as it is.
Log:
In zbx_es_execute() param:{"alert_message":"[zabbix](https:\/\/zabbix.home.lab\/)","alert_subject":"{ALERT.SUBJECT}","api_chat_id":"--CUT-","api_parse_mode":"MarkdownV2","api_token":"-CUT--","event_nseverity":"{EVENT.NSEVERITY} ","event_severity":" {EVENT.SEVERITY}","event_source":"0","event_tags":"{EVENT.TAGSJSON}","event_update_nseverity":"{EVENT.UPDATE.NSEVERITY}","event_update_severity":"{EVENT.UPDATE.SEVERITY}","event_update_status":"0","event_value":"0"} [Telegram Webhook] notification failed: Webhook processing failed: Value "event_tags" contains invalid JSON.
Problem #2
MarkdownV2 does not work as expected
When testing with `[zabbix](https://zabbix.home.lab/)`
In zbx_es_execute() param:{"alert_message":"[zabbix](https:\/\/zabbix.home.lab\/)","alert_subject":"","api_chat_id":"--CUT-","api_parse_mode":"MarkdownV2","api_token":"-CUT--","event_nseverity":"{EVENT.NSEVERITY}","event_severity":"{EVENT.SEVERITY} ","event_source":"0","event_tags":"[]","event_update_nseverity":" {EVENT.UPDATE.NSEVERITY} ","event_update_severity":" {EVENT.UPDATE.SEVERITY} ","event_update_status":"0","event_value":"0"} 0250527:090054.729 [Telegram Webhook] Sending post request:" {\"disable_web_page_preview\":true,\"disable_notification\":false,\"chat_id\":\"---CUT---\",\"text\":\"\\\\[zabbix\\\\]\\\\(https://zabbix\\\\.home\\\\.lab/\\\\)\",\"parse_mode\":\"markdownv2\"} " [Telegram Webhook] Response has been received: {"ok":true,"result":{"message_id":473,"from": {"id":---CUT---,"is_bot":true,"first_name":"---CUT---","username":"---CUT---"} ,"chat":{"id":--CUT-,"title":"-CUT--","type":"group","all_members_are_administrators":true,"accepted_gift_types":{"unlimited_gifts":false,"limited_gifts":false,"unique_gifts":false,"premium_subscription":false}},"date":1748336454,"text":"[zabbix](https://zabbix.home.lab/)","entities":[ {"offset":9,"length":24,"type":"url"} ],"link_preview_options": {"is_disabled":true} }}
In my experiments with AI-generated code, I was unsuccessful in incorporating the Telegramify-Markdown library (https://github.com/skoropadas/telegramify-markdown) into the script, but I believe it is the right way to do it.
I did some experiments with its Python version, and it produces correct results when paired with the 'telebot' library for sending messages. For example when I feed it with `[zabbix.home.lab](https://zabbix.home.lab/)` , it converts it to `[zabbix\.home\.lab](https://zabbix.home.lab/)` and then telebot library sends:
{'chat_id': '---CUT---', 'text': '[zabbix\\.home\\.lab](https://zabbix.home.lab/)\n', 'parse_mode': 'MarkdownV2'}
It works.
So, simple dot replacement will not work, since you need to replace symbols differently, based on where it is - in the link, code/pre block, or text.
PS:
Problem #3
(mostly documentation + UX)
Media testing scenarios are complicated, documentation obsolete
The test window, mentioned in https://www.zabbix.com/integrations/telegram, does not exist anymore, and for the sake of testing, you should fill
alert_message - your text alert_subject - empty, or other text api_chat_id - your chat id event_source - 0 (0 - Trigger, 1 - Discovery, 2 - Autoregistration, 3 - Internal, 4 - Service) event_value - 0 (1 for problem, 0 for recovering) event_update_status - 0 (0 - Webhook was called because of problem/recovery event, 1 - Update operation.) event_tags - [] (because for now it does not fill the empty tags for now)
Problem #4
Message templates, which are provided with the media template, have duplicated information
I think it is because it was inherited from email templates, where you have a "Subject" field and text, but in a telegram message, you only have text, so it's easier to just leave it empty and edit a single field.