Webhook script examples

    Overview

    Jira webhook (custom)

    Slack webhook (custom)

    1. var params = JSON.parse(value),
    2. req = new HttpRequest(),
    3. response;
    4. if (params.HTTPProxy) {
    5. req.setProxy(params.HTTPProxy);
    6. }
    7. req.addHeader('Content-Type: application/x-www-form-urlencoded');
    8. Zabbix.log(4, '[ Slack webhook ] Webhook request with value=' + value);
    9. Zabbix.log(4, '[ Slack webhook ] Responded with code: ' + req.getStatus() + '. Response: ' + response);
    10. try {
    11. response = JSON.parse(response);
    12. }
    13. catch (error) {
    14. if (req.getStatus() < 200 || req.getStatus() >= 300) {
    15. throw 'Request failed with status code ' + req.getStatus();
    16. }
    17. else {
    18. }
    19. if (req.getStatus() !== 200 || !response.ok || response.ok === 'false') {
    20. throw response.error;
    21. }
    22. return 'OK';
    23. }
    24. catch (error) {
    25. Zabbix.log(3, '[ Slack webhook ] Sending failed. Error: ' + error);
    26. throw 'Failed with error: ' + error;