在Cacti上实现MSN报警机制

一、 软件环境:cacti(需Threshold插件),MSN机器人(SendMsg
三、 配置过程:
1.
启用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,会通过emailMSN同时发送报警
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=([email protected]) #
报警接收人 msn
sendMsg()
{
num=0
while [ $num -lt 1 ];
do
wget --post-data "[email protected]&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实现短信报警,敬请期待
 

你可能感兴趣的:(cacti,休闲,MSN,报警,监控服务器)