Zabbix 5.2 由浅入深之钉钉机器人告警(webhook方式)
时间:2025-11-03 20:26:40 出处:数据库阅读(143)

复制var dingding = { key: null,由浅 message: null, msgtype: "markdown", proxy: null, sendMessage: function () { var params = { msgtype: dingding.msgtype, markdown: { title: "IT小白Kasar",(注意这里可以修改) text: dingding.message }, }, data, response, request = new CurlHttpRequest(), 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 keyin 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.Status()); try { response = JSON.parse(response); } catch (error) { response = null; } if (request.Status() !== 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 + "."; } 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.
分享到:
温馨提示:以上内容和图片整理于网络,仅供参考,希望对您有帮助!如有侵权行为请联系删除!