{ ... } ## The parameters are those described above in the "target default" section ## plus the "description" parameter. ## the
should be IPv4 or IPv6 address (not hostname!) EOD; /* add static routes for each gateway with their monitor IP */ if(is_array($gateways_arr)) { foreach($gateways_arr as $gateway) { if($gateway['monitor'] == "") { $gateway['monitor'] = $gateway['gateway']; } $apingerconfig .= "target \"{$gateway['monitor']}\" {\n"; $apingerconfig .= " description \"{$gateway['name']}\"\n"; $apingerconfig .= "}\n"; $apingerconfig .= "\n"; if($gateway['monitor'] == $gateway['gateway']) { /* if the gateway is the same as the monitor we do not add a * route as this will break the routing table */ continue; } else { mwexec("/sbin/route delete -host " . escapeshellarg($gateway['monitor'])); mwexec("/sbin/route add -host " . escapeshellarg($gateway['monitor']) . " " . escapeshellarg($gateway['gateway'])); } } } fwrite($fd, $apingerconfig); fclose($fd); if(!is_process_running("apinger")) { if (is_dir("{$g['tmp_path']}")) chmod("{$g['tmp_path']}", 01777); if (is_dir("{$g['vardb_path']}/rrd")) chgrp("{$g['vardb_path']}/rrd", "nobody"); /* start a new apinger process */ mwexec_bg("/usr/local/sbin/apinger -c {$g['varetc_path']}/apinger.conf"); } return 0; } /* return the status of the apinger targets as a array */ function return_gateways_status() { global $config; global $g; $gateways_arr = return_gateways_array(); $apingerstatus = array(); if(is_readable("{$g['tmp_path']}/apinger.status")) $apingerstatus = file("{$g['tmp_path']}/apinger.status"); $status = array(); foreach($apingerstatus as $line) { $fields = explode(":", $line); switch($fields[0]) { case "Target": $target = trim($fields[1]); $status[$target] = array(); $status[$target]['monitor'] = $target; foreach($gateways_arr as $gateway) { if($gateway['monitor'] == "$target") { $status[$target]['gateway'] = $gateway['gateway']; $status[$target]['interface'] = $gateway['interface']; } } break; case "Description": $status[$target]['name'] = trim($fields[1]); break; case "Last reply received": $status[$target]['lastcheck'] = trim($fields[1]) .":". trim($fields[2]) .":". trim($fields[3]); break; case "Average delay": $status[$target]['delay'] = trim($fields[1]); break; case "Average packet loss": $status[$target]['loss'] = trim($fields[1]); break; case "Active alarms": $status[$target]['status'] = trim($fields[1]); break; } } return($status); } function return_gateways_array() { global $config; global $g; $gateways_arr = array(); /* Loop through all interfaces with a gateway and add it to a array */ $iflist = get_interface_list(); foreach($iflist as $ifname => $if ) { if(interface_has_gateway($ifname)) { $gateway = array(); $friendly = convert_real_interface_to_friendly_interface_name($ifname); $gateway['gateway'] = get_interface_gateway($ifname); /* Loopback for dynamic interfaces without a IP */ if(!is_ipaddr($gateway['gateway'])) { $gateway['gateway'] = "127.0.0.2"; } /* do not add dynamic gateways if it is also found in the gateways array */ if(is_array($config['gateways']['gateway_item'])) { foreach($config['gateways']['gateway_item'] as $gateway_item) { if($gateway_item['gateway'] == $gateway['gateway']) continue 2; } } $gateway['interface'] = $ifname; $descr = convert_friendly_interface_to_friendly_descr($friendly); /* FIXME: somehow retrieve a proper monitor IP? */ $gateway['monitor'] = $gateway['gateway']; $gateway['name'] = "{$friendly}"; $gateway['descr'] = "Interface {$descr} Gateway"; $gateway['modifier'] = "readonly"; $gateways_arr[] = $gateway; } } /* tack on all the hard defined gateways as well */ if(is_array($config['gateways']['gateway_item'])) { foreach($config['gateways']['gateway_item'] as $gateway) { if($gateway['monitor'] == "") { $gateway['monitor'] = $gateway['gateway']; } $gateway['modifier'] = "writeable"; $gateways_arr[] = $gateway; } } return($gateways_arr); } ?>