Ad Widget

Collapse

添加媒介 Rocket.Chat 测试报错

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • singi
    Junior Member
    • Jan 2023
    • 6

    #1

    添加媒介 Rocket.Chat 测试报错

    我想添加 Rocket.Chat 类型媒介,按照官方文档配置后,发起测试得到如下错误

    Code:
    00:00:00.000 [调试] [ RocketChat Webhook ] Sending request: https://domain/hooks/xxx/xxx/api/v1/chat.postMessage {"channel":"{ALERT.SENDTO}","attachments":[{"collapsed":false,"color":"#97AAB3","title":"{ALERT.SUBJECT}","title_link":"{$ZABBIX.URL}/tr_events.php?triggerid={TRIGGER.ID}&eventid={EVENT.ID}","text":"{ALERT.MESSAGE}"}]}
    00:00:00.039 [调试] [ RocketChat Webhook ] Received response with status code 405
    00:00:00.039 [调试] [ RocketChat Webhook ] Failed to parse response received from RocketChat
    00:00:00.039 [告警] [ RocketChat Webhook ] ERROR: Request failed with status code 405. Check debug log for more information.
    测试配置如下:
    Click image for larger version

Name:	image.png
Views:	304
Size:	89.3 KB
ID:	457224
    Click image for larger version

Name:	image.png
Views:	224
Size:	78.2 KB
ID:	457225
    媒介配置如下
    Click image for larger version

Name:	image.png
Views:	228
Size:	85.8 KB
ID:	457226
    Click image for larger version

Name:	image.png
Views:	233
Size:	61.0 KB
ID:	457227​有什么解决方法吗?谢谢。​​
  • singi
    Junior Member
    • Jan 2023
    • 6

    #2
    使用自定义webhook方式解决了,下面是我的脚本,仅供参考:
    Click image for larger version

Name:	image.png
Views:	264
Size:	44.9 KB
ID:	457702
    Code:
    try {
       var valueObject = JSON.parse(value),
           req = new HttpRequest(),
           response;
    
       req.addHeader('Content-Type: application/json');
    
       Zabbix.log(4, '[ RocketChat webhook ] Webhook request with value=' + value);
      
       var params = {
         alias: "zabbix notification",
         text: valueObject.subject + "\n" + valueObject.message
       }
    
       response = req.post('https://domain/hooks/xxx/xxx', JSON.stringify(params));
       Zabbix.log(4, '[ RocketChat webhook ] Responded with code: ' + req.Status + '. 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.ok || response.ok === 'false') {
           throw response.error;
       }
    
       return 'OK';
    }
    catch (error) {
       Zabbix.log(3, '[ RocketChat webhook ] Sending failed. Error: ' + error);
    
       throw 'Failed with error: ' + error;
    }​

    Comment

    Working...