分析家 发表于 2019-1-11 10:05:15

linux下Cacti网络监控警报

一、首先做邮件警告(本实验邮箱地址elevenzhu990@sina.cn):
在安装完setting插件后,可以看到多出来几项:
http://blog.运维网.com/attachment/201206/145415930.png
  1、首先发送一封测试邮件
http://blog.运维网.com/attachment/201206/145707967.png
保存;
2、在cacti服务器上设置sendmail:

# vim /etc/mail/local-host-names
添加两行(主机名和域名)
Eleven.localdomain
Localdomain

修改中继文件:
# vim /etc/mail/access

增加一行:
sina.cn                                 RELAY

# service sendmail restart

http://blog.运维网.com/attachment/201206/150030687.png
http://blog.运维网.com/attachment/201206/150102757.png
3、查看邮箱:
http://blog.运维网.com/attachment/201206/150233638.png
测试邮件成功。
想要用邮件发送警告还有做以下设置;
点击“setting”下的“Alerting/Thold”
http://blog.运维网.com/attachment/201206/150406408.png
http://blog.运维网.com/attachment/201206/150440784.png
http://blog.运维网.com/attachment/201206/150552396.png
4、下面做监控windows server 2003 c盘使用情况:
http://blog.运维网.com/attachment/201206/150703186.png
单击“console”下的“Thresholds”
http://blog.运维网.com/attachment/201206/150816634.png
http://blog.运维网.com/attachment/201206/151007917.png
监测c盘已使用的情况:
http://blog.运维网.com/attachment/201206/151111828.png
来设置当c盘空间使用高于2G低于1G是发送邮件来警告:
http://blog.运维网.com/attachment/201206/151300583.png
http://blog.运维网.com/attachment/201206/151342724.png
再次打开 “console”下的“Thresholds”
http://blog.运维网.com/attachment/201206/151458370.png
由下图可以看到,刚开始状态还是“OK“
http://blog.运维网.com/attachment/201206/151652557.png
等过5分钟后再来查看:
http://blog.运维网.com/attachment/201206/151821621.png
可以发现状态已变为“Alarm”
5、查看邮件:
http://blog.运维网.com/attachment/201206/151925906.png
  邮件警告已完成
二、MSN警告(MNS账号:elevenzhu1990@hotmail.com):
1、安装MNS应用sendMsg.zip
# unzip sendMsg.zip
# mv sendMsg /var/www/html/

2、首先测试MSN
在浏览器中输入http://192.168.101.50/sendMsg
http://blog.运维网.com/attachment/201206/152236859.png
http://blog.运维网.com/attachment/201206/152259638.png
3、查看MSN消息:
http://blog.运维网.com/attachment/201206/152510637.png
测试成功;

4、手工发送msn消息,修要做如下修改
# 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/这个目录下(实现自动发送)
# 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


# cd /var/www/html/cacti/plugins/thold/
# chmod a+x sendmessage.sh

# vim alert.log
内容为:
2222222222222222222

6、执行脚本:
# ./sendmessage.sh
date:2012-06-20-17:12
2222222222222


7、查看MSN消息:
http://blog.运维网.com/attachment/201206/153051322.png
至此以实现MSN监控警报;


三、实现飞信报警
1、下载最新版飞信机器人。
http://bbs.it-adv.net/viewthread.php?tid=1081&extra=page%3D1
根据情况下载,因为会经常更新。 下载两个一个是fetion程序,一个是Linux下的库包linuxso-0101113.tar.gz

# 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
# mkdir -pv /var/www/html/sendsms/linuxso
# cd 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
# cp * /var/www/html/sendsms/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");
# 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
# cd /var/www/html/cacti/plugins/thold/
# chmod a+x sendsms.sh
# ./sendsms.sh
图形验证码已经生成,文件名为:13419871890.jpg请识别后输入图形验证码:

可以看到生成验证码图片,图片在/var/www/html/sendsms/linuxso/目录下
# cd /var/www/html/sendsms/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、查看验证码:
http://blog.运维网.com/attachment/201206/153150787.png
# ./sendsms.sh
图形验证码已经生成,文件名为:13419871890.jpg请识别后输入图形验证码:
bmrb
您输入的识别码是:bmrb

# vim alert.log
内容为:
22222222222222

# ./sendsms.sh

3、查看飞信,可以看到收到了一些系统警告信息和刚才alert.log里的内容“222222222222”

至此飞信警告已完成;cacti监控已完成





页: [1]
查看完整版本: linux下Cacti网络监控警报