Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

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