【描述】
网上有很多提示cacti的短信报警,但用起来都感觉不怎样,故而自己觉得亲自修改cacti的源码来实现短信报警机制。实现方式很简单,通过触发URL来实现手机短信报警。不过短信发送需要收取费用,采用了第三方的短信接口。好了,废话不多说,看具体实现方式吧。
【实现方式】
老规矩,按照settings(V0.5)和thold(V0.4.2)这两个插件。这里就不在详细描述了,之前以前介绍过了,不清楚的朋友可以看下我之前写的博文。
第一步:打开plugins\settings\setup.php
修改:
$tabs['mail'] = 'Mail / Mobile';
在$temp数组下增加如下代码:
"settings_mobile_header" => array( "friendly_name" => "Mobile Options", "method" => "spacer", ), "settings_mobile_number" => array( "friendly_name" => "Mobile Number", "description" => "This is the China Mobile Number that the dead host notifications will be sent to.", "method" => "textbox", "max_length" => 255, ), |
到此setup.php修改完成,打开web 界面可以看到如下:
第二步:将内容发送到手机上,具体操作如下:
打开plugins\thold\thold_functions.php
修改thold_mail 这个函数,大约在1350行,在下面这段代码前加入以下代码
if ($Mailer->send($text) == false) {
print 'ERROR: ' . $Mailer->error() . "\n";
return $Mailer->error();
}
return ''; |
加入的代码为:
//发送短信
preg_match("/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/",$subject,$ip);
preg_match('/-(.*)]/',$subject,$content);
$flag = stristr($subject,'normal');
$content = str_replace('-','',str_replace('','',$content[0]));
if ($flag) {
$content = $ip[0] . $content . ' is OK';
} else {
$content = $ip[0] . $content . ' has problem';
}
thold_mms($content); |
将发送到手机上的短信内容做了处理。大家可以根据自己的实际情况做修改
这下面最主要的就是thold_mms这个函数了,将这个函数添加到thold_mail 函数下
代码如下:
/* mms */
function thold_mms($content) {
$number = db_fetch_row("SELECT value FROM settings WHERE name = 'settings_mobile_number'");
$mobile_string = $number['value'];
$mms_content = iconv("UTF-8","GB2312",$content);
$API_Endpoint="http://service.winic.org/sys_port/gateway/";
$nvpStr ="id=jiunile&pwd=jiunile&to=".$mobile_string."&content=".urlencode($mms_content)."&time=";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpStr);
$response = curl_exec($ch);
if(curl_errno($ch)){
$curl_error_no >=curl_errno($ch) ;
$curl_error_msg>=curl_error($ch);
}else{
curl_close($ch);
}
return $response;
} |
$nvpStr来自http://winic.org提供。


![[转]常见的nginx的配置选项](http://www.jiunile.com/wp-content/themes/xupeng/images/random/8.jpg)






最新评论
如何建立自己的特征码呢? 我
怎么修改啊,帮帮忙啊,,,,
你好,我照您的方法做了之后,
可否请教,要如何的调整呢?
拜读……
您这个是是2003的服务器
安装上以后 发现运行了 直接
有点意思,不错!
你QQ号多少?我是智生道顾问
请问你是怎么修改的啊?为什么