点击这里给我发消息

我的ITblog我作主  关注→ 『伊波拉』→ 测试 SzDlinXie- ITblog     

·√· 本ITblog站点记录相关的软件技术文档、网络技术杂志、测试技术杂谈等技术文档的管理站点.联系方式:MSN:dowling@sunlike.cn QQ:94595885

统计

积分与排名

测试技术网站链接

最新评论

Cacti实现MSN报警

Cacti实现MSN报警

一、 软件环境:cacti(需Threshold插件),MSN机器人(SendMsg)
二、 安装过程:
Cacti的Threshold插件参见:Cacti配置e-mail报警
MSN机器人(SendMsg)参见:系统监控:msn在线机器人实时报警
三、 配置过程:
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("sh /var/www/html/cacti/plugins/thold/sendmessage.sh");

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

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

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

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

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

编写脚本sendmessage.sh自动调用SendMsg发送报警

#!/bin/sh
echo `echo -n "date:"&&date +%Y-%m-%d-%H:%M` >> /var/www/html/sendMsg/msn.txt.1
#得到当前的日期+时间
cat /var/www/html/cacti/plugins/thold/alter.log >>/var/www/html/sendMsg/msn.txt.1
#读取alter.log的报警信息
now=`date +%Y-%m-%d-%H:%M`
SA=(disk)
msnaddr=(lvming104@hotmail.com) #报警接收人msn
sendMsg()
{
num=0
while [ $num -lt 1 ];
do
wget --post-data "sender=test@live.cn&password=12346&recipient=${1}&message=${2}" http://127.0.0.1/sendMsg/index.php -O /var/www/html/sendMsg/index.php.1 >/dev/null 2>&1
#sender:发送人msn,password:密码。/var/www/html/sendMsg为sendMsn安装目录
if [ -f /var/www/html/sendMsg/index.php.1 ]; then
if cat /var/www/html/sendMsg/index.php.1 |grep -i successfully >/dev/null 2>&1;then
num=1 #判断信息发送成功
elif cat /var/www/html/sendMsg/index.php.1 |grep -i "The user appears to be offline" >/dev/null 2>&1;then
num=1 #判断msn接受人为是否在线状态
echo "The user is offline."
exit 0
elif cat /var/www/html/sendMsg/index.php.1 |grep -i "Something went wrong trying to connect to the server" >/dev/null 2>&1;then
num=1 #判断msn 服务器存在连接问题
echo "MSN server is wrong."
exit 0
else
num=0 #除了以上三种情况退出循环外,其他情况重试。
fi
rm -f /var/www/html/sendMsg/index.php.1
else
num=0
fi
done
}
 
mv /var/www/html/sendMsg/msn.txt /var/www/html/sendMsg/bak/msn$now.txt -f 1>/dev/null 2>&1
mv /var/www/html/sendMsg/msn.txt.1 /var/www/html/sendMsg/msn.txt -f 1>/dev/null 2>&1
rm /var/www/html/cacti/plugins/thold/alter.log -f 1>/dev/null 2>&1

for i in 0
do
if cat /var/www/html/sendMsg/msn.txt ; then
messages=`cat /var/www/html/sendMsg/msn.txt ` #读取要发送的信息
sendMsg "${msnaddr[$i]}" "$messages" #发送报警信息
else
continue
fi
done

ok,配置完成了,现在就可以通过MSN接收报警信息了:如下所示

下次更新Cacti实现短信报警,敬请期待

posted on 2008-09-05 23:22 szdlinxie 阅读(851) 评论(3)  编辑 收藏 引用 所属分类: 电脑技术杂志网络技术杂志操作系统技术杂谈

评论

# re: Cacti实现MSN报警 2008-09-08 16:15 游子

cacti 是个啥东东?  回复  更多评论   

# re: Cacti实现MSN报警 2008-10-11 18:24 simplels

拿了别人东西要懂得感谢。。。至少你也说明出处吧。。。。
郁闷  回复  更多评论   

# re: Cacti实现MSN报警 2009-02-05 14:46 sink0k0

用别人的就要注明出处  回复  更多评论   

只有注册用户登录后才能发表评论。
点击这里给我发消息