0) ? true : false; if($nut_config['monitor'] == 'local') { tblrow('Monitoring:','Local UPS'); $cmd = "upsc {$nut_config['name']}@localhost"; } elseif($nut_config['monitor'] == 'remote') { tblrow('Monitoring:','Remote UPS'); $cmd = "upsc {$nut_config['remotename']}@{$nut_config['remoteaddr']}"; } elseif($nut_config['monitor'] == 'snmp') { tblrow('Monitoring:','SNMP UPS'); $cmd = "upsc {$nut_config['name']}@localhost"; } if($running) $handle = popen($cmd, 'r'); elseif($nut_config['monitor'] == 'snmp') tblrow('ERROR:','NUT is enabled, however the service is not running! The SNMP UPS may be unreachable.'); else tblrow('ERROR:','NUT is enabled, however the service is not running!'); if($handle) { $read = fread($handle, 4096); pclose($handle); $lines = explode("\n", $read); $ups = array(); 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']); foreach($status as $condition) { if($disp_status) $disp_status .= ', '; switch ($condition) { case 'WAIT': $disp_status .= 'Waiting'; break; case 'OFF': $disp_status .= 'Off Line'; break; case 'OL': $disp_status .= 'On Line'; break; case 'OB': $disp_status .= 'On Battery'; break; case 'TRIM': $disp_status .= 'SmartTrim'; break; case 'BOOST': $disp_status .= 'SmartBoost'; break; case 'OVER': $disp_status .= 'Overload'; break; case 'LB': $disp_status .= 'Battery Low'; break; case 'RB': $disp_status .= 'Replace Battery'; break; case 'CAL': $disp_status .= 'Calibration'; break; default: $disp_status .= $condition; break; } } tblrow('Status:', $disp_status); 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'], '°'); } tblclose(); ?> |