天天看点

cacti实现短信报警v1.1

制作:高进波

时间:2010-3-8

主题:Cacti-飞信客户端发送免费报警短信

cacti是一个非常好的流量监控与报警软件,还能对很多应用进行监控,如lighttp,nginx,mysql,memcached等

环境:

centos 5.4 x86_64

cacti 0.8.7e

1.安装最新版飞信

#在安装飞信之前需要在/usr/lib目录下加上libACE库文件,以便使飞信能够正常使用

[root@localhost src]# tar zxvf library_linux.tar.gz

[root@localhost src]# mv libACE* libcrypto.so.0.9.8 libssl.so.0.9.8  /usr/lib

#正式安装飞信

[root@localhost src]# tar zxvf fetion20090406003-linux.tar.gz

[root@localhost src]# mv install /usr/local/fetion

[root@localhost src]# chmod -R 755 /usr/local/fetion

[root@localhost src]# chown -R nagios:nagios /usr/local/fetion

#移动服务器更新,需要更新软件

[root@localhost src]# tar zxvf fetion20091117-linux.tar.gz

[root@localhost src]# cp fx/* /usr/local/fetion

[root@localhost src]# vi /etc/ld.so.conf

include ld.so.conf.d/*.conf

/usr/local/fetion      #增加目录

[root@localhost src]# ldconfig

[root@localhost src]#/usr/local/fetion/fetion –mobile=151***** –pwd=*** –to=151***** –msg-utf8="test" –debug

[root@localhost src]#/usr/local/fetion/fetion   ##帮助

[root@localhost src]#cp /usr/local/fetion/fetion /usr/bin/

2.修改thold函数

vi thold_functions.php

function thold_mail($to, $from, $subject, $message, $filename, $headers = ”) {

global $config;

include_once($config["base_path"] . "/plugins/settings/include/mailer.php");

//change for hugwww

exec("echo $subject >>/www/web/cacti/plugins/thold/alter.log");

exec("/www/web/cacti/plugins/thold/sendsms.sh");

//change end

3.编写发送短信的脚本

#!/bin/sh

#send sms by fetion

#Write by hugwww

if [ ! -e "/www/web/cacti/plugins/thold/alter.log" ];then #判断alter.log是否存在

echo "Usage:alter.log does not exist"

exit

fi

if [ -n "`cat /www/web/cacti/plugins/thold/alter.log`" ]; then #判断alter.log是否有报警信息

admin="13724506486,13724506486"  #短信接收人,需在你飞信的好友列表中

/usr/local/fetion/fetion –mobile=13724506486 –pwd=password –to=$admin –file-utf8=/www/web/cacti/plugins/thold/alter.log

rm -f /www/web/cacti/plugins/thold/alter.log 1>/dev/null 2>&1

else

echo "Usage:no alter"

4.修改权限

chmod +x sendsms.sh

chown -R apache:apache *

完成!

附飞信安装文件

<a href="http://u.115.com/file/f4ca2ce55b">http://u.115.com/file/f4ca2ce55b linux-sms飞信.rar</a>

-