您的位置:首页 > 运维架构

在Cacti上实现MSN报警机制

2009-09-15 15:36 253 查看
一、 软件环境: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");
[align=left]备注:本人的thold安装在/var/www/html/cacti/plugins/thold/目录中,如果注释掉thold_mail,只通过MSN发送报警。不注释掉thold_mail,会通过email和MSN同时发送报警[/align]
[align=left]thold-functions.php生成的alter.log范例如下:[/align]
[align=left]192.168.1.207 - Used Space - G: Label: [hdd_percent] is still above threshold of 85 with 99[/align]
[align=left]编写脚本sendmessage.sh自动调用SendMsg发送报警[/align]
#!/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接收报警信息了:如下所示




[align=left]下次更新Cacti实现短信报警,敬请期待[/align]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息