添加报警媒介

image

var weixin = {
    key: null,
    message: null,
    msgtype: "makrdown",
    proxy: null,
    sendMessage: function () {
        var params = {
            msgtype: weixin.msgtype,
            markdown: {
                content: weixin.message
            },
        },
            data,
            response,
            request = new CurlHttpRequest(),
            url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=" + weixin.key;
        if (weixin.proxy) {
            request.setProxy(weixin.proxy);
        }
        request.AddHeader("Content-Type:application/json");
        data = JSON.stringify(params);
        Zabbix.Log(4,"[weixin Webhook] URL:" + url.replace(weixin.key,"<BOT KEY>"));
        Zabbix.Log(4,"[weixin Webhook] params:" + data);
        response = request.Post(url,data);
        Zabbix.Log(4,"[weixin Webhook] HTTP code:" + request.Status());
        try{
            response = JSON.parse(response);
        }catch(error){
            response = null;
        }
        if(request.Status() != 200 || response.errorcode != 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';
    }
    weixin.key =  params.Key;
    if(params.HTTPProxy){
        weixin.proxy = params.HTTPProxy;
    }
    weixin.to = params.To;
    weixin.message = params.Subject + "\n" + params.Message;
    weixin.sendMessage();
    return "OK";
}catch(error){
    Zabbix.Log(4,"[weixin Webhook] notification failed: " + error);
    throw "Sending failed:" + error;
}

添加消息模板

  • 问题模板

  • 问题恢复模板

配置触发动作

image

测试