[ZBX-17490] CurlHttpRequest method is not working with http-url-encoded URIs Created: 2020 Mar 21  Updated: 2024 Apr 10  Resolved: 2021 May 18

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Server (S), Templates (T)
Affects Version/s: 4.4.6
Fix Version/s: None

Type: Problem report Priority: Trivial
Reporter: Leonid Assignee: Zabbix Development Team
Resolution: Duplicate Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

CentOS 7.7.1908, postgreSQL 9.2.24


Attachments: XML File media_slack.xml    
Issue Links:
Duplicate
duplicates ZBX-18673 Slack Webhook from Templates - Throws... Closed
Team: Team INT
Sprint: Sprint 62 (Mar 2020), Sprint 63 (Apr 2020), Sprint 64 (May 2020), Sprint 65 (Jun 2020), Sprint 66 (Jul 2020), Sprint 67 (Aug 2020), Sprint 68 (Sep 2020), Sprint 69 (Oct 2020), Sprint 70 (Nov 2020), Sprint 71 (Dec 2020), Sprint 72 (Jan 2021), Sprint 73 (Feb 2021), Sprint 74 (Mar 2021), Sprint 75 (Apr 2021)

 Description   

Steps to reproduce:

  1. Create Slack media with instructions from https://www.zabbix.com/integrations/slack
  2. Problem message sent, but reported as non-sent because of  error: SyntaxError: invalid json (at offset 1)
  3. Resolve messages is not sent at all, error - channel_not_found

Result:
        Messages in Slack is not working as expected
Expected:
       Messages sends to Slack without errors, resolve and update works too

 

Comment:

 ** After some investigations i've found the reason.
Part of script from tutorial tries to get permalink for Slack message to attach it as tag to Problem in Zabbix:

function getPermalink(channelId, messageTimestamp) {

 var req = new CurlHttpRequest();
 req.AddHeader('Content-Type: application/x-www-form-urlencoded; charset=utf-8');
 req.AddHeader('Authorization: Bearer ' + params.bot_token);

 var resp = JSON.parse(req.Get('\{0}?Ftoken=\{1}&channel=\{2}&message_ts=\{3}'.format(
 Slack.getPermalink,
 params.bot_token,
 channelId,
 messageTimestamp
 )););

 if (req.Status != 200 && !resp.ok) {
  throw resp.error;
 }

 return resp.permalink;
}

CurlHTTPRequest method is not working properly with urlencoded URI, in result it fails to get good answer from server and get plain-text HTML instead of JSON, so script falls with error.



 Comments   
Comment by kaihei sameshima [ 2020 Apr 24 ]

I solved it in the following way.

var resp = JSON.parse(req.Get(url, "")); var resp = JSON.parse(req.Get(url, ""));

see: https://support.zabbix.com/browse/ZBX-17518

Comment by Leonid [ 2020 Apr 30 ]

@kaihei777  thank you, fixed it with your suggestion, so it's template issue, not server itself.

Comment by Leonid [ 2020 May 05 ]

Fixed template: media_slack.xml

Comment by Aleksandrs Larionovs (Inactive) [ 2021 May 14 ]

Resolved in ZBX-18673

Generated at Wed May 14 07:53:26 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.