smeserver-phpsysinfo/root/opt/phpsysinfo/includes/mb/class.k8temp.inc.php

92 lines
2.4 KiB
PHP
Raw Normal View History

<?php
/**
* K8Temp sensor class
*
* 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 SVN: $Id: class.k8temp.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from k8temp
*
* @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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class K8Temp extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private array
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'command':
$lines = "";
CommonFunctions::executeProgram('k8temp', '', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case 'file':
if (CommonFunctions::rfts(APP_ROOT.'/data/k8temp.txt', $lines)) {
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
if (preg_match('/(.*):\s*(\d*)/', $line, $data)) {
if ($data[2] > 0) {
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setMax('70.0');
if ($data[2] < 250) {
$dev->setValue($data[2]);
}
$this->mbinfo->setMbTemp($dev);
}
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
}
}