From c2af9e1e4ae0a51a14efd9b3b9ace3e28fd3e92b Mon Sep 17 00:00:00 2001 From: Ryan Wagoner Date: Tue, 20 Feb 2007 16:05:15 +0000 Subject: -inform user when service is not running -inform user of stale data when connection lost -split data into two tables --- packages/nut/status_nut.php | 59 +++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 18 deletions(-) (limited to 'packages') diff --git a/packages/nut/status_nut.php b/packages/nut/status_nut.php index 7bbba4c8..fc28f59d 100644 --- a/packages/nut/status_nut.php +++ b/packages/nut/status_nut.php @@ -34,12 +34,23 @@ $nut_config = $config['installedpackages']['nut']['config'][0]; /* functions */ +function tblopen () { + print(''."\n"); +} + +function tblclose () { + print("
\n"); +} + function tblrow ($name, $value, $symbol = null) { if(!$value) return; if($symbol == '°') $value = sprintf("%.1f", $value); + if($symbol == 'Hz') + $value = sprintf("%d", $value); + print(<< {$name} @@ -127,30 +138,38 @@ include("head.inc");
- 0) { - if($nut_config['monitor'] == 'local') { - tblrow('Monitoring:','Local UPS'); - $handle = popen("upsc {$nut_config['name']}@localhost","r"); - } elseif($nut_config['monitor'] == 'remote') { - tblrow('Monitoring:','Remote UPS'); - $handle = popen("upsc {$nut_config['remotename']}@{$nut_config['remoteaddr']}","r"); - } + tblopen(); + + $running = ((int)exec('pgrep upsmon | wc -l') > 0) ? true : false; + + if($nut_config['monitor'] == 'local') { + tblrow('Monitoring:','Local UPS'); + $cmd = "upsc {$nut_config['name']}@localhost"; + } else { + tblrow('Monitoring:','Remote UPS'); + $cmd = "upsc {$nut_config['remotename']}@{$nut_config['remoteaddr']}"; } + if($running) + $handle = popen($cmd, 'r'); + else + tblrow('ERROR:','NUT is enabled, however the service is not running!'); + if($handle) { $read = fread($handle, 4096); pclose($handle); - /* parse upsc into array */ - $read = explode("\n", $read); + $lines = explode("\n", $read); $ups = array(); - foreach($read as $line) { + foreach($lines as $line) { $line = explode(':', $line); $ups[$line[0]] = trim($line[1]); } + if(count($lines) == 1) + tblrow('ERROR:', 'Data stale!'); + tblrow('Model:', $ups['ups.model']); $status = explode(' ', $ups['ups.status']); @@ -162,7 +181,7 @@ include("head.inc"); break; case 'OFF': $disp_status .= 'Off Line'; - break; + break; case 'OL': $disp_status .= 'On Line'; break; @@ -186,7 +205,7 @@ include("head.inc"); break; case 'CAL': $disp_status .= 'Calibration'; - break; + break; default: $disp_status .= $condition; break; @@ -196,16 +215,20 @@ include("head.inc"); tblrowbar('Load:', $ups['ups.load'], '%', '100-80', '79-60', '59-0'); tblrowbar('Battery Charge:', $ups['battery.charge'], '%', '0-29' ,'30-79', '80-100'); + + tblclose(); + tblopen(); + + tblrow('Runtime Remaining:', $ups['battery.runtime'], ' seconds'); tblrow('Battery Voltage:', $ups['battery.voltage'], 'V'); tblrow('Input Voltage:', $ups['input.voltage'], 'V'); + tblrow('Input Frequency:', $ups['input.frequency'], 'Hz'); tblrow('Output Voltage:', $ups['output.voltage'], 'V'); tblrow('Temperature:', $ups['ups.temperature'], '°'); - } else { - /* display error */ - tblrow('ERROR:', 'Can\'t parse data from upsc'); } + + tblclose(); ?> -
-- cgit v1.2.3