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