Subversion Repositories ALCASAR

Rev

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