一、首先做邮件警告本实验邮箱地址elevenzhu990@sina.cn):
在安装完setting插件后,可以看到多出来几项:

 

linux下Cacti网络监控警报_警告

1、首先发送一封测试邮件

 

linux下Cacti网络监控警报_警告_02

 

保存;
2、在cacti服务器上设置sendmail:
 
[root@Eleven ~]# vim /etc/mail/local-host-names
添加两行(主机名和域名)
Eleven.localdomain
Localdomain
 
修改中继文件:
[root@Eleven ~]# vim /etc/mail/access
 
增加一行:
sina.cn                                 RELAY
 
[root@Eleven ~]# service sendmail restart
 

 

linux下Cacti网络监控警报_警告_03

 

linux下Cacti网络监控警报_cacti_04

 

3、查看邮箱:

 

linux下Cacti网络监控警报_cacti_05

 

测试邮件成功。
想要用邮件发送警告还有做以下设置;
点击“setting”下的“Alerting/Thold”

 

linux下Cacti网络监控警报_警告_06

 

linux下Cacti网络监控警报_cacti_07

 

linux下Cacti网络监控警报_警告_08

 

4、下面做监控windows server 2003 c盘使用情况:

 

linux下Cacti网络监控警报_警告_09

 

单击“console”下的“Thresholds”

 

linux下Cacti网络监控警报_cacti_10

 

 

linux下Cacti网络监控警报_cacti_11

 

监测c盘已使用的情况:

 

linux下Cacti网络监控警报_警告_12

 

来设置当c盘空间使用高于2G低于1G是发送邮件来警告:

 

linux下Cacti网络监控警报_警告_13

 

linux下Cacti网络监控警报_警告_14

 

再次打开 “console”下的“Thresholds”

 

linux下Cacti网络监控警报_cacti_15

 

由下图可以看到,刚开始状态还是“OK“

 

linux下Cacti网络监控警报_cacti_16

 

等过5分钟后再来查看:

 

linux下Cacti网络监控警报_警告_17

 

可以发现状态已变为“Alarm”
5、查看邮件:

 

linux下Cacti网络监控警报_cacti_18

 

邮件警告已完成

 

二、MSN警告(MNS账号:elevenzhu1990@hotmail.com):
1、安装MNS应用sendMsg.zip
[root@Eleven cacti]# unzip sendMsg.zip
[root@Eleven cacti]# mv sendMsg /var/www/html/
 
2、首先测试MSN
在浏览器中输入http://192.168.101.50/sendMsg

 

linux下Cacti网络监控警报_警告_19

 

linux下Cacti网络监控警报_cacti_20

 

3、查看MSN消息

 

linux下Cacti网络监控警报_cacti_21

 

测试成功;
 
4、手工发送msn消息,修要做如下修改
[root@Eleven cacti]# vim /var/www/html/cacti/plugins/thold/thold_functions.php
增加560、561行:
560    exec("echo $subject >>/var/www/html/cacti/plugins/thold/alert.log");
561    exec("sh /var/www/html/cacti/plugins/thold/sendmessage.sh");
 
5、然后编写个sendmessage.sh脚本,在/var/www/html/cacti/plugins/thold/这个目录下(实现自动发送)
[root@Eleven cacti]# vim /var/www/html/cacti/plugins/thold/sendmessage.sh
内容为:
 
