飞天使-linux操作的一些技巧与知识点9-zabbix6.0 容器之纸飞机告警设置

zabbix 告警纸飞机方式

第一种方式参考 https://blog.csdn.net/yetugeng/article/details/99682432



bash-4.4$ cat telegram.sh 
#!/bin/bash


MSG=$1

TOKEN="61231432278:AAsdfsdfsdfsdHUxBwPSINc2kfOGhVik"
CHAT_ID=-41dsddesfsd3

curl -s -X POST https://api.telegram.org/bot$TOKEN/sendMessage -d chat_id=$CHAT_ID -d text="$MSG" >> /dev/null


webhook 方式
var Telegram = {
    token: null,
    to: null,
    message: null,
    proxy: null,
    parse_mode: null,

    escapeMarkup: function (str, mode) {
        switch (mode) {
            case 'markdown':
                return str.replace(/([_*\[`])/g, '\\$&');

            case 'markdownv2':
                return str.replace(/([_*\[\]()~`>#+\-=|{}.!])/g, '\\$&');

            default:
                return str;
        }
    },

    sendMessage: function () {
        var params = {
            chat_id: Telegram.to,
            text: Telegram.message,
            disable_web_page_preview: true,
            disable_notification: false
        },
        data,
        response,
        request = new HttpRequest(),
        url = 'https://api.telegram.org/bot' + Telegram.token + '/sendMessage';

        if (Telegram.parse_mode !== null) {
            params['parse_mode'] = Telegram.parse_mode;
        }

        if (Telegram.proxy) {
            request.setProxy(Telegram.proxy);
        }

        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, '[Telegram Webhook] URL: ' + url.replace(Telegram.token, '<TOKEN>'));
        Zabbix.log(4, '[Telegram Webhook] params: ' + data);
        response = request.post(url, data);
        Zabbix.log(4, '[Telegram Webhook] HTTP code: ' + request.getStatus());

        try {
            response = JSON.parse(response);
        }
        catch (error) {
            response = null;
        }

        if (request.getStatus() !== 200 || typeof response.ok !== 'boolean' || response.ok !== true) {
            if (typeof response.description === 'string') {
                throw response.description;
            }
            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';
    }

    Telegram.token = params.Token;

    if (params.HTTPProxy) {
        Telegram.proxy = params.HTTPProxy;
    } 

    params.ParseMode = params.ParseMode.toLowerCase();
    
    if (['markdown', 'html', 'markdownv2'].indexOf(params.ParseMode) !== -1) {
        Telegram.parse_mode = params.ParseMode;
    }

    Telegram.to = params.To;
    Telegram.message = params.Subject + '\n' + params.Message;

    if (['markdown', 'markdownv2'].indexOf(params.ParseMode) !== -1) {
        Telegram.message = Telegram.escapeMarkup(Telegram.message, params.ParseMode);
    }

    Telegram.sendMessage();

    return 'OK';
}
catch (error) {
    Zabbix.log(4, '[Telegram Webhook] notification failed: ' + error);
    throw 'Sending failed: ' + error + '.';
}
Message {ALERT.MESSAGE}
ParseMode  Markdown
Subject {ALERT.SUBJECT}

在这里插入图片描述

在这里插入图片描述

告警设置

操作
{{fire}}{{fire}}{{fire}}:告警节点:{TRIGGER.NAME}

问题详情: {ITEM.NAME}:{ITEM.VALUE} 
告警主机: {HOST.NAME} 
IP地址:{HOST.CONN}
告警时间: {EVENT.DATE} {EVENT.TIME} 
告警等级: {TRIGGER.SEVERITY} 
告警信息: {TRIGGER.NAME} 
告警项目: {TRIGGER.KEY1} 
当前状态: {TRIGGER.STATUS}.{ITEM.VALUE} 
事件ID: {EVENT.ID}


恢复操作 
{{OK}}{{OK}}{{OK}}:恢复节点:{TRIGGER.NAME}

问题详情: {ITEM.NAME}:{ITEM.VALUE} 
恢复主机: {HOST.NAME} 
IP地址:{HOST.CONN}
恢复时间: {EVENT.DATE} {EVENT.TIME} 
事件等级: {TRIGGER.SEVERITY} 
恢复项目: {TRIGGER.KEY1} 
当前状态: {TRIGGER.STATUS}.{ITEM.VALUE} 
事件ID: {EVENT.ID}


更新操作 
服务器:{HOST.NAME}: 报警确认

确认人:{USER.FULLNAME} 
时间:{ACK.DATE} {ACK.TIME} 
确认信息如下:"{ACK.MESSAGE}"
确认主机:{HOST.NAME}
问题服务器IP:{HOST.IP}
问题ID:{EVENT.ID}
当前的问题是: {TRIGGER.NAME}

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

客户端配置
#cat /etc/zabbix/zabbix_agent2.conf
PidFile=/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=zabbix.opp.com
ServerActive=zabbix.oppcom
Hostname=system.hostname
Include=/etc/zabbix/zabbix_agent2.d/*.conf
PluginSocket=/run/zabbix/agent.plugin.sock
ControlSocket=/run/zabbix/agent.sock
Include=./zabbix_agent2.d/plugins.d/*.conf
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值