zabbix5.0设置企业微信机器人推送

1. 在企业微信群聊中建立一个机器人 获取webhook地址 2. zabbix中选择管理–报警媒介类型 创建媒体类型,填写以下内容 脚本内容参考下面的内容 var Qiyeweixin = { key: null, message: null, msgtype: "markdown", proxy: null, sendMessage: function () { var params = { msgtype: Qiyeweixin.msgtype, markdown: { content: Qiyeweixin.message, }, }, data, response, request = new CurlHttpRequest(), url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=" + Qiyeweixin.key; if (Qiyeweixin.proxy) { request.setProxy(Qiyeweixin.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, "[Qiyeweixin Webhook] URL: " + url.replace(Qiyeweixin.key, "<BOT KEY>") ); Zabbix.Log(4, "[Qiyeweixin Webhook] params: " + data); response = request.Post(url, data); Zabbix.Log(4, "[Qiyeweixin 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'; } Qiyeweixin.key = params.Key; if (params.HTTPProxy) { Qiyeweixin.proxy = params.HTTPProxy; } Qiyeweixin.to = params.To; Qiyeweixin.message = params.Subject + "\n" + params.Message; Qiyeweixin.sendMessage(); return "OK"; } catch (error) { Zabbix.Log(4, "[Qiyeweixin Webhook] notification failed: " + error); throw "Sending failed: " + error + "."; } 选择Message templates,把所有默认的模板都添加上 ...

2024年4月28日 · 3 分钟 · 492 字 · AIHugoBlog