Ad Widget

Collapse

Zabbix error telegram

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gleisonsouza
    Junior Member
    • Sep 2021
    • 3

    #1

    Zabbix error telegram

    Media type test failed.
    • Sending failed: TypeError: cannot read property 'description' of null.

  • gleisonsouza
    Junior Member
    • Sep 2021
    • 3

    #2
    var Telegram = {
    token: null,
    to: null,
    message: null,
    proxy: null,
    parse_mode: null,

    sendMessage: function() {
    var params = {
    chat_id: -50...,
    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 + '.';
    }

    Comment

    • ChandarbeerNegi
      Junior Member
      • Sep 2023
      • 3

      #3
      Hi,
      I am getting error while sending telegram alerts using zabbix UI.
      Please note that i am using proxy in between and able to send test message using curl but not able send test alert using ZABBIX UI. Please find the attached screenshot of the same.
      Click image for larger version

Name:	Screenshot 2023-10-31 13593677.png
Views:	803
Size:	28.2 KB
ID:	473251
      Attached Files

      Comment

      Working...