Ad Widget

Collapse

Webhook Assistance. Req.post returns errors but works.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SteveThePirate
    Junior Member
    • Nov 2022
    • 2

    #1

    Webhook Assistance. Req.post returns errors but works.

    Hi,

    I'm a new Zabbix user, and I wrote a webbook to write a notification to one of my REST endpoints.

    Currently I'm running Zabbix 6.2.4 on Ubuntu 22.04 in a Virtual Box Image, DB MySQL. I followed the Ubuntu install instructions on the Zabbix page.

    Strangely the webhook works. The receiving system gets the POST message, processes it and responds, but Zabbix reports an error.

    The error I receive is:

    Failed with error: TypeError: undefined not callable (property 'Status' of [object Object])​
    The log has the following:

    00:00:00.000 [Debug] [ My webhook ] Request: [object Object]
    00:00:00.000 [Debug] [ My webhook ] Request: {}
    00:00:01.878 [Warning] [ My webhook ] Sending failed. Error: TypeError: undefined not callable (property 'Status' of [object Object])​
    Dr Google has proven no help.

    I have simplified my code below, but it still reproduces the error.

    Any suggestions on what to look into next?

    Code:
    try {
        var request = new HttpRequest();
        var response;
    
        Zabbix.log(4, '[ My webhook ] Request: ' + request);
        Zabbix.log(4, '[ My webhook ] Request: ' + JSON.stringify(request));
        response = request.post('https://myharcdoded.url/endpoint/', 'My Hard Coded Data');
    
        Zabbix.log(4, '[ My webhook ] Responded with code: ' + request.Status() + '. Response: ' + response);
    
        try {
            response = JSON.parse(response);
        } catch (error) {
            if (request.getStatus() < 200 || request.getStatus() >= 300) {
                throw 'Request failed with status code ' + request.getStatus();
            } else {
                throw 'Request success, but response parsing failed.';
            }
        }
    
        if (request.getStatus() !== 200 || !response.ok || response.ok === 'false') {
            throw response.error;
        }
    
        return 'OK';
    } catch (error) {
        Zabbix.log(3, '[ My webhook ] Sending failed. Error: ' + error);
    
        throw 'Failed with error: ' + error;
    }​
  • SteveThePirate
    Junior Member
    • Nov 2022
    • 2

    #2
    I worked it out.

    I copied the code from the documentation, Slack sample located here: https://www.zabbix.com/documentation...bhook_examples the error is in one of the log lines.

    Code:
    Zabbix.log(4, '[ Slack webhook ] Responded with code: ' + req.Status() + '. Response: ' + response);
    should be

    Code:
    Zabbix.log(4, '[ Slack webhook ] Responded with code: ' + req.getStatus() + '. Response: ' + response);

    Comment

    Working...