Subversion Repositories ALCASAR

Rev

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

Rev Author Line No. Line
2770 rexy 1
<?php
2
/**
3
 * freeipmi sensor class, getting information from ipmi-sensors
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI_Sensor
9
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
10
 * @copyright 2014 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 FreeIPMI extends Sensors
16
{
17
    /**
18
     * content to parse
19
     *
20
     * @var array
21
     */
22
    private $_lines = array();
23
 
24
    /**
25
     * fill the private content var through command or data access
26
     */
27
    public function __construct()
28
    {
29
        parent::__construct();
30
        switch (defined('PSI_SENSOR_FREEIPMI_ACCESS')?strtolower(PSI_SENSOR_FREEIPMI_ACCESS):'command') {
31
        case 'command':
32
            CommonFunctions::executeProgram('ipmi-sensors', '--output-sensor-thresholds', $lines);
33
            $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
34
            break;
35
        case 'data':
36
            if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/freeipmi.txt', $lines)) {
37
                $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
38
            }
39
            break;
40
        default:
41
            $this->error->addConfigError('__construct()', '[sensor_freeipmi] ACCESS');
42
            break;
43
        }
44
    }
45
 
46
    /**
47
     * get temperature information
48
     *
49
     * @return void
50
     */
51
    private function _temperature()
52
    {
53
        foreach ($this->_lines as $line) {
54
            $buffer = preg_split("/\s*\|\s*/", $line);
55
            if ($buffer[2] == "Temperature" && $buffer[11] != "N/A" && $buffer[4] == "C") {
56
                $dev = new SensorDevice();
57
                $dev->setName($buffer[1]);
58
                $dev->setValue($buffer[3]);
59
                if ($buffer[9] != "N/A") $dev->setMax($buffer[9]);
60
                if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
61
                $this->mbinfo->setMbTemp($dev);
62
            }
63
        }
64
    }
65
 
66
    /**
67
     * get voltage information
68
     *
69
     * @return void
70
     */
71
    private function _voltage()
72
    {
73
        foreach ($this->_lines as $line) {
74
            $buffer = preg_split("/\s*\|\s*/", $line);
75
            if ($buffer[2] == "Voltage" && $buffer[11] != "N/A" && $buffer[4] == "V") {
76
                $dev = new SensorDevice();
77
                $dev->setName($buffer[1]);
78
                $dev->setValue($buffer[3]);
79
                if ($buffer[6] != "N/A") $dev->setMin($buffer[6]);
80
                if ($buffer[9] != "N/A") $dev->setMax($buffer[9]);
81
                if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
82
                $this->mbinfo->setMbVolt($dev);
83
            }
84
        }
85
    }
86
 
87
    /**
88
     * get fan information
89
     *
90
     * @return void
91
     */
92
    private function _fans()
93
    {
94
        foreach ($this->_lines as $line) {
95
            $buffer = preg_split("/\s*\|\s*/", $line);
96
            if ($buffer[2] == "Fan" && $buffer[11] != "N/A" && $buffer[4] == "RPM") {
97
                $dev = new SensorDevice();
98
                $dev->setName($buffer[1]);
99
                $dev->setValue($buffer[3]);
100
                if ($buffer[6] != "N/A") {
101
                    $dev->setMin($buffer[6]);
102
                } elseif (($buffer[9] != "N/A") && ($buffer[9]<$buffer[3])) { //max instead min issue
103
                    $dev->setMin($buffer[9]);
104
                }
105
                if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
106
                $this->mbinfo->setMbFan($dev);
107
            }
108
        }
109
    }
110
 
111
    /**
112
     * get power information
113
     *
114
     * @return void
115
     */
116
    private function _power()
117
    {
118
        foreach ($this->_lines as $line) {
119
            $buffer = preg_split("/\s*\|\s*/", $line);
120
            if ($buffer[2] == "Current" && $buffer[11] != "N/A" && $buffer[4] == "W") {
121
                $dev = new SensorDevice();
122
                $dev->setName($buffer[1]);
123
                $dev->setValue($buffer[3]);
124
                if ($buffer[9] != "N/A") $dev->setMax($buffer[9]);
125
                if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
126
                $this->mbinfo->setMbPower($dev);
127
            }
128
        }
129
    }
130
 
131
    /**
132
     * get current information
133
     *
134
     * @return void
135
     */
136
    private function _current()
137
    {
138
        foreach ($this->_lines as $line) {
139
            $buffer = preg_split("/\s*\|\s*/", $line);
140
            if ($buffer[2] == "Current" && $buffer[11] != "N/A" && $buffer[4] == "A") {
141
                $dev = new SensorDevice();
142
                $dev->setName($buffer[1]);
143
                $dev->setValue($buffer[3]);
144
                if ($buffer[6] != "N/A") $dev->setMin($buffer[6]);
145
                if ($buffer[9] != "N/A") $dev->setMax($buffer[9]);
146
                if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
147
                $this->mbinfo->setMbCurrent($dev);
148
            }
149
        }
150
    }
151
 
152
    /**
153
     * get other information
154
     *
155
     * @return void
156
     */
157
    private function _other()
158
    {
159
        foreach ($this->_lines as $line) {
160
            $buffer = preg_split("/\s*\|\s*/", $line);
161
             if ($buffer[4] == "N/A"
162
                && $buffer[2] != "OEM Reserved" && $buffer[11] != "N/A") {
163
                $dev = new SensorDevice();
164
                $dev->setName($buffer[1].' ('.$buffer[2].')');
165
                $dev->setValue(trim($buffer[11], '\''));
166
                $this->mbinfo->setMbOther($dev);
167
            }
168
        }
169
    }
170
 
171
    /**
172
     * get the information
173
     *
174
     * @see PSI_Interface_Sensor::build()
175
     *
176
     * @return Void
177
     */
178
    public function build()
179
    {
180
        $this->_temperature();
181
        $this->_voltage();
182
        $this->_fans();
183
        $this->_power();
184
        $this->_current();
185
        $this->_other();
186
    }
187
}