[ZBX-26484] Telegram notifications don't work in some cases Created: 2025 May 27 Updated: 2025 Aug 01 Resolved: 2025 Jul 14 |
|
Status: | Closed |
Project: | ZABBIX BUGS AND ISSUES |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | 7.0.17rc1, 7.4.1rc1, 8.0.0alpha1 (master) |
Type: | Problem report | Priority: | Trivial |
Reporter: | Sergei Chistokhin | Assignee: | Denis Rasikhov (Inactive) |
Resolution: | Fixed | Votes: | 1 |
Labels: | None | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | 8h | ||
Original Estimate: | Not Specified |
Issue Links: |
|
||||||||
Story Points: | 0.75 |
Description |
I have 2 problems with telegram notifications from Zabbix, which I fixed for my installation, so I propose you do the same for everyone 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 #1Telegram 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 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)
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 #4Message templates, which are provided with the media template, have duplicated information |
Comments |
Comment by Denis Rasikhov (Inactive) [ 2025 Jun 10 ] |
Hello Chistokhin! Problem #1 Confirmed, will be fixed. Problem #2 Already reported in ZBX-22159, follow the updates there. Not exactly sure, but it's an old issue and I think it has something to do with the conflict on how the mediatype escapes special symbols and the expansion of Zabbix macros in message templates. New feature was also requested to help with workaround for this issue - ZBXNEXT-8565. Problem #3 These fields were added and have became required during Problem #4 At the moment almost all the mediatypes use the default message templates that are generated by the frontend, you are free to change it anytime to your liking. In any case, it's also out of scope and will not be addressed here. |
Comment by Denis Rasikhov (Inactive) [ 2025 Jul 09 ] |
Fixed in:
|