一、有关钉钉机器人的配置不再赘述
我是因为把zabbix从6.0升级到7.0之后,发现之前的脚本不能用了
二、因为zabbix更改了函数名,比如curlhttprequest更改为httprequest造成的
三、媒介类型配置如下图
四、脚本如下
var dingding = {
key: null,
message: null,
msgtype: "markdown",
proxy: null,
to: null,
subject: null,
sendMessage: function () {
var params = {
msgtype: "markdown",
markdown: {
title: "告警信息⚠️",
text: dingding.message
},
disable_web_page_preview: true,
disable_notification: false
},
data,
response,
request = new HttpRequest(),
url = 'https://oapi.dingtalk.com/robot/send?access_token=' + dingding.key;
if (dingding.proxy) {
request.setProxy(dingding.proxy);
}
request.addHeader('Content-Type: application/json');
data = JSON.stringify(params);
// Remove replace() function if you want to see the exposed key in the log file.
Zabbix.Log( 4,"[dingding Webhook] URL: " + url.replace(dingding.key, "<BOT KEY>"));
Zabbix.Log(4, "[dingding Webhook] params: " + data);
response = request.post(url, data);
Zabbix.Log(4, "[dingding Webhook] HTTP code: " + request.getStatus());
try {
response = JSON.parse(response);
} catch (error) {
response = null;
}
if (request.getStatus() !== 200 || response.errcode !== 0) {
if (typeof response.errmsg === "string") {
throw response.errmsg;
} else {
throw "Unknown error. Check debug log for more information.";
}
}
},
};
try {
var params = JSON.parse(value);
if (typeof params.Key === "undefined") {
throw 'Incorrect value is given for parameter "Key": parameter is missing';
}
dingding.key = params.Key;
if (params.HTTPProxy) {
dingding.proxy = params.HTTPProxy;
}
dingding.to = params.To;
dingding.message = params.Subject + "\n" + params.Message;
dingding.sendMessage();
return "OK";
} catch (error) {
Zabbix.Log(4, "[dingding Webhook] notification failed: " + error);
throw "Sending failed: " + error + ".";
}