Zabbix自定义飞书webhook告警媒介1
说明:此配置仅适用于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;
}