1,99 → 1,132 |
<?php |
/** |
* mbmon sensor class, getting information from mbmon |
* |
* PHP version 5 |
* |
* @category PHP |
* @package PSI_Sensor |
* @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 |
*/ |
class MBMon extends Sensors |
{ |
/** |
* content to parse |
* |
* @var array |
*/ |
private $_lines = array(); |
|
// phpSysInfo - A PHP System Information Script |
// http://phpsysinfo.sourceforge.net/ |
/** |
* fill the private content var through tcp, command or data access |
*/ |
public function __construct() |
{ |
parent::__construct(); |
switch (defined('PSI_SENSOR_MBMON_ACCESS')?strtolower(PSI_SENSOR_MBMON_ACCESS):'command') { |
case 'tcp': |
$fp = fsockopen("localhost", 411, $errno, $errstr, 5); |
if ($fp) { |
$lines = ""; |
while (!feof($fp)) { |
$lines .= fread($fp, 1024); |
} |
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY); |
} else { |
$this->error->addError("fsockopen()", $errno." ".$errstr); |
} |
break; |
case 'command': |
CommonFunctions::executeProgram('mbmon', '-c 1 -r', $lines, PSI_DEBUG); |
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY); |
break; |
case 'data': |
if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/mbmon.txt', $lines)) { |
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY); |
} |
break; |
default: |
$this->error->addConfigError('__construct()', '[sensor_mbmon] ACCESS'); |
break; |
} |
} |
|
// This program is free software; you can redistribute it and/or |
// modify it under the terms of the GNU General Public License |
// as published by the Free Software Foundation; either version 2 |
// of the License, or (at your option) any later version. |
|
// This program is distributed in the hope that it will be useful, |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// GNU General Public License for more details. |
|
// You should have received a copy of the GNU General Public License |
// along with this program; if not, write to the Free Software |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
// This class was created by Z. Frombach ( zoltan at frombach dot com ) |
|
// $Id: class.mbmon.inc.php,v 1.5 2007/02/18 19:11:31 bigmichi1 Exp $ |
|
class mbinfo { |
var $lines; |
|
function temperature() { |
$results = array(); |
|
if (!isset($this->lines) ) { |
$this->lines = explode("\n", execute_program('mbmon', '-c 1 -r')); |
} |
|
$i = 0; |
foreach($this->lines as $line) { |
if (preg_match('/^(TEMP\d*)\s*:\s*(.*)$/D', $line, $data)) { |
if ($data[2]<>'0') { |
$results[$i]['label'] = $data[1]; |
$results[$i]['limit'] = '70.0'; |
if($data[2] > 250) { |
$results[$i]['value'] = 0; |
$results[$i]['percent'] = 0; |
} else { |
$results[$i]['value'] = $data[2]; |
$results[$i]['percent'] = $results[$i]['value'] * 100 / $results[$i]['limit']; |
} |
$i++; |
/** |
* get temperature information |
* |
* @return void |
*/ |
private function _temperature() |
{ |
foreach ($this->_lines as $line) { |
if (preg_match('/^(TEMP\d*)\s*:\s*(.*)$/D', $line, $data)) { |
if ($data[2] <> '0') { |
$dev = new SensorDevice(); |
$dev->setName($data[1]); |
// $dev->setMax(70); |
if ($data[2] < 250) { |
$dev->setValue($data[2]); |
} |
$this->mbinfo->setMbTemp($dev); |
} |
} |
} |
} |
} |
return $results; |
} |
|
function fans() { |
$results = array(); |
|
if (!isset($this->lines) ) { |
$this->lines = explode("\n", execute_program('mbmon', '-c 1 -r')); |
} |
|
$i = 0; |
foreach($this->lines as $line) { |
if (preg_match('/^(FAN\d*)\s*:\s*(.*)$/D', $line, $data)) { |
if ($data[2]<>'0') { |
$results[$i]['label'] = $data[1]; |
$results[$i]['value'] = $data[2]; |
$results[$i]['min'] = '3000'; |
$i++; |
/** |
* get fan information |
* |
* @return void |
*/ |
private function _fans() |
{ |
foreach ($this->_lines as $line) { |
if (preg_match('/^(FAN\d*)\s*:\s*(.*)$/D', $line, $data)) { |
if ($data[2] <> '0') { |
$dev = new SensorDevice(); |
$dev->setName($data[1]); |
$dev->setValue($data[2]); |
// $dev->setMax(3000); |
$this->mbinfo->setMbFan($dev); |
} |
} |
} |
} |
} |
return $results; |
} |
|
function voltage() { |
$results = array(); |
|
if (!isset($this->lines) ) { |
$this->lines = explode("\n", execute_program('mbmon', '-c 1 -r')); |
} |
|
$i = 0; |
foreach($this->lines as $line) { |
if (preg_match('/^(V.*)\s*:\s*(.*)$/D', $line, $data)) { |
if ($data[2]<>'+0.00') { |
$results[$i]['label'] = $data[1]; |
$results[$i]['value'] = $data[2]; |
$results[$i]['min'] = '0.00'; |
$results[$i]['max'] = '0.00'; |
$i++; |
/** |
* get voltage information |
* |
* @return void |
*/ |
private function _voltage() |
{ |
foreach ($this->_lines as $line) { |
if (preg_match('/^(V.*)\s*:\s*(.*)$/D', $line, $data)) { |
if ($data[2] <> '+0.00') { |
$dev = new SensorDevice(); |
$dev->setName($data[1]); |
$dev->setValue($data[2]); |
$this->mbinfo->setMbVolt($dev); |
} |
} |
} |
} |
} |
|
return $results; |
} |
/** |
* get the information |
* |
* @see PSI_Interface_Sensor::build() |
* |
* @return void |
*/ |
public function build() |
{ |
$this->_temperature(); |
$this->_voltage(); |
$this->_fans(); |
} |
} |
|
?> |