| Subcribe via RSS

Cacti实现短信报警

8月 25th, 2008 Posted in Cacti < by John.Lv >

一、 软件环境: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,配置完成了,现在就可以通过短信接收报警信息了

6 Responses to “Cacti实现短信报警”

  1. gary Says:

    诚心请教在windows下php+apache+mysql+cacti怎么设置飞信的短信报警啊?
    能不能请老大您花点时间写一个这个的教程啊。这方面文章好少。


  2. Michael Field Says:

    To gary:
    不知道在windows配置遇到什么问题吗?
    请罗列一下,一同探讨?


  3. gary Says:

    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–functions.php找不到thold_mail($global_alert_address, ”, $subject, $msg, $file_array);这行啊?
    我的thold版本是0.3.9.
    帮帮忙。谢谢。


  4. arching Says:

    我的情况跟上面的兄弟一样:在thold–functions.php找不到thold_mail($global_alert_address, ”, $subject, $msg, $file_array);这行。版本也是0.3.9.
    还请老大花点时间帮忙解答一下,谢谢


  5. hiphop Says:

    thold–functions.php找不到thold_mail($global_alert_address, ”, $subject, $msg, $file_array);


  6. hiphop Says:

    上面是
    exec(”echo $subject >>/var/www/html/cacti/plugins/thold/alter.log”);
    下面脚本中if [ ! -e "/var/www/html/cacti/plugins/thold/alert.log" ];then

    一个是alter.log 还有1个是alert.log 大哥是不 是搞错了啊


Leave a Reply