zoukankan      html  css  js  c++  java
  • Cacti实现短信报警

    一、 软件环境:cacti(需Threshold插件),飞信机器人(fetion)
    二、 安装过程:
    Cacti的Threshold插件下载及安装配置参见:Cacti配置e-mail报警
    飞信机器人(fetion)下载及安装配置参见:系统监控:linux命令行-飞信客户端发送免费报警短信
    三、 配置过程:
    1.按照Cacti配置e-mail报警配置并启用thold
    2.编辑cacti/plugins/thold/thold-functions.php
    在thold–functions.php查找thold_mail($global_alert_address, ”, $subject, $msg, $file_array);行在此行下面加入:

    exec("echo $subject >>/var/www/html/cacti/plugins/thold/alter.log");
    exec("/var/www/html/cacti/plugins/thold/sendsms.sh");

    查找 thold_mail($item["notify_extra"], ”, $subject,
    $msg, $file_array);行在此行下面加入:

    exec("echo $subject >>/var/www/html/cacti/plugins/thold/alter.log"); #将报警信息记录到alter.log
    exec("/var/www/html/cacti/plugins/thold/sendsms.sh"); #执行sendsms.sh

    备注:本人的thold安装在/var/www/html/cacti/plugins/thold/目录中,如果注释掉thold_mail,只通过短信发送报警。不注释掉thold_mail,会通过email和短信同时发送报警

    thold-functions.php生成的alter.log范例如下:

    192.168.1.207 - Used Space - G: Label: [hdd_percent] is still above threshold of 85 with 99

    编写脚本sendsms.sh自动调用飞信机器人发送报警

    #!/bin/sh
    #send sms by fetion
    #Write by John.Lv
    if [ ! -e "/var/www/html/cacti/plugins/thold/alert.log" ];then #判断alter.log是否存在
    echo "Usage:alert.log does not exist"
    exit
    fi
    if [ -n "`cat /var/www/html/cacti/plugins/thold/alert.log`" ]; then #判断alter.log是否有报警信息
    admin="135xxxxxxxx"  #短信接收人,需在你飞信的好友列表中
    echo "sms $admin "`cat /var/www/html/cacti/plugins/thold/alert.log` >>/var/www/html/cacti/plugins/thold/sms.txt #发送alter.log中的报警信息给admin
    echo "exit" >> /var/www/html/cacti/plugins/thold/sms.txt #退出飞信
    else
    echo "Usage:no alert"
    exit
    fi
    if [ -n "`cat /var/www/html/cacti/plugins/thold/sms.txt`" ] ; then
    /var/www/html/cacti/plugins/thold/install/fetion -u 13512345678 -p "123456" -b /var/www/html/cacti/plugins/thold/sms.txt  -EN
    #调用fetion发送短信,命令格式和参数说明参见:系统监控:linux命令行-飞信客户端发送免费报警短信
    rm -f /var/www/html/cacti/plugins/thold/sms.txt 1>/dev/null 2>&1
    rm -f /var/www/html/cacti/plugins/thold/alert.log 1>/dev/null 2>&1
    else
    echo "Usgae:no message to send"
    exit
    fi

    ok,配置完成了,现在就可以通过短信接收报警信息了

  • 相关阅读:
    基于python批量获取Url
    记一次tp5.0.11rce
    centOS 6.2 x64系统上安装 oracle 11g R2 x64
    用xmanager连接Linux的配置步骤
    0级备份和全备
    配置EM遇到的问题
    转:如何迁移oracle 队列表
    oracle audit
    VIEWS for Oracle object privileges
    Oracle 脚本
  • 原文地址:https://www.cnblogs.com/weaver1/p/2342383.html
Copyright © 2011-2022 走看看