Cacti安裝插件:email,msn,fetion報警(轉載)

Cacti版本:cacti 0.8.7g
對應的PA 版本:PA 2.8
要安裝別的插件前,先要安裝cacti的一個patch--Plugin Architecture,才能支持插件
PA 2.8 = cacti 0.8.7g
[root@station1~]# wget http://mirror.cactiusers.org/downloads/plugins/cacti-plugin-0.8.7g-PA-v2.8.zip
[root@station1~]# unzip cacti-plugin-0.8.7g-PA-v2.8.zip
[root@station1~]# cp -R cacti-plugin-arch/* /var/www/html/cacti/
[root@station1~]# cd /var/www/html/cacti/
[root@station1 cacti]# mysql -ucacti -pcacti cacti <pa.sql
[root@station1 cacti]# patch -p1 -N <cacti-plugin-0.8.7g-PA-v2.8.diff
[root@station1 cacti]# vi /var/www/html/cacti/include/config.php
/* Default database settings*/
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
$database_port = "3306";
$url_path = “/cacti/”;
之後可能會出現禁止訪問的警告
最終確定是selinux的問題。可以使用chcon -R –reference /var/www/html /var/www/html/cacti
也可以關閉selinux,重啓就OK了。
授權admin用戶"plugin Management":
登錄後,Utilities–User Management–admin—Realm Permissions,選中“Plugin Management",Save。
安裝monitor、thold、settings 插件
[root@station1~]# wget http://docs.cacti.net/_media/plugin:monitor-latest.tgz
[root@station1 ~]# wget http://docs.cacti.net/_media/plugin:thold-latest.tgz
[root@station1~]# wget http://docs.cacti.net/_media/plugin:settings-latest.tgz
[root@station1 ~]# tar zxvf monitor-latest.tgz
[root@station1 ~]# tar zxvf settings-latest.tgz
[root@station1 ~]# tar zxvf thold-latest.tgz
[root@station1 ~]# mv monitor-0.9/ /var/www/cacti/plugins/monitor
[root@station1 ~]# mv settings-0.6/ /var/www/cacti/plugins/settings
[root@station1 ~]# mv thold-0.41/ /var/www/cacti/plugins/thold
現在去安裝,見下圖:

注意: 1.官方文檔說要修改/var/www/html/cacti/include/global.php  裏面的內容。我試驗後發現,修改後反而不能找到插件。不修改即可找到插件。 2.在安裝thold是,可能會出現 You are missing a dependency for thold, please install the 'Settings' plugin. 這樣的警告。只需要先安裝settings插件就OK。 3.MSN報警 1.去下載 (SendMsg)下載地址: http://downloads.fanatic.net.nz/dev/php/sendMsg.zip 然後解壓,放在目錄/var/www/html/sendMsg 然後通過web訪問,輸入sender和rcpiter,都能收到信息,那麼說明正常。 見圖:

2.修改cacti插件thold目錄下的thold_functions.php
我這裏是/var/www/html/cacti/plugins/thold
搜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("sh /var/www/html/cacti/plugins/thold/sendmessage.sh");
保存退出
3.然後編寫個sendmessage.sh腳本,在/var/www/html/cacti/plugins/thold/這個目錄下
腳本內容
===============================================================================
#!/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=([email protected])
sendMsg()
{
num=0
while [ $num -lt 1 ];
do
wget —post-data "[email protected]&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>&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
===========================================================
然後保存退出。(發送和接受者必須互爲好友)
4.手動運行sendmessage.sh這個腳本,如果沒有問題,應該可以收到消息。
4.飛信報警功能實現
1.下載最新版飛信機器人。
http://bbs.it-adv.net/viewthread.php?tid=1081&extra=page%3D1
根據情況下載,因爲會經常更新。 下載兩個一個是fetion程序,一個是Linux下的庫包linuxso-20101113.tar.gz
2.飛信機器人放置位置
Cd /var/www/html
Mkdir sendsms
Cp linuxso_20101113 /var/www/html/sendsms/linuxso
Cp fetion /var/www/html/sendsms/linuxso/fetion
Chmod 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 [email protected]
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="150382XXXX"
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=158038XXX90 --pwd=123xxx --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
=====================================================================
保存,退出。測試一下。
可以新建alert.log以及sms.txt,其中在alert.log中添加一個內容。
然後運行腳本
./sendsms.sh
會返回以下結果,表示成功。 同時對方收到短信。
[root@station1 thold]# ./sendsms.sh
圖形驗證碼已經生成,文件名爲:15803826990.jpg請識別後輸入圖形驗證碼:
Nm8p     #一般第一次會讓你輸入驗證碼。這個圖片,在你的fetion的目錄下。
您輸入的識別碼是:nm8p
SIP-C/4.0 280 Send SMS OK
T: sip:[email protected];p=9283
I: 3
Q: 1 M
L: 115
D: Mon, 22 Nov 2010 15:28:45 GMT
XI: 516723D0200B5C60F8747A8E9B4CFF55

OK,成功發送飛信,此時你的手機便可以接收到飛信。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章