Subversion Repositories ALCASAR

Rev

Rev 3037 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 3037 Rev 3100
1
<?php
1
<?php
2
/**
2
/**
3
 * qtstemp sensor class, getting hardware temperature information through snmpwalk
3
 * qtstemp sensor class, getting hardware temperature information through snmpwalk
4
 *
4
 *
5
 * PHP version 5
5
 * PHP version 5
6
 *
6
 *
7
 * @category  PHP
7
 * @category  PHP
8
 * @package   PSI_Sensor
8
 * @package   PSI_Sensor
9
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
9
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
10
 * @copyright 2016 phpSysInfo
10
 * @copyright 2016 phpSysInfo
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
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
12
 * @version   Release: 3.0
13
 * @link      http://phpsysinfo.sourceforge.net
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
14
 */
15
class QTSsnmp extends Sensors
15
class QTSsnmp extends Sensors
16
{
16
{
17
    /**
17
    /**
18
     * get temperature information
18
     * get temperature information
19
     *
19
     *
20
     * @return void
20
     * @return void
21
     */
21
     */
22
    private function _temperature()
22
    private function _temperature()
23
    {
23
    {
-
 
24
        if (!defined('PSI_EMU_PORT')) {
-
 
25
            $address = '127.0.0.1';
-
 
26
        } else {
-
 
27
            $address = PSI_EMU_HOSTNAME;
-
 
28
        }
24
        if (CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." 127.0.0.1 .1.3.6.1.4.1.24681.1.2.5.0", $buffer, PSI_DEBUG)
29
        if (CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$address." .1.3.6.1.4.1.24681.1.2.5.0", $buffer, PSI_DEBUG)
25
           && preg_match('/^[\.\d]+ = STRING:\s\"?(\d+)\sC/', $buffer, $data)) {
30
           && preg_match('/^[\.\d]+ = STRING:\s\"?(\d+)\sC/', $buffer, $data)) {
26
            $dev = new SensorDevice();
31
            $dev = new SensorDevice();
27
            $dev->setName("CPU");
32
            $dev->setName("CPU");
28
            $dev->setValue($data[1]);
33
            $dev->setValue($data[1]);
29
            $this->mbinfo->setMbTemp($dev);
34
            $this->mbinfo->setMbTemp($dev);
30
        }
35
        }
31
 
36
 
32
        if (CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." 127.0.0.1 .1.3.6.1.4.1.24681.1.2.6.0", $buffer, PSI_DEBUG)
37
        if (CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$address." .1.3.6.1.4.1.24681.1.2.6.0", $buffer, PSI_DEBUG)
33
           && preg_match('/^[\.\d]+ = STRING:\s\"?(\d+)\sC/', $buffer, $data)) {
38
           && preg_match('/^[\.\d]+ = STRING:\s\"?(\d+)\sC/', $buffer, $data)) {
34
            $dev = new SensorDevice();
39
            $dev = new SensorDevice();
35
            $dev->setName("System");
40
            $dev->setName("System");
36
            $dev->setValue($data[1]);
41
            $dev->setValue($data[1]);
37
            $this->mbinfo->setMbTemp($dev);
42
            $this->mbinfo->setMbTemp($dev);
38
        }
43
        }
39
 
44
 
40
        if (CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." 127.0.0.1 .1.3.6.1.4.1.24681.1.2.11.1.3", $buffer, PSI_DEBUG)) {
45
        if (CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$address." .1.3.6.1.4.1.24681.1.2.11.1.3", $buffer, PSI_DEBUG)) {
41
            $lines = preg_split('/\r?\n/', $buffer);
46
            $lines = preg_split('/\r?\n/', $buffer);
42
            foreach ($lines as $line) if (preg_match('/^[\.\d]+\.(\d+) = STRING:\s\"?(\d+)\sC/', $line, $data)) {
47
            foreach ($lines as $line) if (preg_match('/^[\.\d]+\.(\d+) = STRING:\s\"?(\d+)\sC/', $line, $data)) {
43
                $dev = new SensorDevice();
48
                $dev = new SensorDevice();
44
                $dev->setName("HDD ".$data[1]);
49
                $dev->setName("HDD ".$data[1]);
45
                $dev->setValue($data[2]);
50
                $dev->setValue($data[2]);
46
                $this->mbinfo->setMbTemp($dev);
51
                $this->mbinfo->setMbTemp($dev);
47
            }
52
            }
48
        }
53
        }
49
    }
54
    }
50
 
55
 
51
    /**
56
    /**
52
     * get fan information
57
     * get fan information
53
     *
58
     *
54
     * @return void
59
     * @return void
55
     */
60
     */
56
    private function _fans()
61
    private function _fans()
57
    {
62
    {
-
 
63
        if (!defined('PSI_EMU_PORT')) {
-
 
64
            $address = '127.0.0.1';
-
 
65
        } else {
-
 
66
            $address = PSI_EMU_HOSTNAME;
-
 
67
        }
58
        if (CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." 127.0.0.1 .1.3.6.1.4.1.24681.1.2.15.1.3", $buffer, PSI_DEBUG)) {
68
        if (CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$address." .1.3.6.1.4.1.24681.1.2.15.1.3", $buffer, PSI_DEBUG)) {
59
            $lines = preg_split('/\r?\n/', $buffer);
69
            $lines = preg_split('/\r?\n/', $buffer);
60
            foreach ($lines as $line) if (preg_match('/^[\.\d]+\.(\d+) = STRING:\s\"?(\d+)\sRPM/', $line, $data)) {
70
            foreach ($lines as $line) if (preg_match('/^[\.\d]+\.(\d+) = STRING:\s\"?(\d+)\sRPM/', $line, $data)) {
61
                $dev = new SensorDevice();
71
                $dev = new SensorDevice();
62
                $dev->setName("Fan ".$data[1]);
72
                $dev->setName("Fan ".$data[1]);
63
                $dev->setValue($data[2]);
73
                $dev->setValue($data[2]);
64
                $this->mbinfo->setMbFan($dev);
74
                $this->mbinfo->setMbFan($dev);
65
            }
75
            }
66
        }
76
        }
67
    }
77
    }
68
 
78
 
69
    /**
79
    /**
70
     * get the information
80
     * get the information
71
     *
81
     *
72
     * @see PSI_Interface_Sensor::build()
82
     * @see PSI_Interface_Sensor::build()
73
     *
83
     *
74
     * @return void
84
     * @return void
75
     */
85
     */
76
    public function build()
86
    public function build()
77
    {
87
    {
78
        if ((PSI_OS == 'Linux') && !defined('PSI_EMU_HOSTNAME')) {
88
        if ((PSI_OS == 'Linux') && (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT'))) {
79
            $this->_temperature();
89
            $this->_temperature();
80
            $this->_fans();
90
            $this->_fans();
81
        }
91
        }
82
    }
92
    }
83
}
93
}
84
 
94