1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
<?php
/**
* fortisensor sensor class, getting hardware sensors information from Fortinet devices
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2022 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 FortiSensor extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private array
*/
public function __construct()
{
parent::__construct();
$lines = "";
if (defined('PSI_EMU_PORT') && CommonFunctions::executeProgram('execute', 'sensor list', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$resulti = substr($resulte, strlen($resulto[1][0]));
if (preg_match('/(\n.*[\$#])$/', $resulti, $resulto, PREG_OFFSET_CAPTURE)) {
$lines = substr($resulti, 0, $resulto[1][1]);
}
}
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
if (preg_match('/^\s*\d+\s(.+)\sTemperature\s+([\d\.]+)\s\S*C\s*$/', $line, $data)) {
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setValue($data[2]);
$this->mbinfo->setMbTemp($dev);
} elseif (preg_match('/^\s*\d+\s(.+)\s+alarm=(\d)\s+value=(\d+)\s/', $line, $data)
&& !preg_match('/fan| vin/i', $data[1])) {
$dev = new SensorDevice();
$dev->setName(trim($data[1]));
$dev->setValue($data[3]);
if ($data[2] != 0) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbTemp($dev);
}
}
}
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
foreach ($this->_lines as $line) {
if (preg_match('/^\s*\d+\s(.+)\s+alarm=(\d)\s+value=([\d\.]+)\s/', $line, $data)
&& preg_match('/\./', $data[3])
&& !preg_match('/fan|temp/i', $data[1])) {
$dev = new SensorDevice();
$dev->setName(trim($data[1]));
$dev->setValue($data[3]);
if ($data[2] != 0) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbVolt($dev);
}
}
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
foreach ($this->_lines as $line) {
if (preg_match('/^\s*\d+\s(.+)\s+alarm=(\d)\s+value=(\d+)\s/', $line, $data)
&& preg_match('/fan/i', $data[1])) {
$dev = new SensorDevice();
$dev->setName(trim($data[1]));
$dev->setValue($data[3]);
if ($data[2] != 0) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbFan($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
}
}
|