Subversion Repositories ALCASAR

Rev

Rev 2976 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

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