公司的extmail postfix 和监控服务器都放在一起,问题就出来了,以前都可以用sendmail 发,现在默认的发送邮件方式不能用了。查了一下午的文档终于找到了方法:
1. 修改/var/www/cacti/plugins/thold/thold_functions.php
加入红色部分:
function thold_mail($to, $from, $subject, $message, $filename, $headers = '') {
global $config;
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");
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-
转载于:https://blog.51cto.com/dogdogcom/530819