cacti 實現靈活短信報警方法

公司的extmail postfix 和監控服務器都放在一塊兒,問題就出來了,之前均可以用sendmail 發,如今默認的發送郵件方式不能用了。查了一下午的文檔終於找到了方法:



1. 修改/var/www/cacti/plugins/thold/thold_functions.php

加入紅色部分:

function thold_mail($to, $from, $subject, $message, $filename, $headers = '') {
        global $config;php

        include_once($config['base_path'] . '/plugins/settings/include/mailer.php');
         file_put_contents('/var/www/cacti/plugins/thold/alert.log', $subject);
               exec("echo $subject >>/var/www/cacti/plugins/thold/alert.log");
               exec("date +%D/%T  >> /var/www/cacti/plugins/thold/alert.log");
               exec("sh /tets/duanxin.sh");
vim

        include_once($config['base_path'] . '/plugins/thold/setup.php');

保存退出



vim /test/duanxin.sh
if [ ! -e "/var/www/cacti/plugins/thold/alert.log" ];then
echo "Usage:alter.log does not exist"
elif [ -n "`cat /var/www/cacti/plugins/thold/alert.log`" ]; then
echo `cat /var/www/cacti/plugins/thold/alert.log`|mail -s "warring" alex@dog.com
echo >/var/www/cacti/plugins/thold/alert.log
fi


總體思路
先將cacti  的警告輸出到一個文件alert.log去,並執行腳本。
腳本就負責把alert.log的記錄發到郵件或經過飛信發到郵箱或手機上
最好清空alert.log服務器

發送飛信的腳本,只需替換髮去郵件的那一句。
echo `cat /var/www/cacti/plugins/thold/alert.log`|
fetion --mobile=13XXXXXX --pwd=XXXXXXX --to=136XXXXXXX --msg-type=1 --msg-ide

相關文章
相關標籤/搜索