飞天使-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}
相关推荐
行云流水剑14 分钟前
【学习记录】在 Ubuntu 中将新硬盘挂载到 /home 目录的完整指南
服务器·学习·ubuntu
藥瓿亭19 分钟前
K8S认证|CKS题库+答案| 7. Dockerfile 检测
运维·ubuntu·docker·云原生·容器·kubernetes·cks
搬码临时工44 分钟前
如何把本地服务器变成公网服务器?内网ip网址转换到外网连接访问
运维·服务器·网络·tcp/ip·智能路由器·远程工作·访问公司内网
vortex51 小时前
探索 Shell:选择适合你的命令行利器 bash, zsh, fish, dash, sh...
linux·开发语言·bash·shell·dash
GalaxyPokemon1 小时前
LeetCode - 148. 排序链表
linux·算法·leetcode
Guheyunyi1 小时前
监测预警系统重塑隧道安全新范式
大数据·运维·人工智能·科技·安全
懒羊羊大王呀1 小时前
Ubuntu20.04中 Redis 的安装和配置
linux·redis
鳄鱼杆2 小时前
服务器 | Centos 9 系统中,如何部署SpringBoot后端项目?
服务器·spring boot·centos
杰哥技术分享2 小时前
在 CentOS 上安装 Docker 和 Docker Compose 并配置使用国内镜像源
linux·docker·centos
知更鸟呆呆2 小时前
【Linux操作系统】基础开发工具(yum、vim、gcc/g++)
linux·运维·vim