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

文章目录

      • [zabbix 告警纸飞机方式](#zabbix 告警纸飞机方式)
        • [webhook 方式](#webhook 方式)

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}
相关推荐
ZoeLandia13 分钟前
nginx实战分析
运维·前端·nginx
菜菜子爱学习28 分钟前
Nginx学习笔记(九)—— Nginx Rewrite深度解析
linux·运维·笔记·学习·nginx
迷之程序员1 小时前
服务器装两个cpu
运维·服务器
Tearstornbyrain1 小时前
在Ubuntu24.04中使用ssh连接本地git仓库到github远程仓库
linux·git·ubuntu·ssh·github
Jia ming2 小时前
【奔跑吧!Linux 内核(第二版)】第6章:简单的字符设备驱动(三)
linux
Mr_Xuhhh3 小时前
传输层协议 TCP(1)
运维·服务器·网络·c++·网络协议·tcp/ip·https
星哥说事3 小时前
如何将堡塔云WAF备份、迁移到新的服务器
linux
楽码4 小时前
端到端应用Hmac加密
服务器·后端·算法
ycchenG74 小时前
缓存元数据损坏操作步骤(lvmcache修复)
linux·缓存
扶风呀4 小时前
具有熔断能力和活性探测的服务负载均衡解决方案
运维·负载均衡