(主机=Host=Device)
背景:默认情况下Cacti的Down机邮件报警功能只能设置一个统一的接受地址,不够人性化。特是对于集团性质的企业,通常不同的主机是由不同的人员来负责的,因此,为每主机定义不同的邮件接收地址就很有必要。
环境:Cacti 0.8.7g Monitor1.2.1 Thold 0.4.1
Setp1: 给cacti.host表增加一个字段`alertMail`
ALTER TABLE host ADD laertmail varchar(200) default ” not null AFTER monitor_text;
Setp2: 修改脚本
$fields_host_edit3['alertMail'] = array( "method" => "textbox", "friendly_name" => "Alert Email", "description" => "This is the email address that will be sent when this host is reported as down.", "value" => "|arg1:alertMail|", "max_length" => "250", );
找到monitor_api_device_save()方法,在return $save;一行的上面,增加如下代码
if (isset($_POST['alertMail'])) $save['alertMail'] = form_input_validate($_POST['alertMail'], 'alertMail', '', true, 3); else $save['alertMail'] = form_input_validate('', 'alertMail', '', true, 3);
公司换了Lotus邮件服务器,更换后不能任意设置“From Email Address”,导致Cacti Thold不能正常发送报警邮件,提示“554 Sender address not allowed for this authenticated session”。
修改
查找
if ($from == '') { if (isset($_SERVER['HOSTNAME'])) { $from = 'Cacti@' . $_SERVER['HOSTNAME']; } else { $from = 'Cacti@cactiusers.org'; } }
修改为,即指定Settings->Mail/DNS->Emailing Options->From Email Address中填写的邮件地址
if ($from == '') { $from = read_config_option('settings_from_email'); }
加入了64位与32位环境的判断(ip2long),更新了计算方法。
<?php /* * Leon * http://nerrsoft.com * leon@nerrsoft.com * 2011-04-11 */ class ipInfo{ var $address; var $netbits; public function getIpInfo($ipStr){ list($this->address, $this->netbits) = explode('/', $ipStr); $info['long']['mask'] = $this->netmask(); $info['ip']['mask'] = long2ip($info['long']['mask']); $info['long']['net'] = $this->network(); $info['ip']['net'] = long2ip($info['long']['net']); $info['long']['begin'] = $info['long']['net'] + 1; $info['ip']['begin'] = long2ip($info['long']['begin']); $info['long']['end'] = abs($info['long']['mask']) + $info['long']['begin'] - 3; $info['ip']['end'] = long2ip($info['long']['end']); $info['long']['broacast'] = $this->broadcast(); $info['ip']['broacast'] = long2ip($info['long']['broacast']); $info['count'] = $info['long']['broacast'] - $info['long']['net'] - 1; return $info; } // Return the netmask function netmask(){ $mask = $this->check6432('255.255.255.255'); return $mask << (32 - $this->netbits); } // Return the network that the address sits in function network(){ $ip = $this->check6432($this->address); return ($ip & $this->netmask()); } // Return the broadcast that the address sits in function broadcast(){ return ($this->network() | (~$this->netmask())); } // Return the inverse mask of the netmask function inverse(){ $mask = $this->check6432('255.255.255.255'); return (long2ip(~($mask << (32 - $this->netbits)))); } // function check6432($ip){ if(PHP_INT_MAX==2147483647){ $mask = ip2long($ip); }else{ list(, $mask) = unpack('l', pack('l', ip2long($ip))); } return $mask; } } ?>
Comments