Subversion Repositories ALCASAR

Rev

Rev 3037 | Details | Compare with Previous | Last modification | View Log

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