Zabbix webhook 自定义报警媒介

场景一:使用企业微信机器人报警

 

 图中的token是:在群组中添加机器人,机器人的webhook地址的key

var Wechat = { token: null, to: null, message: null, parse_mode: null, sendMessage: function() { var params = { msgtype: "text", chat_id: Wechat.to, text: { content:Wechat.message }, disable_web_page_preview: true, disable_notification: false }, data, response, request = new CurlHttpRequest(), url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=' + Wechat.token; if (Wechat.parse_mode !== null) { params['parse_mode'] = Wechat.parse_mode; } request.AddHeader('Content-Type: application/json'); data = JSON.stringify(params); // Remove replace() function if you want to see the exposed token in the log file. Zabbix.Log(4, '[Wechat Webhook] URL: ' + url.replace(Wechat.token, '<TOKEN>')); Zabbix.Log(4, '[Wechat Webhook] params: ' + data); response = request.Post(url, data); Zabbix.Log(4, '[Wechat Webhook] HTTP code: ' + request.Status()); Zabbix.Log(4, '[Wechat Webhook] response: ' + response); try { response = JSON.parse(response); } catch (error) { response = null; Zabbix.Log(4, '[Wechat Webhook] response parse error'); } if (request.Status() !== 200 || response.errcode !== 0 || response.errmsg !== 'ok') { 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.Token === 'undefined') { throw 'Incorrect value is given for parameter "Token": parameter is missing'; } Wechat.token = params.Token; if (['Markdown', 'HTML', 'MarkdownV2'].indexOf(params.ParseMode) !== -1) { Wechat.parse_mode = params.ParseMode; } Wechat.to = params.To; Wechat.message = params.Subject + '\n' + params.Message; Wechat.sendMessage(); return 'OK'; } catch (error) { Zabbix.Log(4, '[Wechat Webhook] notification failed: ' + error); throw 'Sending failed: ' + error + '.'; }

 

场景二:电话报警

 

var Wechat = { tel: null, calluser: function (){ var response, request = new CurlHttpRequest(), url = 'http://phone_server.com/TRinterfaceYun/CheckSystem.aspx?phone=' + Wechat.tel + '&guid=1234'; // 此处URL 为电话接口 Zabbix.Log(4, '[Wechat Webhook] URL: ' + url.replace(Wechat.tel, '<Tel>')); response = request.Post(url); Zabbix.Log(4, '[Wechat Webhook] HTTP code: ' + request.Status()); Zabbix.Log(4, '[Wechat Webhook] response: ' + response); try { response = JSON.parse(response); } catch (error) { response = null; Zabbix.Log(4, '[Wechat Webhook] response parse error'); } } } try { var params = JSON.parse(value); if (typeof params.Tel === 'undefined') { throw 'Incorrect value is given for parameter "Tel": parameter is missing'; } Wechat.tel = params.Tel; Wechat.calluser(); return 'OK'; } catch (error) { Zabbix.Log(4, '[Wechat Webhook] notification failed: ' + error); throw 'Sending failed: ' + error + '.'; }

 


__EOF__

本文作者语 默
本文链接https://www.cnblogs.com/weijie0717/p/15218832.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   语~默  阅读(1037)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· Qt个人项目总结 —— MySQL数据库查询与断言
点击右上角即可分享
微信分享提示