diff options
author | jim-p <jimp@pfsense.org> | 2010-12-14 10:42:38 -0500 |
---|---|---|
committer | jim-p <jimp@pfsense.org> | 2010-12-14 10:42:38 -0500 |
commit | a776c720e6757fc12222643665f749c2e6d05c1c (patch) | |
tree | ab27afc84cc2b50237b010e1a72e112374296bec | |
parent | 5ca559d227855d9293a1d194e6981b8275e043ae (diff) | |
download | pfsense-a776c720e6757fc12222643665f749c2e6d05c1c.zip pfsense-a776c720e6757fc12222643665f749c2e6d05c1c.tar.gz |
Move some lb status parsing functions to a common area so they can be reused by the widget.
-rw-r--r-- | etc/inc/vslb.inc | 66 | ||||
-rwxr-xr-x | usr/local/www/status_lb_pool.php | 17 | ||||
-rwxr-xr-x | usr/local/www/status_lb_vs.php | 61 |
3 files changed, 71 insertions, 73 deletions
diff --git a/etc/inc/vslb.inc b/etc/inc/vslb.inc index 3985337..82aeb06 100644 --- a/etc/inc/vslb.inc +++ b/etc/inc/vslb.inc @@ -283,4 +283,70 @@ function relayd_configure() { } +function get_lb_redirects() { +/* +# relayctl show summary +Id Type Name Avlblty Status +1 redirect testvs2 active +5 table test2:80 active (3 hosts up) +11 host 192.168.1.2 91.55% up +10 host 192.168.1.3 100.00% up +9 host 192.168.1.4 88.73% up +3 table test:80 active (1 hosts up) +7 host 192.168.1.2 66.20% down +6 host 192.168.1.3 97.18% up +0 redirect testvs active +3 table test:80 active (1 hosts up) +7 host 192.168.1.2 66.20% down +6 host 192.168.1.3 97.18% up +4 table testvs-sitedown:80 active (1 hosts up) +8 host 192.168.1.4 84.51% up +# relayctl show redirects +Id Type Name Avlblty Status +1 redirect testvs2 active +0 redirect testvs active +# relayctl show redirects +Id Type Name Avlblty Status +1 redirect testvs2 active + total: 2 sessions + last: 2/60s 2/h 2/d sessions + average: 1/60s 0/h 0/d sessions +0 redirect testvs active +*/ + $rdr_a = array(); + exec('/usr/local/sbin/relayctl show redirects 2>&1', $rdr_a); + $vs = array(); + for ($i = 0; isset($rdr_a[$i]); $i++) { + $line = $rdr_a[$i]; + if (preg_match("/^[0-9]+/", $line)) { + $regs = array(); + if($x = preg_match("/^[0-9]+\s+redirect\s+([^\s]+)\s+([^\s]+)/", $line, $regs)) { + $vs[trim($regs[1])] = array(); + $vs[trim($regs[1])]['status'] = trim($regs[2]); + } + } + } + return $vs; +} + +function get_lb_summary() { + $relayctl = array(); + exec('/usr/local/sbin/relayctl show summary 2>&1', $relayctl); + $relay_hosts=Array(); + foreach( (array) $relayctl as $line) { + $t=split("\t", $line); + switch (trim($t[1])) { + case "table": + $curpool=trim($t[2]); + break; + case "host": + $curhost=trim($t[2]); + $relay_hosts[$curpool][$curhost]['avail']=trim($t[3]); + $relay_hosts[$curpool][$curhost]['state']=trim($t[4]); + break; + } + } + return $relay_hosts; +} + ?>
\ No newline at end of file diff --git a/usr/local/www/status_lb_pool.php b/usr/local/www/status_lb_pool.php index 16f474b..b7d79ce 100755 --- a/usr/local/www/status_lb_pool.php +++ b/usr/local/www/status_lb_pool.php @@ -43,6 +43,7 @@ require_once("guiconfig.inc"); require_once("functions.inc"); require_once("filter.inc"); require_once("shaper.inc"); +require_once("vslb.inc"); if (!is_array($config['load_balancer']['lbpool'])) { $config['load_balancer']['lbpool'] = array(); @@ -61,21 +62,7 @@ $year = date("Y"); $pgtitle = array(gettext("Status"),gettext("Load Balancer"),gettext("Pool")); include("head.inc"); -$relayctl=split("\n", shell_exec("/usr/local/sbin/relayctl show summary")); -$relay_hosts=Array(); -foreach( (array) $relayctl as $line) { - $t=split("\t", $line); - switch (trim($t[1])) { - case "table": - $curpool=trim($t[2]); - break; - case "host": - $curhost=trim($t[2]); - $relay_hosts[$curpool][$curhost]['avail']=trim($t[3]); - $relay_hosts[$curpool][$curhost]['state']=trim($t[4]); - break; - } -} +$relay_hosts = get_lb_summary(); if ($_POST) { if ($_POST['apply']) { diff --git a/usr/local/www/status_lb_vs.php b/usr/local/www/status_lb_vs.php index 7495e37..33ad6e3 100755 --- a/usr/local/www/status_lb_vs.php +++ b/usr/local/www/status_lb_vs.php @@ -40,7 +40,8 @@ ##|*MATCH=status_lb_vs.php* ##|-PRIV -require("guiconfig.inc"); +require_once("guiconfig.inc"); +require_once("vslb.inc"); if (!is_array($config['load_balancer']['lbpool'])) { $config['load_balancer']['lbpool'] = array(); @@ -50,63 +51,7 @@ if (!is_array($config['load_balancer']['virtual_server'])) { } $a_vs = &$config['load_balancer']['virtual_server']; $a_pool = &$config['load_balancer']['lbpool']; - - - -// # relayctl show summary -// Id Type Name Avlblty Status -// 1 redirect testvs2 active -// 5 table test2:80 active (3 hosts up) -// 11 host 192.168.1.2 91.55% up -// 10 host 192.168.1.3 100.00% up -// 9 host 192.168.1.4 88.73% up -// 3 table test:80 active (1 hosts up) -// 7 host 192.168.1.2 66.20% down -// 6 host 192.168.1.3 97.18% up -// 0 redirect testvs active -// 3 table test:80 active (1 hosts up) -// 7 host 192.168.1.2 66.20% down -// 6 host 192.168.1.3 97.18% up -// 4 table testvs-sitedown:80 active (1 hosts up) -// 8 host 192.168.1.4 84.51% up -// # relayctl show redirects -// Id Type Name Avlblty Status -// 1 redirect testvs2 active -// 0 redirect testvs active -// # relayctl show redirects -// Id Type Name Avlblty Status -// 1 redirect testvs2 active -// total: 2 sessions -// last: 2/60s 2/h 2/d sessions -// average: 1/60s 0/h 0/d sessions -// 0 redirect testvs active - -$redirects_a = array(); -exec('/usr/local/sbin/relayctl show redirects 2>&1', $redirects_a); -$summary_a = array(); -exec('/usr/local/sbin/relayctl show summary 2>&1', $summary_a); -$rdr_a = parse_redirects($redirects_a); -//$server_a = parse_summary($summary_a, parse_redirects($redirects_a)); - -function parse_redirects($rdr_a) { - $vs = array(); - for ($i = 0; isset($rdr_a[$i]); $i++) { - $line = $rdr_a[$i]; - if (preg_match("/^[0-9]+/", $line)) { - $regs = array(); - if($x = preg_match("/^[0-9]+\s+redirect\s+([^\s]+)\s+([^\s]+)/", $line, $regs)) { - $vs[trim($regs[1])] = array(); - $vs[trim($regs[1])]['status'] = trim($regs[2]); - } - } - } - return $vs; -} - -function parse_summary($summary, $rdrs_a) { - $server_a = array(); - return $server_a; -} +$rdr_a = get_lb_redirects(); $pgtitle = array(gettext("Status"),gettext("Load Balancer"),gettext("Virtual Server")); include("head.inc"); |