cacti0.8.7g监控速配+msn,2010版飞信报警
Cacti安装,MSN,飞信报警测试系统:RHEL 5.4 cacti版本:cacti-0.8.7g本次实验在关闭防火墙,selinux的情况下实验的。本次需要的所有软件下载地址:http://u.115.com/file/f180e8f0d61.安装cacti主程序首先安装以下程序包: # yum -y install httpd php php-mysql php-snmp mysql mysql-server perl-DBD-MySQL php-pdo net-snmp net-snmp-libs net-snmp-utils net-snmp-devel ruby ruby-devel使以下服务开机自启动。 # chkconfig mysqld on # chkconfig httpd on # chkconfig snmpd on修改 apache 配置文件 # vi /etc/httpd/conf/httpd.conf# 找到 AddType 添加如下二行AddType application/x-httpd-php.phpAddType application/x-httpd-php-source.phps#找到 DirectoryIndex index.html修改为:DirectoryIndexindex.phpindex.html启动 mysql 与 http 服务 #service mysqld start #service httpd start安装 rrdtool到rrdtool 网站:http://www.express.org/~wrl/rrdtool/ (找到最新版本即可)下载三个文件rrdtool-1.4.4-1.el5.wrl.i386.rpm rrdtool-ruby-1.4.4-1.el5.wrl.i386.rpm rrdtool-perl-1.4.4-1.el5.wrl.i386.rpm# rpm -ivh /usr/local/src/rrdtool-* 安装三个包修改系统中的 snmp 设置 #vi /etc/snmp/snmp.conf将com2secnotConfigUser default public改为:com2secnotConfigUser 127.0.0.1 public (这是监控本地,被监控主机设置,后续介绍)将accessnotConfigGroup “”any noauth exactsystemviewnone none改为:accessnotConfigGroup”"any noauth exact all nonenone#view all included.1 80将前面的 # 注释去掉。重新启动 snmp 服务 #service snmpd restart安装 cacti # tar xzvfcacti-0.8.7g.tar.gz # mv cacti-0.8.7g/ var/www/html/cacti # chmod 777 -R /var/www/html/cacti在Mysql中创建一个用于存储Cacti信息的数据库,数据库名称为cacti,新建一个数据库用户cacti ,设置密码为 cacti ,并赋予该用户对数据库cacti完全控制权限。导入/var/www/html/cacti目录中cacti.sql生成cacti数据库结构,然后编辑cacti的数据库配置文件。进入数据库 # mysqlMysql > CREATE DATABASE cacti;Mysql>insert into mysql.user(Host,User,Password) values(“localhost”,”cacti”,password(“cacti”));Mysql > flush privileges;Mysql > grant all privileges on cacti.* to cacti@localhost>Mysql > grant all privileges on cacti.* to cacti@127.0.0.1 identified by ‘cacti’;Mysql >flush privileges;Mysql > quit导数据进数据库 # mysql -ucacti -pcacti cacti < /var/www/html/cacti/cacti.sql修改 cacti 数据库配置文件 # vi /var/www/html/cacti/include/config.php修改成:$database_type= “ mysql ” ;$database_default = “cacti” ;$database_hostname = “ localhost ” ;$database_username = “cacti” ;$database_password = “cacti” ;加入一个计划任务,使得 cacti 每五分钟生成一个监控图表。 # crontab -e*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1打开浏览器,在浏览器地址栏中输入 http://IP/cacti,在第一次使用 cacti 时会显示cacti的安装指南,设置好一次后,以后就不会出现了。点击 “Next”由于是第一次安装,所以选择“New Install”,如果是升级安装,请选择升级安装,点击“Next”指定 rrdtool、 php、 snmp 工具的 Binary 文件路径,确保所有的路径都是显示 FOUND,而不是 NOT FOUND,点击 Finish 完成安装。Cacti 默认的用户名与密码是 admin,输入用户名与密码,点击 login为了安全的原因,第一次登录成功后,cacti 会强制要求你更改一个新的 password ,输入新密码并确认密码,点击 save ,进入 cacti 控制台界面.2.安装插件管理器Cacti版本:cacti 0.8.7g对应的PA 版本:PA 2.8要安装别的插件前,先要安装cacti的一个patch--Plugin Architecture,才能支持插件PA 2.8 = cacti 0.8.7g# wget http://mirror.cactiusers.org/downloads/plugins/cacti-plugin-0.8.7g-PA-v2.8.zip# unzip cacti-plugin-0.8.7g-PA-v2.8.zip# cp -R cacti-plugin-arch/* /var/www/html/cacti/# cd /var/www/html/cacti/# mysql -ucacti -pcacti cacti /var/www/html/cacti/plugins/thold/alert.log");exec("sh /var/www/html/cacti/plugins/thold/sendmessage.sh");保存退出3.然后编写个sendmessage.sh脚本,在/var/www/html/cacti/plugins/thold/这个目录下脚本内容===============================================================================#!/bin/shecho `echo -n "date:"&&date +%Y-%m-%d-%H:%M` >> /var/www/html/sendMsg/msn.txt.1cat /var/www/html/cacti/plugins/thold/alert.log >>/var/www/html/sendMsg/msn.txt.1now=`date +%Y-%m-%d-%H:%M`SA=(test)msnaddr=(pingsun2010@hotmail.com)sendMsg(){num=0while [ $num -lt 1 ];dowget —post-data "sender=pingsun2012@hotmail.com&password=123456&recipient=${1}&message=${2}" http://127.0.0.1/sendMsg/index.php -O /var/www/html/sendMsg/index.php.1 >/dev/null 2>&1if [ -f /var/www/html/sendMsg/index.php.1 ]; thenif cat /var/www/html/sendMsg/index.php.1 |grep -i successfully >/dev/null 2>&1;thennum=1elif cat /var/www/html/sendMsg/index.php.1 |grep -i "The user appears to be offline" >/dev/null 2>&1;thennum=1echo "The user is offline."exit 0elif cat /var/www/html/sendMsg/index.php.1 |grep -i "Something went wrong trying to connect to the server" >/dev/null 2>&1;thennum=1echo "MSN server is online."exit 0elsenum=0firm -f /var/www/html/sendMsg/index.php.1elsenum=0fidone}mv /var/www/html/sendMsg/msn.txt /var/www/html/sendMsg/bak/msn$now.txt -f 1>/dev/null 2>&1mv /var/www/html/sendMsg/msn.txt.1 /var/www/html/sendMsg/msn.txt -f 1>/dev/null 2>&1rm /var/www/html/cacti/plugins/thold/alert.log -f 1>/dev/null 2>&1for i in 0doif cat /var/www/html/sendMsg/msn.txt ; thenmessages=`cat /var/www/html/sendMsg/msn.txt `sendMsg "${msnaddr[$i]}" "$messages"elsecontinuefidone===========================================================然后保存退出。(发送和接受者必须互为好友)4.手动运行sendmessage.sh这个脚本,如果没有问题,应该可以收到消息。4.飞信报警功能实现1.下载最新版飞信机器人。http://bbs.it-adv.net/viewthread.php?tid=1081&extra=page%3D1根据情况下载,因为会经常更新。 下载两个一个是fetion程序,一个是Linux下的库包linuxso-20101113.tar.gz2.飞信机器人放置位置Cd /var/www/htmlMkdir sendsmsCp linuxso_20101113 /var/www/html/sendsms/linuxsoCp fetion /var/www/html/sendsms/linuxso/fetionChmod 777 -R/var/www/html/sendsms/linuxso搜thold_mail找到文件中的第一个这一句 : if (trim($alert_emails) != "") thold_mail($alert_emails, '', $subject, $msg, $file_array);然后下面添加exec("echo $subject >>/var/www/html/cacti/plugins/thold/alert.log");exec("/var/www/html/cacti/plugins/thold/sendsms.sh");编写sendsms.sh脚本,内容如下:=========================================================#!/bin/sh#send sms by fetion#Write by pingsun2010@hotmail.comif [ ! -e "/var/www/html/cacti/plugins/thold/alert.log" ];thenecho "Usage:alert.log does not exist"exitfiif [ -n "`cat /var/www/html/cacti/plugins/thold/alert.log`" ]; thenadmin="150382XXXX"echo "sms $admin "`cat /var/www/html/cacti/plugins/thold/alert.log` >>/var/www/html/cacti/plugins/thold/sms.txtecho "exit" >> /var/www/html/cacti/plugins/thold/sms.txtelseecho "Usage:no alert"exitfiif [ -n "`cat /var/www/html/cacti/plugins/thold/sms.txt`" ] ; thenLD_LIBRARY_PATH=/var/www/html/sendsms/linuxso /var/www/html/sendsms/linuxso/fetion --mobile=15803826990 --pwd=xxx --to=$admin --file-utf8=/var/www/html/cacti/plugins/thold/sms.txtrm -f /var/www/html/cacti/plugins/thold/sms.txt 1>/dev/null 2>&1rm -f /var/www/html/cacti/plugins/thold/alert.log 1>/dev/null 2>&1elseecho "Usgae:no message to send"exitfi============================================================保存,退出。测试一下。可以新建alert.log以及sms.txt,其中在alert.log中添加一个内容。然后运行脚本./sendsms.sh会返回以下结果,表示成功。 同时对方收到短信。# ./sendsms.sh图形验证码已经生成,文件名为:15803826990.jpg请识别后输入图形验证码:Nm8p #一般第一次会让你输入验证码。这个图片,在你的fetion的目录下。您输入的识别码是:nm8pSIP-C/4.0 280 Send SMS OKT: sip:759885962@fetion.com.cn;p=9283I: 3Q: 1 ML: 115D: Mon, 22 Nov 2010 15:28:45 GMTXI: 516723D0200B5C60F8747A8E9B4CFF55#
页:
[1]