导读:
一、 软件环境: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 [星期五, 8月 22nd, 2008 at 12:20 下午] Cacti. [RSS 2.0] feed.
4 Responses to “Cacti实现MSN报警”
Martian GuoSays:
8月 22nd, 2008 at 1:06 下午
从代码角度,考虑最好能把这些东西整合在一起
John.LvSays:
8月 22nd, 2008 at 2:53 下午
请不要忘记,cacti的用户要对SendMsg和shell脚本有执行的权限
freekeSays:
9月 1st, 2008 at 11:01 上午
好,非常好,几天不见,又多了这么多新文章!虽然我去年就配置好了cacti,平时也只是用来分析各个服务器的资源及性能情况,有这个功能,就比较好了!
freekeSays:
9月 1st, 2008 at 11:06 上午
对了,博主高人朋友,你的thold是什么版本呀?我的好像和你的文件内容不太一样!0.3.8我的版本
本文转自
http://www.hiadmin.com/cacti%e5%ae%9e%e7%8e%b0msn%e6%8a%a5%e8%ad%a6/
一、 软件环境: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接收报警信息了:如下所示
![](http://www.hiadmin.com/wp-content/uploads/2008/08/14-300x267.jpg)
下次更新Cacti实现短信报警,敬请期待
-Posted on [星期五, 8月 22nd, 2008 at 12:20 下午] Cacti. [RSS 2.0] feed.
4 Responses to “Cacti实现MSN报警”
Martian GuoSays:
8月 22nd, 2008 at 1:06 下午
从代码角度,考虑最好能把这些东西整合在一起
John.LvSays:
8月 22nd, 2008 at 2:53 下午
请不要忘记,cacti的用户要对SendMsg和shell脚本有执行的权限
freekeSays:
9月 1st, 2008 at 11:01 上午
好,非常好,几天不见,又多了这么多新文章!虽然我去年就配置好了cacti,平时也只是用来分析各个服务器的资源及性能情况,有这个功能,就比较好了!
freekeSays:
9月 1st, 2008 at 11:06 上午
对了,博主高人朋友,你的thold是什么版本呀?我的好像和你的文件内容不太一样!0.3.8我的版本
本文转自
http://www.hiadmin.com/cacti%e5%ae%9e%e7%8e%b0msn%e6%8a%a5%e8%ad%a6/