Subversion Repositories ALCASAR

Rev

Rev 2770 | Rev 3037 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2770 Rev 2976
1
<?php
1
<?php
2
/**
2
/**
3
 * mbmon sensor class, getting information from mbmon
3
 * mbmon sensor class, getting information from mbmon
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    Michael Cramer <BigMichi1@users.sourceforge.net>
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
10
 * @copyright 2009 phpSysInfo
10
 * @copyright 2009 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 MBMon extends Sensors
15
class MBMon extends Sensors
16
{
16
{
17
    /**
17
    /**
18
     * content to parse
18
     * content to parse
19
     *
19
     *
20
     * @var array
20
     * @var array
21
     */
21
     */
22
    private $_lines = array();
22
    private $_lines = array();
23
 
23
 
24
    /**
24
    /**
25
     * fill the private content var through tcp, command or data access
25
     * fill the private content var through tcp, command or data access
26
     */
26
     */
27
    public function __construct()
27
    public function __construct()
28
    {
28
    {
29
        parent::__construct();
29
        parent::__construct();
30
        switch (defined('PSI_SENSOR_MBMON_ACCESS')?strtolower(PSI_SENSOR_MBMON_ACCESS):'command') {
30
        if ((PSI_OS != 'WINNT') && !defined('PSI_EMU_HOSTNAME')) switch (defined('PSI_SENSOR_MBMON_ACCESS')?strtolower(PSI_SENSOR_MBMON_ACCESS):'command') {
31
        case 'tcp':
31
        case 'tcp':
32
            $fp = fsockopen("localhost", 411, $errno, $errstr, 5);
32
            $fp = fsockopen("localhost", 411, $errno, $errstr, 5);
33
            if ($fp) {
33
            if ($fp) {
34
                $lines = "";
34
                $lines = "";
35
                while (!feof($fp)) {
35
                while (!feof($fp)) {
36
                    $lines .= fread($fp, 1024);
36
                    $lines .= fread($fp, 1024);
37
                }
37
                }
38
                $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
38
                $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
39
            } else {
39
            } else {
40
                $this->error->addError("fsockopen()", $errno." ".$errstr);
40
                $this->error->addError("fsockopen()", $errno." ".$errstr);
41
            }
41
            }
42
            break;
42
            break;
43
        case 'command':
43
        case 'command':
44
            CommonFunctions::executeProgram('mbmon', '-c 1 -r', $lines, PSI_DEBUG);
44
            CommonFunctions::executeProgram('mbmon', '-c 1 -r', $lines, PSI_DEBUG);
45
            $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
45
            $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
46
            break;
46
            break;
47
        case 'data':
47
        case 'data':
48
            if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/mbmon.txt', $lines)) {
48
            if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/mbmon.txt', $lines)) {
49
                $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
49
                $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
50
            }
50
            }
51
            break;
51
            break;
52
        default:
52
        default:
53
            $this->error->addConfigError('__construct()', '[sensor_mbmon] ACCESS');
53
            $this->error->addConfigError('__construct()', '[sensor_mbmon] ACCESS');
54
            break;
54
            break;
55
        }
55
        }
56
    }
56
    }
57
 
57
 
58
    /**
58
    /**
59
     * get temperature information
59
     * get temperature information
60
     *
60
     *
61
     * @return void
61
     * @return void
62
     */
62
     */
63
    private function _temperature()
63
    private function _temperature()
64
    {
64
    {
65
        foreach ($this->_lines as $line) {
65
        foreach ($this->_lines as $line) {
66
            if (preg_match('/^(TEMP\d*)\s*:\s*(.*)$/D', $line, $data)) {
66
            if (preg_match('/^(TEMP\d*)\s*:\s*(.*)$/D', $line, $data)) {
67
                if ($data[2] <> '0') {
67
                if ($data[2] <> '0') {
68
                    $dev = new SensorDevice();
68
                    $dev = new SensorDevice();
69
                    $dev->setName($data[1]);
69
                    $dev->setName($data[1]);
70
//                    $dev->setMax(70);
70
//                    $dev->setMax(70);
71
                    if ($data[2] < 250) {
71
                    if ($data[2] < 250) {
72
                        $dev->setValue($data[2]);
72
                        $dev->setValue($data[2]);
73
                    }
73
                    }
74
                    $this->mbinfo->setMbTemp($dev);
74
                    $this->mbinfo->setMbTemp($dev);
75
                }
75
                }
76
            }
76
            }
77
        }
77
        }
78
    }
78
    }
79
 
79
 
80
    /**
80
    /**
81
     * get fan information
81
     * get fan information
82
     *
82
     *
83
     * @return void
83
     * @return void
84
     */
84
     */
85
    private function _fans()
85
    private function _fans()
86
    {
86
    {
87
        foreach ($this->_lines as $line) {
87
        foreach ($this->_lines as $line) {
88
            if (preg_match('/^(FAN\d*)\s*:\s*(.*)$/D', $line, $data)) {
88
            if (preg_match('/^(FAN\d*)\s*:\s*(.*)$/D', $line, $data)) {
89
                if ($data[2] <> '0') {
89
                if ($data[2] <> '0') {
90
                    $dev = new SensorDevice();
90
                    $dev = new SensorDevice();
91
                    $dev->setName($data[1]);
91
                    $dev->setName($data[1]);
92
                    $dev->setValue($data[2]);
92
                    $dev->setValue($data[2]);
93
//                    $dev->setMax(3000);
93
//                    $dev->setMax(3000);
94
                    $this->mbinfo->setMbFan($dev);
94
                    $this->mbinfo->setMbFan($dev);
95
                }
95
                }
96
            }
96
            }
97
        }
97
        }
98
    }
98
    }
99
 
99
 
100
    /**
100
    /**
101
     * get voltage information
101
     * get voltage information
102
     *
102
     *
103
     * @return void
103
     * @return void
104
     */
104
     */
105
    private function _voltage()
105
    private function _voltage()
106
    {
106
    {
107
        foreach ($this->_lines as $line) {
107
        foreach ($this->_lines as $line) {
108
            if (preg_match('/^(V.*)\s*:\s*(.*)$/D', $line, $data)) {
108
            if (preg_match('/^(V.*)\s*:\s*(.*)$/D', $line, $data)) {
109
                if ($data[2] <> '+0.00') {
109
                if ($data[2] <> '+0.00') {
110
                    $dev = new SensorDevice();
110
                    $dev = new SensorDevice();
111
                    $dev->setName($data[1]);
111
                    $dev->setName($data[1]);
112
                    $dev->setValue($data[2]);
112
                    $dev->setValue($data[2]);
113
                    $this->mbinfo->setMbVolt($dev);
113
                    $this->mbinfo->setMbVolt($dev);
114
                }
114
                }
115
            }
115
            }
116
        }
116
        }
117
    }
117
    }
118
 
118
 
119
    /**
119
    /**
120
     * get the information
120
     * get the information
121
     *
121
     *
122
     * @see PSI_Interface_Sensor::build()
122
     * @see PSI_Interface_Sensor::build()
123
     *
123
     *
124
     * @return void
124
     * @return void
125
     */
125
     */
126
    public function build()
126
    public function build()
127
    {
127
    {
128
        $this->_temperature();
128
        $this->_temperature();
129
        $this->_voltage();
129
        $this->_voltage();
130
        $this->_fans();
130
        $this->_fans();
131
    }
131
    }
132
}
132
}
133
 
133