From cdcea13f940daf60d500db2f6a17a22ef1c79d71 Mon Sep 17 00:00:00 2001 From: Seth Mos Date: Tue, 8 Jul 2008 21:19:34 +0000 Subject: Move gateway status and monitoring over to gwlb.inc. Still needs a return_gateway_status_by_name(); --- etc/inc/gwlb.inc | 261 +++++++++++++++++++++++++++++++--------------- etc/inc/pfsense-utils.inc | 181 +------------------------------- 2 files changed, 180 insertions(+), 262 deletions(-) (limited to 'etc') diff --git a/etc/inc/gwlb.inc b/etc/inc/gwlb.inc index b0d4bd7..faa4399 100644 --- a/etc/inc/gwlb.inc +++ b/etc/inc/gwlb.inc @@ -1,7 +1,7 @@ /dev/null 2>&1"); - mwexec("/sbin/route add -host {$lbsvr_split[1]} 127.0.0.1 1> /dev/null 2>&1"); - } else { - mwexec("/sbin/route delete -host {$lbsvr_split[1]} 1>/dev/null 2>&1"); - mwexec("/sbin/route add -host {$lbsvr_split[1]} {$gateway} 1> /dev/null 2>&1"); - } - } - $slbdconf .= "\t:service-port=666:\\\n"; - $slbdconf .= "\t:method=round-robin:\\\n"; - $slbdconf .= "\t:services={$svrcnt}:\\\n"; - $slbdconf .= $svrtxt; - - $slbdconf .= "\t:ping:\n"; - - $should_start=1; - } - } - - if($should_start == 1) { - fwrite($fd, $slbdconf); - fclose($fd); - mwexec("/usr/bin/killall -9 slbd"); - sleep(2); - /* startup slbd pointing it's config at /var/etc/slbd.conf with a polling interval of 5 seconds */ - mwexec("/usr/local/sbin/slbd -c{$g['varetc_path']}/slbd.conf -r5000"); - } else { - mwexec("/usr/bin/killall -9 slbd"); - fclose($fd); - } +/* add static routes for monitor IP addresse + * creates monitoring configuration file + */ +function setup_gateways_monitor() { + global $config; + global $g; + + /* kill apinger process */ + exec("/usr/bin/killall apinger"); + $fd = fopen("{$g['varetc_path']}/apinger.conf", "w"); + $apingerconfig = << { ... } +## 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($config['gateways']['gateway_item'])) { + foreach($config['gateways']['gateway_item'] 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); + + sleep(3); + if(!is_process_running("apinger")) { + if (is_dir("{$g['vardb_path']}/rrd")) + chown("{$g['vardb_path']}/rrd", "nobody"); + 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; + + $apingerstatus = array(); + if(is_readable("{$g['tmp_path']}/apinger.status")) + $apingerstatus = file("{$g['tmp_path']}/apinger.status"); + + foreach($apingerstatus as $line) { + $fields = explode(":", $line); + switch($fields[0]) { + case "Target": + $target = trim($fields[1]); + $status[$target] = array(); + $status[$target]['monitor'] = $target; + foreach($config['gateways']['gateway_item'] 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); } -?> \ No newline at end of file +?> diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index 40bdd6e..b68d5fe 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -4049,183 +4049,4 @@ $span_begin = ""; } } -/* add static routes for monitor IP addresse - * creates monitoring configuration file - */ -function setup_gateways_monitor() { - global $config; - global $g; - - /* kill apinger process */ - exec("/usr/bin/killall apinger"); - $fd = fopen("{$g['varetc_path']}/apinger.conf", "w"); - $apingerconfig = << { ... } -## 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($config['gateways']['gateway_item'])) { - foreach($config['gateways']['gateway_item'] 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); - - sleep(3); - if(!is_process_running("apinger")) { - if (is_dir("{$g['vardb_path']}/rrd")) - chown("{$g['vardb_path']}/rrd", "nobody"); - 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; - - $apingerstatus = array(); - if(is_readable("{$g['tmp_path']}/apinger.status")) - $apingerstatus = file("{$g['tmp_path']}/apinger.status"); - - foreach($apingerstatus as $line) { - $fields = explode(":", $line); - switch($fields[0]) { - case "Target": - $target = trim($fields[1]); - $status[$target] = array(); - $status[$target]['monitor'] = $target; - foreach($config['gateways']['gateway_item'] 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); -} - -?> \ No newline at end of file +?> -- cgit v1.1