* Mon May 12 2025 Brian Read <brianr@koozali.org> 11.0.0-1.sme

- Adding SM2 panel [SME: 13004]
- Upgrade to phpsysinfo 3.4.4
- Add code to delete inline styles and add css to make it look better.
- version saved / built uses the static version, which means no drops downs and choices.
This commit is contained in:
2025-05-14 16:14:01 +01:00
parent 80b1da5fa5
commit c8ce77259d
952 changed files with 51341 additions and 28699 deletions

View File

@@ -8,7 +8,7 @@
* @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
* @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
*/
@@ -20,7 +20,7 @@
* @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
* @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
*/
@@ -29,7 +29,7 @@ class Apcupsd extends UPS
/**
* internal storage for all gathered data
*
* @var Array
* @var array
*/
private $_output = array();
@@ -39,22 +39,53 @@ class Apcupsd extends UPS
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);
if (!defined('PSI_UPS_APCUPSD_ACCESS')) {
define('PSI_UPS_APCUPSD_ACCESS', false);
}
switch (strtolower(PSI_UPS_APCUPSD_ACCESS)) {
case 'data':
if (defined('PSI_UPS_APCUPSD_LIST') && is_string(PSI_UPS_APCUPSD_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_APCUPSD_LIST)) {
$upss = eval(PSI_UPS_APCUPSD_LIST);
} else {
$upss = array(PSI_UPS_APCUPSD_LIST);
}
} else {
$upses = array(PSI_UPS_APCUPSD_LIST);
$upss = array('UPS');
}
foreach ($upses as $ups) {
CommonFunctions::executeProgram('apcaccess', 'status '.trim($ups), $temp);
$un = 0;
foreach ($upss as $ups) {
$temp = "";
CommonFunctions::rftsdata("upsapcupsd{$un}.tmp", $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
$un++;
}
} else { //use default if address and port not defined
CommonFunctions::executeProgram('apcaccess', 'status', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
break;
default:
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) {
$temp = "";
CommonFunctions::executeProgram('apcaccess', 'status '.trim($ups), $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
} else { //use default if address and port not defined
if (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT')) {
CommonFunctions::executeProgram('apcaccess', 'status', $temp);
} else {
CommonFunctions::executeProgram('apcaccess', 'status '.PSI_EMU_HOSTNAME, $temp);
}
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
}
}
@@ -62,7 +93,7 @@ class Apcupsd extends UPS
/**
* parse the input and store data in resultset for xml generation
*
* @return Void
* @return void
*/
private function _info()
{
@@ -75,7 +106,7 @@ class Apcupsd extends UPS
$dev->setName(trim($data[1]));
}
if (preg_match('/^MODEL\s*:\s*(.*)$/m', $ups, $data)) {
$model=trim($data[1]);
$model = trim($data[1]);
if (preg_match('/^APCMODEL\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setModel($model.' ('.trim($data[1]).')');
} else {
@@ -92,7 +123,10 @@ class Apcupsd extends UPS
$dev->setStatus(trim($data[1]));
}
if (preg_match('/^ITEMP\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setTemperatur(trim($data[1]));
$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)) {
@@ -136,7 +170,7 @@ class Apcupsd extends UPS
*
* @see PSI_Interface_UPS::build()
*
* @return Void
* @return void
*/
public function build()
{

View File

@@ -9,7 +9,7 @@
* @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
* @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
*/
@@ -21,7 +21,7 @@
* @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
* @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
*/
@@ -40,29 +40,62 @@ class Nut extends UPS
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);
if (!defined('PSI_UPS_NUT_ACCESS')) {
define('PSI_UPS_NUT_ACCESS', false);
}
switch (strtolower(PSI_UPS_NUT_ACCESS)) {
case 'data':
if (defined('PSI_UPS_NUT_LIST') && is_string(PSI_UPS_NUT_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_NUT_LIST)) {
$upss = eval(PSI_UPS_NUT_LIST);
} else {
$upss = array(PSI_UPS_NUT_LIST);
}
} else {
$upses = array(PSI_UPS_NUT_LIST);
$upss = array('UPS');
}
foreach ($upses as $ups) {
CommonFunctions::executeProgram('upsc', '-l '.trim($ups), $output);
$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);
if (! empty($temp)) {
$this->_output[trim($ups_name).'@'.trim($ups)] = $temp;
$un = 0;
foreach ($upss as $ups) {
$temp = "";
CommonFunctions::rftsdata("upsnut{$un}.tmp", $temp);
if (! empty($temp)) {
$this->_output[$ups] = $temp;
}
$un++;
}
break;
default:
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) {
$upsname = trim($ups_name).'@'.trim($ups);
$temp = "";
CommonFunctions::executeProgram('upsc', $upsname, $temp, PSI_DEBUG);
if (! empty($temp)) {
$this->_output[$upsname] = $temp;
}
}
}
}
} else { //use default if address and port not defined
CommonFunctions::executeProgram('upsc', '-l', $output);
$ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
foreach ($ups_names as $ups_name) {
CommonFunctions::executeProgram('upsc', trim($ups_name), $temp);
if (! empty($temp)) {
$this->_output[trim($ups_name)] = $temp;
} else { //use default if address and port not defined
if (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT')) {
CommonFunctions::executeProgram('upsc', '-l', $output, PSI_DEBUG);
} else {
CommonFunctions::executeProgram('upsc', '-l '.PSI_EMU_HOSTNAME, $output, PSI_DEBUG);
}
$ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
foreach ($ups_names as $ups_name) {
$temp = "";
CommonFunctions::executeProgram('upsc', trim($ups_name), $temp, PSI_DEBUG);
if (! empty($temp)) {
$this->_output[trim($ups_name)] = $temp;
}
}
}
}
@@ -71,16 +104,16 @@ class Nut extends UPS
/**
* parse the input and store data in resultset for xml generation
*
* @return array
* @return void
*/
private function _info()
{
if (! empty($this->_output)) {
foreach ($this->_output as $name=>$value) {
foreach ($this->_output as $name => $value) {
$temp = preg_split("/\n/", $value, -1, PREG_SPLIT_NO_EMPTY);
$ups_data = array();
foreach ($temp as $value) {
$line = preg_split('/: /', $value, 2);
foreach ($temp as $valueTemp) {
$line = preg_split('/: /', $valueTemp, 2);
$ups_data[$line[0]] = isset($line[1]) ? trim($line[1]) : '';
}
$dev = new UPSDevice();
@@ -95,6 +128,9 @@ class Nut extends UPS
if (isset($ups_data['ups.status'])) {
$dev->setStatus($ups_data['ups.status']);
}
if (isset($ups_data['ups.beeper.status'])) {
$dev->setBeeperStatus($ups_data['ups.beeper.status']);
}
//Line
if (isset($ups_data['input.voltage'])) {
@@ -133,7 +169,7 @@ class Nut extends UPS
*
* @see PSI_Interface_UPS::build()
*
* @return Void
* @return void
*/
public function build()
{

View File

@@ -8,7 +8,7 @@
* @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
* @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
*/
@@ -19,7 +19,7 @@
* @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
* @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
*/
@@ -38,41 +38,60 @@ class Pmset extends UPS
public function __construct()
{
parent::__construct();
CommonFunctions::executeProgram('pmset', '-g batt', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
if (defined('PSI_UPS_PMSET_ACCESS') && (strtolower(trim(PSI_UPS_PMSET_ACCESS))==='data')) {
if (CommonFunctions::rftsdata('upspmset.tmp', $temp)) {
$this->_output[] = $temp;
}
} elseif (PSI_OS == 'Darwin') {
if (CommonFunctions::executeProgram('pmset', '-g batt', $temp) && !empty($temp)) {
$this->_output[] = $temp;
}
}
}
/**
* parse the input and store data in resultset for xml generation
*
* @return array
* @return void
*/
private function _info()
{
if (empty($this->_output)) {
return;
}
$model = array();
$percCharge = array();
$lines = explode(PHP_EOL, implode($this->_output));
$dev = new UPSDevice();
$model = explode('FW:', $lines[1]);
if (strpos($model[0], 'InternalBattery') === false) {
$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);
if (count($lines)>1) {
if (strpos($lines[1], 'InternalBattery') === false) {
$dev = new UPSDevice();
$dev->setName('UPS');
$percCharge = explode(';', $lines[1]);
$model = explode('FW:', $lines[1]);
if ($model !== false) {
$dev->setModel(substr(trim($model[0]), 1));
}
if ($percCharge !== false) {
if (preg_match("/\s(\d+)\%$/", trim($percCharge[0]), $tmpbuf)) {
if ($tmpbuf[1]>100) {
$dev->setBatterCharge(100);
} else {
$dev->setBatterCharge($tmpbuf[1]);
}
}
$percCharge[1]=trim($percCharge[1]);
if (preg_match("/^(.+) present:/", $percCharge[1], $tmpbuf)) {
$dev->setStatus(trim($tmpbuf[1]));
} else {
$dev->setStatus($percCharge[1]);
}
if (isset($percCharge[2]) && preg_match("/\s(\d+):(\d+)\s/", $percCharge[2], $tmpbuf)) {
$dev->setTimeLeft($tmpbuf[1]*60+$tmpbuf[2]);
}
}
$dev->setMode("pmset");
$this->upsinfo->setUpsDevices($dev);
}
$this->upsinfo->setUpsDevices($dev);
}
}
@@ -81,7 +100,7 @@ class Pmset extends UPS
*
* @see PSI_Interface_UPS::build()
*
* @return Void
* @return void
*/
public function build()
{

View File

@@ -8,7 +8,7 @@
* @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
* @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
*/
@@ -19,7 +19,7 @@
* @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
* @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
*/
@@ -28,7 +28,7 @@ class PowerSoftPlus extends UPS
/**
* internal storage for all gathered data
*
* @var Array
* @var array
*/
private $_output = array();
@@ -38,16 +38,23 @@ class PowerSoftPlus extends UPS
public function __construct()
{
parent::__construct();
CommonFunctions::executeProgram('powersoftplus', '-p', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
if (defined('PSI_UPS_POWERSOFTPLUS_ACCESS') && (strtolower(trim(PSI_UPS_POWERSOFTPLUS_ACCESS))==='data')) {
CommonFunctions::rftsdata('upspowersoftplus.tmp', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
} elseif (PSI_OS == 'Linux') {
CommonFunctions::executeProgram('powersoftplus', '-p', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
}
/**
* parse the input and store data in resultset for xml generation
*
* @return Void
* @return void
*/
private function _info()
{
@@ -69,18 +76,18 @@ class PowerSoftPlus extends UPS
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)) {
if (preg_match('/^Output load\s*:\s*(.*)\s\[\%\]\r?$/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)) {
if (($load == 0) && ($maxpwr != 0) && preg_match('/^Effective power\s*:\s*(.*)\s\[W\]\r?$/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)) {
if (preg_match('/^Battery voltage\s*:\s*(.*)\s\[Volt\]\r?$/m', $ups, $data)) {
$dev->setBatteryVoltage(trim($data[1]));
}
if (preg_match('/^Battery state\s*:\s*(.*)$/m', $ups, $data)) {
@@ -91,10 +98,10 @@ class PowerSoftPlus extends UPS
}
}
// Line
if (preg_match('/^Input voltage\s*:\s*(.*)\s\[Volt\]$/m', $ups, $data)) {
if (preg_match('/^Input voltage\s*:\s*(.*)\s\[Volt\]\r?$/m', $ups, $data)) {
$dev->setLineVoltage(trim($data[1]));
}
if (preg_match('/^Input frequency\s*:\s*(.*)\s\[Hz\]$/m', $ups, $data)) {
if (preg_match('/^Input frequency\s*:\s*(.*)\s\[Hz\]\r?$/m', $ups, $data)) {
$dev->setLineFrequency(trim($data[1]));
}
$this->upsinfo->setUpsDevices($dev);
@@ -106,7 +113,7 @@ class PowerSoftPlus extends UPS
*
* @see PSI_Interface_UPS::build()
*
* @return Void
* @return void
*/
public function build()
{

View File

@@ -0,0 +1,292 @@
<?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();
if (!defined('PSI_UPS_SNMPUPS_ACCESS')) {
define('PSI_UPS_SNMPUPS_ACCESS', 'php-snmp');
}
switch (strtolower(PSI_UPS_SNMPUPS_ACCESS)) {
case 'data':
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);
}
} else {
$upss = array('UPS');
}
$un = 0;
foreach ($upss as $ups) {
$temp = "";
CommonFunctions::rftsdata("upssnmpups{$un}.tmp", $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
$un++;
}
break;
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) {
$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.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");
}
}
/**
* 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]).")";
}
}
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]).")";
}
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]).")";
}
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();
}
}

View File

@@ -8,7 +8,7 @@
* @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
* @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
*/
@@ -19,7 +19,7 @@
* @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
* @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
*/
@@ -28,9 +28,9 @@ abstract class UPS implements PSI_Interface_UPS
/**
* object for error handling
*
* @var Error
* @var PSI_Error
*/
protected $error;
public $error;
/**
* main object for ups information
@@ -44,7 +44,7 @@ abstract class UPS implements PSI_Interface_UPS
*/
public function __construct()
{
$this->error = Error::singleton();
$this->error = PSI_Error::singleton();
$this->upsinfo = new UPSInfo();
}