zabbix7.0(6.4以上)钉钉告警脚本

一、有关钉钉机器人的配置不再赘述

        我是因为把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 + "."; 
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值