你好,游客 登录 注册 搜索
背景:
阅读新闻

Cacti及其相关插件的安装

[日期:2013-10-31] 来源:Linux社区  作者:pjp5945 [字体:大 中 小]

配置支持发送msn消息

[root@cacti software]# unzip sendMsg.zip

[root@cacti software]# mv sendMsg/ var/www/html/

 

[root@cacti software]# vim /var/www/html/cacti/plugins/thold/thold_functions.php

添加下面这两行

560 exec("echo $subject>>/var/www/html/cacti/plugins/thold/alert.log");

561 exec("sh /var/www/html/cacti/plugins/thold/sendmessage.sh");

 

编写个sendmessage.sh脚本,在/var/www/html/cacti/plugins/thold/这个目录下(实现自动发送)

[root@cacti software]# 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=(接收信息的帐号)

sendMsg()

{

num=0

while [ $num -lt 1 ];

do

wget ?post-data"sender=发送信息的帐号&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/null2>&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@cacti software]# tar -jxvf feition.tar.bz2

[root@cacti software]# mkdir -pv /var/www/html/sendsms/linuxso

[root@cacti software]# cp linuxso_20101113/* /lib/

[root@cacti software]# mv linuxso_20101113/* /var/www/html/sendsms/linuxso/

[root@cacti software]# vim /var/www/html/cacti/plugins/thold/thold_functions.php

添加这两行

562 exec("echo $subject>>/var/www/html/cacti/plugins/thold/alert.log");

563 exec("/var/www/html/cacti/plugins/thold/sendsms.sh");

 

[root@cacti software]# 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 notexist"

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@cacti thold]# chmod a+x send*

给新建的脚本添加可执行权限

 

vim /var/www/html/cacti/plugins/thold/alert.log

随便写点儿内容,当飞信程序执行的时候会自动删除里面的内容

可以新建alert.log以及sms.txt,其中在alert.log中添加一个内容。然后手工运行脚本进行测试,需要保证本机能正常接入互联网。

 

目前cacti的环境已经搭建完成,cacti的使用还需要好好学习……

linux
相关资讯       Cacti安装  Cacti插件 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款