Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 2770 → Rev 2775

/web/acc/phpsysinfo/includes/ups/class.apcupsd.inc.php
0,0 → 1,148
<?php
/**
* Apcupsd class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.apcupsd.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting ups information from apcupsd program
*
* @category PHP
* @package PSI_UPS
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @author Artem Volk <artvolk@mail.ru>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Apcupsd extends UPS
{
/**
* internal storage for all gathered data
*
* @var array
*/
private $_output = array();
 
/**
* get all information from all configured ups in phpsysinfo.ini and store output in internal array
*/
public function __construct()
{
parent::__construct();
if (defined('PSI_UPS_APCUPSD_LIST') && is_string(PSI_UPS_APCUPSD_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_APCUPSD_LIST)) {
$upses = eval(PSI_UPS_APCUPSD_LIST);
} else {
$upses = array(PSI_UPS_APCUPSD_LIST);
}
foreach ($upses as $ups) {
CommonFunctions::executeProgram('apcaccess', 'status '.trim($ups), $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
} else { //use default if address and port not defined
CommonFunctions::executeProgram('apcaccess', 'status', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
}
 
/**
* parse the input and store data in resultset for xml generation
*
* @return Void
*/
private function _info()
{
foreach ($this->_output as $ups) {
 
$dev = new UPSDevice();
 
// General info
if (preg_match('/^UPSNAME\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setName(trim($data[1]));
}
if (preg_match('/^MODEL\s*:\s*(.*)$/m', $ups, $data)) {
$model = trim($data[1]);
if (preg_match('/^APCMODEL\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setModel($model.' ('.trim($data[1]).')');
} else {
$dev->setModel($model);
}
}
if (preg_match('/^UPSMODE\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setMode(trim($data[1]));
}
if (preg_match('/^STARTTIME\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setStartTime(trim($data[1]));
}
if (preg_match('/^STATUS\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setStatus(trim($data[1]));
}
if (preg_match('/^ITEMP\s*:\s*(.*)$/m', $ups, $data)) {
$temperatur = trim($data[1]);
if (($temperatur !== "-273.1 C") && ($temperatur !== "-273.1 C Internal")) {
$dev->setTemperatur($temperatur);
}
}
// Outages
if (preg_match('/^NUMXFERS\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setOutages(trim($data[1]));
}
if (preg_match('/^LASTXFER\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setLastOutage(trim($data[1]));
}
if (preg_match('/^XOFFBATT\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setLastOutageFinish(trim($data[1]));
}
// Line
if (preg_match('/^LINEV\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setLineVoltage(trim($data[1]));
}
if (preg_match('/^LINEFREQ\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setLineFrequency(trim($data[1]));
}
if (preg_match('/^LOADPCT\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setLoad(trim($data[1]));
}
// Battery
if (preg_match('/^BATTDATE\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setBatteryDate(trim($data[1]));
}
if (preg_match('/^BATTV\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setBatteryVoltage(trim($data[1]));
}
if (preg_match('/^BCHARGE\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setBatterCharge(trim($data[1]));
}
if (preg_match('/^TIMELEFT\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setTimeLeft(trim($data[1]));
}
$this->upsinfo->setUpsDevices($dev);
}
}
 
/**
* get the information
*
* @see PSI_Interface_UPS::build()
*
* @return Void
*/
public function build()
{
$this->_info();
}
}
/web/acc/phpsysinfo/includes/ups/class.nut.inc.php
0,0 → 1,142
<?php
/**
* Nut class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @author Artem Volk <artvolk@mail.ru>
* @author Anders Häggström <hagge@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.nut.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting ups information from upsc program
*
* @category PHP
* @package PSI_UPS
* @author Artem Volk <artvolk@mail.ru>
* @author Anders Häggström <hagge@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Nut extends UPS
{
/**
* internal storage for all gathered data
*
* @var array
*/
private $_output = array();
 
/**
* get all information from all configured ups and store output in internal array
*/
public function __construct()
{
parent::__construct();
if (defined('PSI_UPS_NUT_LIST') && is_string(PSI_UPS_NUT_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_NUT_LIST)) {
$upses = eval(PSI_UPS_NUT_LIST);
} else {
$upses = array(PSI_UPS_NUT_LIST);
}
foreach ($upses as $ups) {
CommonFunctions::executeProgram('upsc', '-l '.trim($ups), $output, PSI_DEBUG);
$ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
foreach ($ups_names as $ups_name) {
CommonFunctions::executeProgram('upsc', trim($ups_name).'@'.trim($ups), $temp, PSI_DEBUG);
if (! empty($temp)) {
$this->_output[trim($ups_name).'@'.trim($ups)] = $temp;
}
}
}
} else { //use default if address and port not defined
CommonFunctions::executeProgram('upsc', '-l', $output, PSI_DEBUG);
$ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
foreach ($ups_names as $ups_name) {
CommonFunctions::executeProgram('upsc', trim($ups_name), $temp, PSI_DEBUG);
if (! empty($temp)) {
$this->_output[trim($ups_name)] = $temp;
}
}
}
}
 
/**
* parse the input and store data in resultset for xml generation
*
* @return void
*/
private function _info()
{
if (! empty($this->_output)) {
foreach ($this->_output as $name => $value) {
$temp = preg_split("/\n/", $value, -1, PREG_SPLIT_NO_EMPTY);
$ups_data = array();
foreach ($temp as $valueTemp) {
$line = preg_split('/: /', $valueTemp, 2);
$ups_data[$line[0]] = isset($line[1]) ? trim($line[1]) : '';
}
$dev = new UPSDevice();
//General
$dev->setName($name);
if (isset($ups_data['ups.model'])) {
$dev->setModel($ups_data['ups.model']);
}
if (isset($ups_data['driver.name'])) {
$dev->setMode($ups_data['driver.name']);
}
if (isset($ups_data['ups.status'])) {
$dev->setStatus($ups_data['ups.status']);
}
 
//Line
if (isset($ups_data['input.voltage'])) {
$dev->setLineVoltage($ups_data['input.voltage']);
}
if (isset($ups_data['input.frequency'])) {
$dev->setLineFrequency($ups_data['input.frequency']);
}
if (isset($ups_data['ups.load'])) {
$dev->setLoad($ups_data['ups.load']);
}
 
//Battery
if (isset($ups_data['battery.voltage'])) {
$dev->setBatteryVoltage($ups_data['battery.voltage']);
}
if (isset($ups_data['battery.charge'])) {
$dev->setBatterCharge($ups_data['battery.charge']);
}
if (isset($ups_data['battery.runtime'])) {
$dev->setTimeLeft(round($ups_data['battery.runtime']/60, 2));
}
 
//Temperature
if (isset($ups_data['ups.temperature'])) {
$dev->setTemperatur($ups_data['ups.temperature']);
}
 
$this->upsinfo->setUpsDevices($dev);
}
}
}
 
/**
* get the information
*
* @see PSI_Interface_UPS::build()
*
* @return Void
*/
public function build()
{
$this->_info();
}
}
/web/acc/phpsysinfo/includes/ups/class.pmset.inc.php
0,0 → 1,96
<?php
/**
* Pmset class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @author Robert Pelletier <drizzt@menzonet.org>
* @copyright 2014 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.nut.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting ups information from pmset program
*
* @category PHP
* @package PSI_UPS
* @author Robert Pelletier <drizzt@menzonet.org>
* @copyright 2014 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Pmset extends UPS
{
/**
* internal storage for all gathered data
*
* @var array
*/
private $_output = array();
 
/**
* get all information from all configured ups and store output in internal array
*/
public function __construct()
{
parent::__construct();
$temp = "";
if (CommonFunctions::executeProgram('pmset', '-g batt', $temp) && !empty($temp)) {
$this->_output[] = $temp;
}
}
 
/**
* parse the input and store data in resultset for xml generation
*
* @return void
*/
private function _info()
{
if (empty($this->_output)) {
return;
}
$model = array();
$percCharge = array();
$lines = explode(PHP_EOL, implode($this->_output));
if (count($lines)>1) {
$model = explode('FW:', $lines[1]);
if (strpos($model[0], 'InternalBattery') === false) {
$dev = new UPSDevice();
$percCharge = explode(';', $lines[1]);
$dev->setName('UPS');
if ($model !== false) {
$dev->setModel(substr(trim($model[0]), 1));
}
if ($percCharge !== false) {
$dev->setBatterCharge(trim(substr($percCharge[0], -4, 3)));
$dev->setStatus(trim($percCharge[1]));
if (isset($percCharge[2])) {
$time = explode(':', $percCharge[2]);
$hours = $time[0];
$minutes = $hours*60+substr($time[1], 0, 2);
$dev->setTimeLeft($minutes);
}
}
$dev->setMode("pmset");
$this->upsinfo->setUpsDevices($dev);
}
}
}
 
/**
* get the information
*
* @see PSI_Interface_UPS::build()
*
* @return Void
*/
public function build()
{
$this->_info();
}
}
/web/acc/phpsysinfo/includes/ups/class.powersoftplus.inc.php
0,0 → 1,115
<?php
/**
* PowerSoftPlus class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2014 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.powersoftplus.inc.php 661 2014-06-13 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting ups information from powersoftplus program
*
* @category PHP
* @package PSI_UPS
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2014 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class PowerSoftPlus extends UPS
{
/**
* internal storage for all gathered data
*
* @var array
*/
private $_output = array();
 
/**
* get all information from all configured ups in phpsysinfo.ini and store output in internal array
*/
public function __construct()
{
parent::__construct();
CommonFunctions::executeProgram('powersoftplus', '-p', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
 
/**
* parse the input and store data in resultset for xml generation
*
* @return Void
*/
private function _info()
{
foreach ($this->_output as $ups) {
 
$dev = new UPSDevice();
 
// General info
$dev->setName("EVER");
$dev->setMode("PowerSoftPlus");
$maxpwr = 0;
$load = null;
if (preg_match('/^Identifier: UPS Model\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setModel(trim($data[1]));
if (preg_match('/\s(\d*)[^\d]*$/', trim($data[1]), $number)) {
$maxpwr=$number[1]*0.65;
}
}
if (preg_match('/^Current UPS state\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setStatus(trim($data[1]));
}
if (preg_match('/^Output load\s*:\s*(.*)\s\[\%\]$/m', $ups, $data)) {
$load = trim($data[1]);
}
//wrong Output load issue
if (($load == 0) && ($maxpwr != 0) && preg_match('/^Effective power\s*:\s*(.*)\s\[W\]$/m', $ups, $data)) {
$load = 100.0*trim($data[1])/$maxpwr;
}
if ($load != null) {
$dev->setLoad($load);
}
// Battery
if (preg_match('/^Battery voltage\s*:\s*(.*)\s\[Volt\]$/m', $ups, $data)) {
$dev->setBatteryVoltage(trim($data[1]));
}
if (preg_match('/^Battery state\s*:\s*(.*)$/m', $ups, $data)) {
if (preg_match('/^At full capacity$/', trim($data[1]))) {
$dev->setBatterCharge(100);
} elseif (preg_match('/^(Discharged)|(Depleted)$/', trim($data[1]))) {
$dev->setBatterCharge(0);
}
}
// Line
if (preg_match('/^Input voltage\s*:\s*(.*)\s\[Volt\]$/m', $ups, $data)) {
$dev->setLineVoltage(trim($data[1]));
}
if (preg_match('/^Input frequency\s*:\s*(.*)\s\[Hz\]$/m', $ups, $data)) {
$dev->setLineFrequency(trim($data[1]));
}
$this->upsinfo->setUpsDevices($dev);
}
}
 
/**
* get the information
*
* @see PSI_Interface_UPS::build()
*
* @return Void
*/
public function build()
{
$this->_info();
}
}
/web/acc/phpsysinfo/includes/ups/class.snmpups.inc.php
0,0 → 1,286
<?php
/**
* SNMPups class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.apcupsd.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting ups information from SNMPups program
*
* @category PHP
* @package PSI_UPS
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @author Artem Volk <artvolk@mail.ru>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class SNMPups extends UPS
{
/**
* internal storage for all gathered data
*
* @var array
*/
private $_output = array();
 
/**
* get all information from all configured ups in phpsysinfo.ini and store output in internal array
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_UPS_SNMPUPS_ACCESS)) {
case 'command':
if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) {
$upss = eval(PSI_UPS_SNMPUPS_LIST);
} else {
$upss = array(PSI_UPS_SNMPUPS_LIST);
}
foreach ($upss as $ups) {
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$ups." .1.3.6.1.4.1.318.1.1.1.1", $buffer, PSI_DEBUG);
if (strlen($buffer) > 0) {
$this->_output[$ups] = $buffer;
$buffer = "";
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$ups." .1.3.6.1.4.1.318.1.1.1.2", $buffer, PSI_DEBUG);
if (strlen($buffer) > 0) {
$this->_output[$ups] .= "\n".$buffer;
}
$buffer = "";
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$ups." .1.3.6.1.4.1.318.1.1.1.3", $buffer, PSI_DEBUG);
if (strlen($buffer) > 0) {
$this->_output[$ups] .= "\n".$buffer;
}
$buffer = "";
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$ups." .1.3.6.1.4.1.318.1.1.1.4", $buffer, PSI_DEBUG);
if (strlen($buffer) > 0) {
$this->_output[$ups] .= "\n".$buffer;
}
}
}
}
break;
case 'php-snmp':
if (!extension_loaded("snmp")) {
$this->error->addError("Requirements error", "SNMPups plugin requires the snmp extension to php in order to work properly");
break;
}
snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) {
$upss = eval(PSI_UPS_SNMPUPS_LIST);
} else {
$upss = array(PSI_UPS_SNMPUPS_LIST);
}
foreach ($upss as $ups) {
if (! PSI_DEBUG) {
restore_error_handler(); /* default error handler */
$old_err_rep = error_reporting();
error_reporting(E_ERROR); /* fatal errors only */
}
$bufferarr=snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.1", 1000000 * PSI_SNMP_TIMEOUT_INT, PSI_SNMP_RETRY_INT);
if (! PSI_DEBUG) {
error_reporting($old_err_rep); /* restore error level */
set_error_handler('errorHandlerPsi'); /* restore error handler */
}
if (! empty($bufferarr)) {
$buffer="";
foreach ($bufferarr as $id=>$string) {
$buffer .= $id." = ".$string."\n";
}
 
if (! PSI_DEBUG) {
restore_error_handler(); /* default error handler */
$old_err_rep = error_reporting();
error_reporting(E_ERROR); /* fatal errors only */
}
$bufferarr2=snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.2", 1000000 * PSI_SNMP_TIMEOUT_INT, PSI_SNMP_RETRY_INT);
$bufferarr3=snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.3", 1000000 * PSI_SNMP_TIMEOUT_INT, PSI_SNMP_RETRY_INT);
$bufferarr4=snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.4", 1000000 * PSI_SNMP_TIMEOUT_INT, PSI_SNMP_RETRY_INT);
if (! PSI_DEBUG) {
error_reporting($old_err_rep); /* restore error level */
set_error_handler('errorHandlerPsi'); /* restore error handler */
}
if (! empty($bufferarr2)) {
foreach ($bufferarr2 as $id=>$string) {
$buffer .= $id." = ".$string."\n";
}
if (! empty($bufferarr3)) {
foreach ($bufferarr3 as $id=>$string) {
$buffer .= $id." = ".$string."\n";
}
} }
if (! empty($bufferarr4)) {
foreach ($bufferarr4 as $id=>$string) {
$buffer .= $id." = ".$string."\n";
}
}
if (strlen(trim($buffer)) > 0) {
$this->_output[$ups] = $buffer;
}
}
}
}
break;
default:
$this->error->addError("switch(PSI_UPS_SNMPUPS_ACCESS)", "Bad SNMPups configuration in phpsysinfo.ini");
break;
}
}
 
/**
* parse the input and store data in resultset for xml generation
*
* @return Void
*/
private function _info()
{
if (empty($this->_output)) {
return;
}
foreach ($this->_output as $result) {
$dev = new UPSDevice();
$status = "";
$status2 = "";
$status3 = "";
$dev->setMode("SNMP");
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.1\.1\.2\.0 = STRING:\s(.*)/m', $result, $data)) {
$dev->setName(trim($data[1], "\" \r\t"));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.1\.1\.1\.0 = STRING:\s(.*)/m', $result, $data)) {
$dev->setModel(trim($data[1], "\" \r\t"));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.4\.1\.1\.0 = INTEGER:\s(.*)/m', $result, $data)) {
switch (trim($data[1])) {
case 1: $status = "Unknown";
break;
case 2: $status = "On Line";
break;
case 3: $status = "On Battery";
break;
case 4: $status = "On Smart Boost";
break;
case 5: $status = "Timed Sleeping";
break;
case 6: $status = "Software Bypass";
break;
case 7: $status = "Off";
break;
case 8: $status = "Rebooting";
break;
case 9: $status = "Switched Bypass";
break;
case 10:$status = "Hardware Failure Bypass";
break;
case 11:$status = "Sleeping Until Power Returns";
break;
case 12:$status = "On Smart Trim";
break;
default: $status = "Unknown state (".trim($data[1]).")";
break;
}
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.1\.1\.0 = INTEGER:\s(.*)/m', $result, $data)) {
$batstat = "";
switch (trim($data[1])) {
case 1: $batstat = "Battery Unknown";
break;
case 2: break;
case 3: $batstat = "Battery Low";
break;
default: $batstat = "Battery Unknown (".trim($data[1]).")";
break;
}
if ($batstat !== "") {
if ($status !== "") {
$status .= ", ".$batstat;
} else {
$status = $batstat;
}
}
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.2\.4\.0 = INTEGER:\s(.*)/m', $result, $data)) {
$batstat = "";
switch (trim($data[1])) {
case 1: break;
case 2: $batstat = "Replace Battery";
break;
default: $batstat = "Replace Battery (".trim($data[1]).")";
break;
}
if ($batstat !== "") {
if ($status !== "") {
$status .= ", ".$batstat;
} else {
$status = $batstat;
}
}
}
if ($status !== "") {
$dev->setStatus(trim($status));
}
 
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.3\.3\.1\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setLineVoltage(trim($data[1])/10);
} elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.3\.2\.1\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setLineVoltage(trim($data[1]));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.4\.3\.3\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setLoad(trim($data[1])/10);
} elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.4\.2\.3\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setLoad(trim($data[1]));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.3\.4\.0 = INTEGER:\s(.*)/m', $result, $data)) {
$dev->setBatteryVoltage(trim($data[1])/10);
} elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.2\.8\.0 = INTEGER:\s(.*)/m', $result, $data)) {
$dev->setBatteryVoltage(trim($data[1]));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.3\.1\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setBatterCharge(trim($data[1])/10);
} elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.2\.1\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setBatterCharge(trim($data[1]));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.2\.3\.0 = Timeticks:\s\((\d*)\)/m', $result, $data)) {
$dev->setTimeLeft(trim($data[1])/6000);
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.3\.2\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setTemperatur(trim($data[1])/10);
} elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.2\.2\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setTemperatur(trim($data[1]));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.1\.3\.0 = STRING:\s(.*)/m', $result, $data)) {
$dev->setBatteryDate(trim($data[1], "\" \r\t"));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.3\.3\.4\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setLineFrequency(trim($data[1])/10);
} elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.3\.2\.4\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setLineFrequency(trim($data[1]));
}
 
$this->upsinfo->setUpsDevices($dev);
}
}
 
/**
* get the information
*
* @see PSI_Interface_UPS::build()
*
* @return Void
*/
public function build()
{
$this->_info();
}
}
/web/acc/phpsysinfo/includes/ups/class.ups.inc.php
0,0 → 1,64
<?php
/**
* Basic UPS Class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.ups.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* Basic UPS functions for all UPS classes
*
* @category PHP
* @package PSI_UPS
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class UPS implements PSI_Interface_UPS
{
/**
* object for error handling
*
* @var PSI_Error
*/
public $error;
 
/**
* main object for ups information
*
* @var UPSInfo
*/
protected $upsinfo;
 
/**
* build the global Error object
*/
public function __construct()
{
$this->error = PSI_Error::singleton();
$this->upsinfo = new UPSInfo();
}
 
/**
* build and return the ups information
*
* @see PSI_Interface_UPS::getUPSInfo()
*
* @return UPSInfo
*/
final public function getUPSInfo()
{
$this->build();
 
return $this->upsinfo;
}
}