Ad Widget

Collapse

Zabbix 5.2 error sending Telegram messages

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • terule
    Junior Member
    • May 2021
    • 4

    #1

    Zabbix 5.2 error sending Telegram messages

    I`m new here and didn`t found any entries about this.

    I configured Telegram in media types and tested it with a simple message, it works just fine.

    But when a problem happens i get the message
    Code:
    zabbix telegram Sending failed: Bad Request: can't parse entities: Unsupported start tag "" at byte offset 76.
    My parse_mode is set to HTML and when i use any html tags "<" or ">" ont the message I get the error even with the "process tags" checked.


    Click image for larger version

Name:	Screenshot 2021-05-04 074401.png
Views:	4310
Size:	47.4 KB
ID:	424039

    I didn't change the Telegram JS default script

    Code:
    var Telegram = {
    token: null,
    to: null,
    message: null,
    proxy: null,
    parse_mode: null,
    
    sendMessage: function() {
    var params = {
    chat_id: Telegram.to,
    text: Telegram.message,
    disable_web_page_preview: true,
    disable_notification: false
    },
    data,
    response,
    request = new CurlHttpRequest(),
    url = 'https://api.telegram.org/bot' + Telegram.token + '/sendMessage';
    
    if (Telegram.parse_mode !== null) {
    params['parse_mode'] = Telegram.parse_mode;
    }
    
    if (Telegram.proxy) {
    request.SetProxy(Telegram.proxy);
    }
    
    request.AddHeader('Content-Type: application/json');
    data = JSON.stringify(params);
    
    // Remove replace() function if you want to see the exposed token in the log file.
    Zabbix.Log(4, '[Telegram Webhook] URL: ' + url.replace(Telegram.token, '<TOKEN>'));
    Zabbix.Log(4, '[Telegram Webhook] params: ' + data);
    response = request.Post(url, data);
    Zabbix.Log(4, '[Telegram Webhook] HTTP code: ' + request.Status());
    
    try {
    response = JSON.parse(response);
    }
    catch (error) {
    response = null;
    }
    
    if (request.Status() !== 200 || typeof response.ok !== 'boolean' || response.ok !== true) {
    if (typeof response.description === 'string') {
    throw response.description;
    }
    else {
    throw 'Unknown error. Check debug log for more information.'
    }
    }
    }
    }
    
    try {
    var params = JSON.parse(value);
    
    if (typeof params.Token === 'undefined') {
    throw 'Incorrect value is given for parameter "Token": parameter is missing';
    }
    
    Telegram.token = params.Token;
    
    if (params.HTTPProxy) {
    Telegram.proxy = params.HTTPProxy;
    }
    
    if (['Markdown', 'HTML', 'MarkdownV2'].indexOf(params.ParseMode) !== -1) {
    Telegram.parse_mode = params.ParseMode;
    }
    
    Telegram.to = params.To;
    Telegram.message = params.Subject + '\n' + params.Message;
    Telegram.sendMessage();
    
    return 'OK';
    }
    catch (error) {
    Zabbix.Log(4, '[Telegram Webhook] notification failed: ' + error);
    throw 'Sending failed: ' + error + '.';
    }
    The message I'm trying to send:

    Code:
    ❌ Problem: <b>{HOST.NAME}</b>
    {EVENT.NAME}
    <b>{ITEM.NAME1}</b> <i>{ITEM.VALUE1}</i>
    
    <a href={HOST.IP}>{HOST.IP}</a>
    <i>{EVENT.SEVERITY}</i>
    can someone please help me with this?
  • avmagrini
    Junior Member
    • Jun 2021
    • 2

    #2
    Hello! I deployed a Zabbix 5.2 server and successfully configured notifications by Telegram, however, I have the same problem reported by terule. Was anybody able to solve the problem in any way other than renaming all triggers with the characters <, > and &?
    Thanks!

    Comment

    • DrQuake
      Junior Member
      • Oct 2023
      • 1

      #3
      It's simple. Consists of two dogmas
      1. You using HTML formatting
      2. You have HTML tag symbols <> in trigger name/text and so on

      And one consequence
      You must filter <> only in trigger text , thats not possible in current state of zabbix engine notifier, it's consists of ONE final phase in notification method JS filter when you can filter tags and you cannot determine was that symbol/tag from trigger name/text or trigger real intentional HTML tags, you must use html symbols escape BEFORE making message text, in place like message template , when it's not possible for now or just not use HTML processing at all(max possible - intent body vs header using replaces and special prefix/suffix in message template and so on at notification method level) and filter EVERY <> symbol also, that makes HTML mode mostly useless at all

      Comment

      Working...