Zabbix自定义飞书webhook告警媒介1

2023-12-13 04:37:40

说明:此配置仅适用于7版本及以上,低版本可能有问题

JavaScript 内容如下:
try {
           var sourceData = JSON.parse(value),
               req = new HttpRequest(),
               response;
       
           if (sourceData.HTTPProxy) {
               req.setProxy(sourceData.HTTPProxy);
           }
       
           req.addHeader('Content-Type: application/json');
           var targetData = {
               "msg_type": "text",
               "content": {
                    "text": sourceData.message
               }
           };


           Zabbix.log(4, '[feishu  webhook ] Webhook request with value=' + value);
       
           response = req.post(sourceData.URL, JSON.stringify(targetData));
           Zabbix.log(4, '[feishu    webhook ] Responded with code: ' + req.getStatus() + '. Response: ' + response);
       
           try {
               response = JSON.parse(response);
           }
           catch (error) {
               if (req.getStatus() < 200 || req.getStatus() >= 300) {
                   throw 'Request failed with status code ' + req.getStatus();
               }
               else {
                   throw 'Request success, but response parsing failed.';
               }
           }
       
           if (req.getStatus() !== 200 || response.code !== 0) {
               throw response.error;
           }
       
           return 'OK';
       }
       catch (error) {

           Zabbix.log(3, '[ Jira webhook ] Sending failed. Error: ' + error);
       
           throw 'Failed with error: ' + error;
       }

文章来源:https://blog.csdn.net/u013235026/article/details/134825868
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。