#!/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/alert.log >>/var/www/html/sendMsg/msn.txt.1
now=`date +%Y-%m-%d-%H:%M`
SA=(test)
msnaddr=(接受者msn账号名称)
sendMsg()
{
num=0
while [ $num -lt 1 ];
do
wget —post-data "sender=发送者msn用户名&password=密码&recipient=${1}&message=${2}" http://127.0.0.1/sendMsg/index.php -O /var/www/html/sendMsg/index.php.1 >/dev/null 2>&1
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
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
echo "MSN server is online."
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/alert.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
 
 
[root@Eleven cacti]# cd /var/www/html/cacti/plugins/thold/
[root@Eleven thold]# chmod a+x sendmessage.sh
 
[root@Eleven thold]# vim alert.log
内容为:
2222222222222222222
 
6、执行脚本:
[root@Eleven thold]# ./sendmessage.sh
date:2012-06-20-17:12
2222222222222
 
 
7、查看MSN消息:

 

linux下Cacti网络监控警报_cacti_22

 

至此以实现MSN监控警报;
 
 
三、实现飞信报警
1、下载最新版飞信机器人。
http://bbs.it-adv.net/viewthread.php?tid=1081&extra=page%3D1
根据情况下载,因为会经常更新。 下载两个一个是fetion程序,一个是Linux下的库包linuxso-0101113.tar.gz
 
[root@Eleven cacti]# tar jxvf feition.tar.bz2
linuxso_20101113/
linuxso_20101113/fetion
linuxso_20101113/libssl.so.4
linuxso_20101113/libcrypto.so.4
linuxso_20101113/libACE_SSL-5.7.2.so
linuxso_20101113/libACE-5.7.2.so
fetion
解压后形成两个目录:
fetion和linuxso_20101113
[root@Eleven cacti]# mkdir -pv /var/www/html/sendsms/linuxso
[root@Eleven cacti]# cd linuxso_20101113/
[root@Eleven linuxso_20101113]# ll
total 13220
-rwxrwxrwx 1 1000 1000   470097 Nov 22 2010 fetion
-rwxrwxrwx 1 1000 1000 11317349 Nov 22 2010 libACE-5.7.2.so
-rwxrwxrwx 1 1000 1000   548099 Nov 22 2010 libACE_SSL-5.7.2.so
-rwxrwxrwx 1 1000 1000   945120 Nov 22 2010 libcrypto.so.4
-rwxrwxrwx 1 1000 1000   213600 Nov 22 2010 libssl.so.4
[root@Eleven linuxso_20101113]# cp * /var/www/html/sendsms/linuxso/
[root@Eleven linuxso]# vim /var/www/html/cacti/plugins/thold/thold_functions.php
增加562、563行:
562    exec("echo $subject >>/var/www/html/cacti/plugins/thold/alert.log");
563    exec("/var/www/html/cacti/plugins/thold/sendsms.sh");
[root@Eleven linuxso]# vim /var/www/html/cacti/plugins/thold/sendsms.sh
内容为:
#!/bin/sh
#send sms by fetion
#Write by pingsun2010@hotmail.com
if [ ! -e "/var/www/html/cacti/plugins/thold/alert.log" ];then
echo "Usage:alert.log does not exist"
exit
fi
if [ -n "`cat /var/www/html/cacti/plugins/thold/alert.log`" ]; then
admin="接收者号码"
echo "sms $admin "`cat /var/www/html/cacti/plugins/thold/alert.log` >>/var/www/html/cacti/plugins/thold/sms.txt
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
LD_LIBRARY_PATH=/var/www/html/sendsms/linuxso /var/www/html/sendsms/linuxso/fetion --mobile=发送者号码 --pwd=密码 --to=$admin --file-utf8=/var/www/html/cacti/plugins/thold/sms.txt
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
[root@Eleven linuxso]# cd /var/www/html/cacti/plugins/thold/
[root@Eleven thold]# chmod a+x sendsms.sh
[root@Eleven thold]# ./sendsms.sh
图形验证码已经生成,文件名为:13419871890.jpg请识别后输入图形验证码:
 
可以看到生成验证码图片,图片在/var/www/html/sendsms/linuxso/目录下
[root@Eleven thold]# cd /var/www/html/sendsms/linuxso/
[root@Eleven linuxso]# ll
total 13228
-rw-r--r-- 1 root root      932 Jun 20 19:09 13419871890.cache
-rw-r--r-- 1 root root     1686 Jun 20 19:14 13419871890.jpg
-rwxr-xr-x 1 root root   470097 Jun 20 18:55 fetion
-rwxr-xr-x 1 root root 11317349 Jun 20 18:55 libACE-5.7.2.so
-rwxr-xr-x 1 root root   548099 Jun 20 18:55 libACE_SSL-5.7.2.so
-rwxr-xr-x 1 root root   945120 Jun 20 18:55 libcrypto.so.4
-rwxr-xr-x 1 root root   213600 Jun 20 18:55 libssl.so.4
 
2、查看验证码:

 

linux下Cacti网络监控警报_警告_23

 

[root@Eleven thold]# ./sendsms.sh
图形验证码已经生成,文件名为:13419871890.jpg请识别后输入图形验证码:
bmrb
您输入的识别码是:bmrb
 
[root@Eleven thold]# vim alert.log
内容为:
22222222222222
 
[root@Eleven thold]# ./sendsms.sh
 
3、查看飞信,可以看到收到了一些系统警告信息和刚才alert.log里的内容“222222222222”
 
至此飞信警告已完成;cacti监控已完成