2770 |
rexy |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* ipmiutil 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 IPMIutil 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();
|
3100 |
rexy |
30 |
if (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT')) switch (defined('PSI_SENSOR_IPMIUTIL_ACCESS')?strtolower(PSI_SENSOR_IPMIUTIL_ACCESS):'command') {
|
2770 |
rexy |
31 |
case 'command':
|
|
|
32 |
CommonFunctions::executeProgram('ipmiutil', 'sensor -stw', $lines);
|
|
|
33 |
$this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
34 |
break;
|
|
|
35 |
case 'data':
|
3100 |
rexy |
36 |
if (!defined('PSI_EMU_PORT') && CommonFunctions::rftsdata('ipmiutil.tmp', $lines)) {
|
2770 |
rexy |
37 |
$this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
38 |
}
|
|
|
39 |
break;
|
|
|
40 |
default:
|
|
|
41 |
$this->error->addConfigError('__construct()', '[sensor_ipmiutil] ACCESS');
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* get temperature information
|
|
|
47 |
*
|
|
|
48 |
* @return void
|
|
|
49 |
*/
|
|
|
50 |
private function _temperature()
|
|
|
51 |
{
|
|
|
52 |
foreach ($this->_lines as $line) {
|
|
|
53 |
$buffer = preg_split("/\s*\|\s*/", $line);
|
|
|
54 |
if (isset($buffer[2]) && $buffer[2] == "Temperature"
|
|
|
55 |
&& $buffer[1] == "Full"
|
|
|
56 |
&& isset($buffer[6]) && preg_match("/^(\S+)\sC$/", $buffer[6], $value)
|
|
|
57 |
&& $buffer[5] !== "Init") {
|
|
|
58 |
$dev = new SensorDevice();
|
|
|
59 |
$dev->setName($buffer[4]);
|
|
|
60 |
$dev->setValue($value[1]);
|
|
|
61 |
if (isset($buffer[7]) && $buffer[7] == "Thresholds") {
|
|
|
62 |
if ((isset($buffer[8]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[8], $limits))
|
|
|
63 |
||(isset($buffer[9]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[9], $limits))
|
|
|
64 |
||(isset($buffer[10]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[10], $limits))
|
|
|
65 |
||(isset($buffer[11]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[11], $limits))) {
|
|
|
66 |
$dev->setMax($limits[1]);
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
if ($buffer[5] != "OK") $dev->setEvent($buffer[5]);
|
|
|
70 |
$this->mbinfo->setMbTemp($dev);
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
/**
|
|
|
76 |
* get voltage information
|
|
|
77 |
*
|
|
|
78 |
* @return void
|
|
|
79 |
*/
|
|
|
80 |
private function _voltage()
|
|
|
81 |
{
|
|
|
82 |
foreach ($this->_lines as $line) {
|
|
|
83 |
$buffer = preg_split("/\s*\|\s*/", $line);
|
|
|
84 |
if (isset($buffer[2]) && $buffer[2] == "Voltage"
|
|
|
85 |
&& $buffer[1] == "Full"
|
|
|
86 |
&& isset($buffer[6]) && preg_match("/^(\S+)\sV$/", $buffer[6], $value)
|
|
|
87 |
&& $buffer[5] !== "Init") {
|
|
|
88 |
$dev = new SensorDevice();
|
|
|
89 |
$dev->setName($buffer[4]);
|
|
|
90 |
$dev->setValue($value[1]);
|
|
|
91 |
if (isset($buffer[7]) && $buffer[7] == "Thresholds") {
|
|
|
92 |
if ((isset($buffer[8]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[8], $limits))
|
|
|
93 |
||(isset($buffer[9]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[9], $limits))
|
|
|
94 |
||(isset($buffer[10]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[10], $limits))
|
|
|
95 |
||(isset($buffer[11]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[11], $limits))) {
|
|
|
96 |
$dev->setMin($limits[1]);
|
|
|
97 |
}
|
|
|
98 |
if ((isset($buffer[8]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[8], $limits))
|
|
|
99 |
||(isset($buffer[9]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[9], $limits))
|
|
|
100 |
||(isset($buffer[10]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[10], $limits))
|
|
|
101 |
||(isset($buffer[11]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[11], $limits))) {
|
|
|
102 |
$dev->setMax($limits[1]);
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
if ($buffer[5] != "OK") $dev->setEvent($buffer[5]);
|
|
|
106 |
$this->mbinfo->setMbVolt($dev);
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
/**
|
|
|
112 |
* get fan information
|
|
|
113 |
*
|
|
|
114 |
* @return void
|
|
|
115 |
*/
|
|
|
116 |
private function _fans()
|
|
|
117 |
{
|
|
|
118 |
foreach ($this->_lines as $line) {
|
|
|
119 |
$buffer = preg_split("/\s*\|\s*/", $line);
|
|
|
120 |
if (isset($buffer[2]) && $buffer[2] == "Fan"
|
|
|
121 |
&& $buffer[1] == "Full"
|
|
|
122 |
&& isset($buffer[6]) && preg_match("/^(\S+)\sRPM$/", $buffer[6], $value)
|
|
|
123 |
&& $buffer[5] !== "Init") {
|
|
|
124 |
$dev = new SensorDevice();
|
|
|
125 |
$dev->setName($buffer[4]);
|
|
|
126 |
$dev->setValue($value[1]);
|
|
|
127 |
if (isset($buffer[7]) && $buffer[7] == "Thresholds") {
|
|
|
128 |
if ((isset($buffer[8]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[8], $limits))
|
|
|
129 |
||(isset($buffer[9]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[9], $limits))
|
|
|
130 |
||(isset($buffer[10]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[10], $limits))
|
|
|
131 |
||(isset($buffer[11]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[11], $limits))) {
|
|
|
132 |
$dev->setMin($limits[1]);
|
|
|
133 |
} elseif ((isset($buffer[8]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[8], $limits))
|
|
|
134 |
||(isset($buffer[9]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[9], $limits))
|
|
|
135 |
||(isset($buffer[10]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[10], $limits))
|
|
|
136 |
||(isset($buffer[11]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[11], $limits))) {
|
|
|
137 |
if ($limits[1]<$value[1]) {//max instead min issue
|
|
|
138 |
$dev->setMin($limits[1]);
|
|
|
139 |
}
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
if ($buffer[5] != "OK") $dev->setEvent($buffer[5]);
|
|
|
143 |
$this->mbinfo->setMbFan($dev);
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
/**
|
|
|
149 |
* get power information
|
|
|
150 |
*
|
|
|
151 |
* @return void
|
|
|
152 |
*/
|
|
|
153 |
private function _power()
|
|
|
154 |
{
|
|
|
155 |
foreach ($this->_lines as $line) {
|
|
|
156 |
$buffer = preg_split("/\s*\|\s*/", $line);
|
|
|
157 |
if (isset($buffer[2]) && $buffer[2] == "Current"
|
|
|
158 |
&& $buffer[1] == "Full"
|
|
|
159 |
&& isset($buffer[6]) && preg_match("/^(\S+)\sW$/", $buffer[6], $value)
|
|
|
160 |
&& $buffer[5] !== "Init") {
|
|
|
161 |
$dev = new SensorDevice();
|
|
|
162 |
$dev->setName($buffer[4]);
|
|
|
163 |
$dev->setValue($value[1]);
|
|
|
164 |
if (isset($buffer[7]) && $buffer[7] == "Thresholds") {
|
|
|
165 |
if ((isset($buffer[8]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[8], $limits))
|
|
|
166 |
||(isset($buffer[9]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[9], $limits))
|
|
|
167 |
||(isset($buffer[10]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[10], $limits))
|
|
|
168 |
||(isset($buffer[11]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[11], $limits))) {
|
|
|
169 |
$dev->setMax($limits[1]);
|
|
|
170 |
}
|
|
|
171 |
}
|
|
|
172 |
if ($buffer[5] != "OK") $dev->setEvent($buffer[5]);
|
|
|
173 |
$this->mbinfo->setMbPower($dev);
|
|
|
174 |
}
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
/**
|
|
|
179 |
* get current information
|
|
|
180 |
*
|
|
|
181 |
* @return void
|
|
|
182 |
*/
|
|
|
183 |
private function _current()
|
|
|
184 |
{
|
|
|
185 |
foreach ($this->_lines as $line) {
|
|
|
186 |
$buffer = preg_split("/\s*\|\s*/", $line);
|
|
|
187 |
if (isset($buffer[2]) && $buffer[2] == "Current"
|
|
|
188 |
&& $buffer[1] == "Full"
|
|
|
189 |
&& isset($buffer[6]) && preg_match("/^(\S+)\sA$/", $buffer[6], $value)
|
|
|
190 |
&& $buffer[5] !== "Init") {
|
|
|
191 |
$dev = new SensorDevice();
|
|
|
192 |
$dev->setName($buffer[4]);
|
|
|
193 |
$dev->setValue($value[1]);
|
|
|
194 |
if (isset($buffer[7]) && $buffer[7] == "Thresholds") {
|
|
|
195 |
if ((isset($buffer[8]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[8], $limits))
|
|
|
196 |
||(isset($buffer[9]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[9], $limits))
|
|
|
197 |
||(isset($buffer[10]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[10], $limits))
|
|
|
198 |
||(isset($buffer[11]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[11], $limits))) {
|
|
|
199 |
$dev->setMin($limits[1]);
|
|
|
200 |
}
|
|
|
201 |
if ((isset($buffer[8]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[8], $limits))
|
|
|
202 |
||(isset($buffer[9]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[9], $limits))
|
|
|
203 |
||(isset($buffer[10]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[10], $limits))
|
|
|
204 |
||(isset($buffer[11]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[11], $limits))) {
|
|
|
205 |
$dev->setMax($limits[1]);
|
|
|
206 |
}
|
|
|
207 |
}
|
|
|
208 |
if ($buffer[5] != "OK") $dev->setEvent($buffer[5]);
|
|
|
209 |
$this->mbinfo->setMbCurrent($dev);
|
|
|
210 |
}
|
|
|
211 |
}
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
/**
|
|
|
215 |
* get other information
|
|
|
216 |
*
|
|
|
217 |
* @return void
|
|
|
218 |
*/
|
|
|
219 |
private function _other()
|
|
|
220 |
{
|
|
|
221 |
foreach ($this->_lines as $line) {
|
|
|
222 |
$buffer = preg_split("/\s*\|\s*/", $line);
|
|
|
223 |
if (isset($buffer[1]) && $buffer[1] == "Compact"
|
|
|
224 |
&& $buffer[5] !== "Init"
|
|
|
225 |
&& $buffer[5] !== "Unknown"
|
|
|
226 |
&& $buffer[5] !== "NotAvailable") {
|
|
|
227 |
$dev = new SensorDevice();
|
|
|
228 |
$dev->setName($buffer[4].' ('.$buffer[2].')');
|
|
|
229 |
|
|
|
230 |
$buffer5s = preg_split("/\s+/", $buffer5 = $buffer[5]);
|
|
|
231 |
if (isset($buffer5s[1])) {
|
3037 |
rexy |
232 |
if (preg_match('/^[0-9A-Fa-f]+$/', $buffer5s[0])) {
|
|
|
233 |
$value = hexdec($buffer5s[0]) & 0xff;
|
|
|
234 |
if ($buffer5s[1] === 'DiscreteEvt') {
|
|
|
235 |
$dev->setValue('0x'.dechex($value));
|
|
|
236 |
} elseif (($buffer5s[1] === 'DiscreteUnit') && ($value > 0)) {
|
|
|
237 |
$dev->setValue('0x'.dechex($value - 1));
|
|
|
238 |
} else {
|
|
|
239 |
$dev->setValue($buffer5);
|
|
|
240 |
}
|
2770 |
rexy |
241 |
} else {
|
|
|
242 |
$dev->setValue($buffer5);
|
|
|
243 |
}
|
|
|
244 |
} else {
|
|
|
245 |
$dev->setValue($buffer5);
|
|
|
246 |
}
|
|
|
247 |
$this->mbinfo->setMbOther($dev);
|
|
|
248 |
}
|
|
|
249 |
}
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
/**
|
|
|
253 |
* get the information
|
|
|
254 |
*
|
|
|
255 |
* @see PSI_Interface_Sensor::build()
|
|
|
256 |
*
|
3037 |
rexy |
257 |
* @return void
|
2770 |
rexy |
258 |
*/
|
|
|
259 |
public function build()
|
|
|
260 |
{
|
|
|
261 |
$this->_temperature();
|
|
|
262 |
$this->_voltage();
|
|
|
263 |
$this->_fans();
|
|
|
264 |
$this->_power();
|
|
|
265 |
$this->_current();
|
|
|
266 |
$this->_other();
|
|
|
267 |
}
|
|
|
268 |
}
|