From 5ab3fb16e8f42dbf981266e0b786537a7029688a Mon Sep 17 00:00:00 2001 From: jim-p Date: Wed, 28 Dec 2016 13:51:08 -0500 Subject: Add a function to format and return plain text output showing the gateway status, for use by a shell script and status.php. Ticket #7046 --- src/etc/inc/gwlb.inc | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src') diff --git a/src/etc/inc/gwlb.inc b/src/etc/inc/gwlb.inc index 743fe58..6421170 100644 --- a/src/etc/inc/gwlb.inc +++ b/src/etc/inc/gwlb.inc @@ -506,6 +506,49 @@ function return_gateways_status($byname = false) { return($status); } +function return_gateways_status_text($byname = false, $brief = false) { + $gwstat = return_gateways_status($byname); + $output = ""; + $widths = array(); + $col_sep = 2; + if ($brief) { + $collist = array('status' => "Status"); + } else { + $collist = array('monitorip' => "Monitor", + 'srcip' => "Source", + 'delay' => "Delay", + 'stddev' => "StdDev", + 'loss' => "Loss", + 'status' => "Status"); + } + foreach ($gwstat as $gw) { + foreach ($gw as $gwdidx => $gwdata) { + if (strlen($gwdata) > $widths[$gwdidx]) { + $widths[$gwdidx] = strlen($gwdata); + } + } + } + + $output .= str_pad("Name", $widths['name'] + $col_sep, " ", STR_PAD_RIGHT); + foreach ($collist as $hdrcol => $hdrdesc) { + if (strlen($hdrdesc) > $widths[$hdrcol]) { + $widths[$hdrcol] = strlen($hdrdesc); + } + $output .= str_pad($hdrdesc, $widths[$hdrcol] + $col_sep, " ", (substr($hdrcol, -2, 2) == "ip") ? STR_PAD_RIGHT : STR_PAD_LEFT); + } + $output .= "\n"; + + foreach ($gwstat as $idx => $gw) { + $output .= str_pad($gw['name'], $widths['name'] + $col_sep, " ", STR_PAD_RIGHT); + foreach (array_keys($collist) as $col) { + $output .= str_pad($gw[$col], $widths[$col] + $col_sep, " ", (substr($col, -2, 2) == "ip") ? STR_PAD_RIGHT : STR_PAD_LEFT); + } + $output .= "\n"; + } + + return $output; +} + /* Return all configured gateways on the system */ function return_gateways_array($disabled = false, $localhost = false, $inactive = false) { global $config, $g; -- cgit v1.1