Subversion Repositories ALCASAR

Rev

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

Rev 2976 Rev 3037
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
        if ((PSI_OS != 'WINNT') && !defined('PSI_EMU_HOSTNAME')) 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::rftsdata('mbmon.tmp', $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;
-
 
55
        }
54
        }
56
    }
55
    }
57
 
56
 
58
    /**
57
    /**
59
     * get temperature information
58
     * get temperature information
60
     *
59
     *
61
     * @return void
60
     * @return void
62
     */
61
     */
63
    private function _temperature()
62
    private function _temperature()
64
    {
63
    {
65
        foreach ($this->_lines as $line) {
64
        foreach ($this->_lines as $line) {
66
            if (preg_match('/^(TEMP\d*)\s*:\s*(.*)$/D', $line, $data)) {
65
            if (preg_match('/^(TEMP\d*)\s*:\s*(.*)$/D', $line, $data)) {
67
                if ($data[2] <> '0') {
66
                if ($data[2] <> '0') {
68
                    $dev = new SensorDevice();
67
                    $dev = new SensorDevice();
69
                    $dev->setName($data[1]);
68
                    $dev->setName($data[1]);
70
//                    $dev->setMax(70);
69
//                    $dev->setMax(70);
71
                    if ($data[2] < 250) {
70
                    if ($data[2] < 250) {
72
                        $dev->setValue($data[2]);
71
                        $dev->setValue($data[2]);
73
                    }
72
                    }
74
                    $this->mbinfo->setMbTemp($dev);
73
                    $this->mbinfo->setMbTemp($dev);
75
                }
74
                }
76
            }
75
            }
77
        }
76
        }
78
    }
77
    }
79
 
78
 
80
    /**
79
    /**
81
     * get fan information
80
     * get fan information
82
     *
81
     *
83
     * @return void
82
     * @return void
84
     */
83
     */
85
    private function _fans()
84
    private function _fans()
86
    {
85
    {
87
        foreach ($this->_lines as $line) {
86
        foreach ($this->_lines as $line) {
88
            if (preg_match('/^(FAN\d*)\s*:\s*(.*)$/D', $line, $data)) {
87
            if (preg_match('/^(FAN\d*)\s*:\s*(.*)$/D', $line, $data)) {
89
                if ($data[2] <> '0') {
88
                if ($data[2] <> '0') {
90
                    $dev = new SensorDevice();
89
                    $dev = new SensorDevice();
91
                    $dev->setName($data[1]);
90
                    $dev->setName($data[1]);
92
                    $dev->setValue($data[2]);
91
                    $dev->setValue($data[2]);
93
//                    $dev->setMax(3000);
92
//                    $dev->setMax(3000);
94
                    $this->mbinfo->setMbFan($dev);
93
                    $this->mbinfo->setMbFan($dev);
95
                }
94
                }
96
            }
95
            }
97
        }
96
        }
98
    }
97
    }
99
 
98
 
100
    /**
99
    /**
101
     * get voltage information
100
     * get voltage information
102
     *
101
     *
103
     * @return void
102
     * @return void
104
     */
103
     */
105
    private function _voltage()
104
    private function _voltage()
106
    {
105
    {
107
        foreach ($this->_lines as $line) {
106
        foreach ($this->_lines as $line) {
108
            if (preg_match('/^(V.*)\s*:\s*(.*)$/D', $line, $data)) {
107
            if (preg_match('/^(V.*)\s*:\s*(.*)$/D', $line, $data)) {
109
                if ($data[2] <> '+0.00') {
108
                if ($data[2] <> '+0.00') {
110
                    $dev = new SensorDevice();
109
                    $dev = new SensorDevice();
111
                    $dev->setName($data[1]);
110
                    $dev->setName($data[1]);
112
                    $dev->setValue($data[2]);
111
                    $dev->setValue($data[2]);
113
                    $this->mbinfo->setMbVolt($dev);
112
                    $this->mbinfo->setMbVolt($dev);
114
                }
113
                }
115
            }
114
            }
116
        }
115
        }
117
    }
116
    }
118
 
117
 
119
    /**
118
    /**
120
     * get the information
119
     * get the information
121
     *
120
     *
122
     * @see PSI_Interface_Sensor::build()
121
     * @see PSI_Interface_Sensor::build()
123
     *
122
     *
124
     * @return void
123
     * @return void
125
     */
124
     */
126
    public function build()
125
    public function build()
127
    {
126
    {
128
        $this->_temperature();
127
        $this->_temperature();
129
        $this->_voltage();
128
        $this->_voltage();
130
        $this->_fans();
129
        $this->_fans();
131
    }
130
    }
132
}
131
}
133
 
132