zabbix配置企业微信群机器人告警

一、数据获取

1.1 添加群机器人

image.png

1.2 新建一个机器人

image.png
image.png

1.3 复制token到zabbix

image.png

二、操作步骤

2.1 新建告警媒介

image.png

2.2 填入相关信息

image.png

2.3 配置消息模板

image.png
image.png

三、脚本

var Wechat = {
    token: null,
    to: null,
    message: null,
    parse_mode: null,

    sendMessage: function() {
        var params = {
            msgtype: "markdown",
            chat_id: Wechat.to,
            markdown: {
                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 + '.';
}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Zabbix是一个广泛使用的网络监控和告警系统,企业微信机器人Zabbix提供的一种告警方式。通过Zabbix企业微信机器人可以将监控告警信息发送到企业微信中,方便及时获取告警信息并进行处理。的代码中,我们可以看到通过调用企业微信机器人接口实现发送消息的功能。该代码使用Python编写,通过传递参数实现将指定的用户、主题和消息内容发送给企业微信机器人。在发送消息的过程中,可以使用Markdown语法来格式化消息的样式,如引用中的效果图所示。 通过在Zabbix配置中设置相应的触发器和动作,可以将Zabbix监控系统中的告警信息与该Python脚本进行关联,从而实现将告警信息发送到企业微信的功能。 需要注意的是,为了能够正常使用企业微信机器人,需要在企业微信开发者中心申请机器人的key,并将其替换在代码中的对应位置。123 #### 引用[.reference_title] - *1* [zabbix监控-企业微信webhook告警并使用markdown格式](https://blog.csdn.net/stars_moon1024/article/details/123042369)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *2* [Zabbix-企微Bot告警机器人(markdown)](https://blog.csdn.net/qq_45194089/article/details/127742251)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *3* [Zabbix 6.4 版本企业微信群机器人报警配置](https://blog.csdn.net/qq_42725261/article/details/130510337)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值