免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 896 | 回复: 0
打印 上一主题 下一主题

Cacti实现短信报警 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-10-10 23:46 |只看该作者 |倒序浏览

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

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/81377/showart_1286006.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP