|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ipmiinfo Plugin |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @category PHP |
|
8
|
|
|
* @package PSI_Plugin_ipmiinfo |
|
9
|
|
|
* @author Mieczyslaw Nalewaj <[email protected]> |
|
10
|
|
|
* @copyright 2009 phpSysInfo |
|
11
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
|
12
|
|
|
* @version SVN: $Id: class.ipmiinfo.inc.php 661 2012-08-27 11:26:39Z namiltd $ |
|
13
|
|
|
* @link http://phpsysinfo.sourceforge.net |
|
14
|
|
|
*/ |
|
15
|
|
|
/** |
|
16
|
|
|
* ipmiinfo plugin, which displays all ipmi informations available |
|
17
|
|
|
* |
|
18
|
|
|
* @category PHP |
|
19
|
|
|
* @package PSI_Plugin_ipmiinfo |
|
20
|
|
|
* @author Mieczyslaw Nalewaj <[email protected]> |
|
21
|
|
|
* @copyright 2009 phpSysInfo |
|
22
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
|
23
|
|
|
* @version Release: 3.0 |
|
24
|
|
|
* @link http://phpsysinfo.sourceforge.net |
|
25
|
|
|
*/ |
|
26
|
|
|
class ipmiinfo extends PSI_Plugin |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
private $_lines; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct($enc) |
|
31
|
|
|
{ |
|
32
|
|
|
parent::__construct(__CLASS__, $enc); |
|
33
|
|
|
|
|
34
|
|
|
$this->_lines = array(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* get temperature information |
|
39
|
|
|
* |
|
40
|
|
|
* @return array temperatures in array with label |
|
41
|
|
|
*/ |
|
42
|
|
View Code Duplication |
private function temperatures() |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
|
|
$result = array(); |
|
45
|
|
|
$i = 0; |
|
46
|
|
|
foreach ($this->_lines as $line) { |
|
47
|
|
|
$buffer = preg_split("/\s*\|\s*/", $line); |
|
48
|
|
|
if ($buffer[2] == "degrees C" && $buffer[3] != "na") { |
|
49
|
|
|
$result[$i]['label'] = $buffer[0]; |
|
50
|
|
|
$result[$i]['value'] = $buffer[1]; |
|
51
|
|
|
$result[$i]['state'] = $buffer[3]; |
|
52
|
|
|
if ($buffer[8] != "na") $result[$i]['max'] = $buffer[8]; |
|
53
|
|
|
$i++; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $result; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* get voltages information |
|
62
|
|
|
* |
|
63
|
|
|
* @return array voltage in array with label |
|
64
|
|
|
*/ |
|
65
|
|
|
private function voltages() |
|
66
|
|
|
{ |
|
67
|
|
|
$result = array(); |
|
68
|
|
|
$i = 0; |
|
69
|
|
|
foreach ($this->_lines as $line) { |
|
70
|
|
|
$buffer = preg_split("/\s*\|\s*/", $line); |
|
71
|
|
|
if ($buffer[2] == "Volts" && $buffer[3] != "na") { |
|
72
|
|
|
$result[$i]['label'] = $buffer[0]; |
|
73
|
|
|
$result[$i]['value'] = $buffer[1]; |
|
74
|
|
|
$result[$i]['state'] = $buffer[3]; |
|
75
|
|
|
if ($buffer[5] != "na") $result[$i]['min'] = $buffer[5]; |
|
76
|
|
|
if ($buffer[8] != "na") $result[$i]['max'] = $buffer[8]; |
|
77
|
|
|
$i++; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $result; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* get fans information |
|
86
|
|
|
* |
|
87
|
|
|
* @return array fans in array with label |
|
88
|
|
|
*/ |
|
89
|
|
View Code Duplication |
private function fans() |
|
|
|
|
|
|
90
|
|
|
{ |
|
91
|
|
|
$result = array(); |
|
92
|
|
|
$i = 0; |
|
93
|
|
|
foreach ($this->_lines as $line) { |
|
94
|
|
|
$buffer = preg_split("/\s*\|\s*/", $line); |
|
95
|
|
|
if ($buffer[2] == "RPM" && $buffer[3] != "na") { |
|
96
|
|
|
$result[$i]['label'] = $buffer[0]; |
|
97
|
|
|
$result[$i]['value'] = $buffer[1]; |
|
98
|
|
|
$result[$i]['state'] = $buffer[3]; |
|
99
|
|
|
if ($buffer[8] != "na") $result[$i]['min'] = $buffer[8]; |
|
100
|
|
|
$i++; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return $result; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* get powers information |
|
109
|
|
|
* |
|
110
|
|
|
* @return array misc in array with label |
|
111
|
|
|
*/ |
|
112
|
|
View Code Duplication |
private function powers() |
|
|
|
|
|
|
113
|
|
|
{ |
|
114
|
|
|
$result = array(); |
|
115
|
|
|
$i = 0; |
|
116
|
|
|
foreach ($this->_lines as $line) { |
|
117
|
|
|
$buffer = preg_split("/\s*\|\s*/", $line); |
|
118
|
|
|
if ($buffer[2] == "Watts" && $buffer[3] != "na") { |
|
119
|
|
|
$result[$i]['label'] = $buffer[0]; |
|
120
|
|
|
$result[$i]['value'] = $buffer[1]; |
|
121
|
|
|
$result[$i]['state'] = $buffer[3]; |
|
122
|
|
|
if ($buffer[8] != "na") $result[$i]['max'] = $buffer[8]; |
|
123
|
|
|
$i++; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return $result; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* get currents information |
|
132
|
|
|
* |
|
133
|
|
|
* @return array misc in array with label |
|
134
|
|
|
*/ |
|
135
|
|
View Code Duplication |
private function currents() |
|
|
|
|
|
|
136
|
|
|
{ |
|
137
|
|
|
$result = array(); |
|
138
|
|
|
$i = 0; |
|
139
|
|
|
foreach ($this->_lines as $line) { |
|
140
|
|
|
$buffer = preg_split("/\s*\|\s*/", $line); |
|
141
|
|
|
if ($buffer[2] == "Amps" && $buffer[3] != "na") { |
|
142
|
|
|
$result[$i]['label'] = $buffer[0]; |
|
143
|
|
|
$result[$i]['value'] = $buffer[1]; |
|
144
|
|
|
$result[$i]['state'] = $buffer[3]; |
|
145
|
|
|
if ($buffer[8] != "na") $result[$i]['max'] = $buffer[8]; |
|
146
|
|
|
$i++; |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
return $result; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* get misc information |
|
155
|
|
|
* |
|
156
|
|
|
* @return array misc in array with label |
|
157
|
|
|
*/ |
|
158
|
|
|
private function misc() |
|
159
|
|
|
{ |
|
160
|
|
|
$result = array(); |
|
161
|
|
|
$i = 0; |
|
162
|
|
|
foreach ($this->_lines as $line) { |
|
163
|
|
|
$buffer = preg_split("/\s*\|\s*/", $line); |
|
164
|
|
|
if ($buffer[2] == "discrete" && $buffer[3] != "na") { |
|
165
|
|
|
$result[$i]['label'] = $buffer[0]; |
|
166
|
|
|
$result[$i]['value'] = $buffer[1]; |
|
167
|
|
|
$result[$i]['state'] = $buffer[3]; |
|
168
|
|
|
$i++; |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
return $result; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
public function execute() |
|
176
|
|
|
{ |
|
177
|
|
|
$this->_lines = array(); |
|
178
|
|
|
switch (strtolower(PSI_PLUGIN_IPMIINFO_ACCESS)) { |
|
179
|
|
|
case 'command': |
|
180
|
|
|
$lines = ""; |
|
181
|
|
|
if (CommonFunctions::executeProgram('ipmitool', 'sensor', $lines) && !empty($lines)) |
|
182
|
|
|
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY); |
|
183
|
|
|
break; |
|
184
|
|
|
case 'data': |
|
185
|
|
|
if (CommonFunctions::rfts(APP_ROOT."/data/ipmiinfo.txt", $lines) && !empty($lines)) |
|
186
|
|
|
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY); |
|
187
|
|
|
break; |
|
188
|
|
|
default: |
|
189
|
|
|
$this->error->addConfigError('__construct()', 'PSI_PLUGIN_IPMIINFO_ACCESS'); |
|
|
|
|
|
|
190
|
|
|
break; |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
public function xml() |
|
195
|
|
|
{ |
|
196
|
|
|
if (empty($this->_lines)) |
|
197
|
|
|
return $this->xml->getSimpleXmlElement(); |
|
|
|
|
|
|
198
|
|
|
|
|
199
|
|
|
$arrBuff = $this->temperatures(); |
|
200
|
|
View Code Duplication |
if (sizeof($arrBuff) > 0) { |
|
|
|
|
|
|
201
|
|
|
$temp = $this->xml->addChild("Temperatures"); |
|
202
|
|
|
foreach ($arrBuff as $arrValue) { |
|
203
|
|
|
$item = $temp->addChild('Item'); |
|
204
|
|
|
$item->addAttribute('Label', $arrValue['label']); |
|
205
|
|
|
$item->addAttribute('Value', $arrValue['value']); |
|
206
|
|
|
$item->addAttribute('State', $arrValue['state']); |
|
207
|
|
|
if (isset($arrValue['Max'])) $item->addAttribute('Max', $arrValue['Max']); |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
$arrBuff = $this->voltages(); |
|
211
|
|
|
if (sizeof($arrBuff) > 0) { |
|
212
|
|
|
$volt = $this->xml->addChild('Voltages'); |
|
213
|
|
|
foreach ($arrBuff as $arrValue) { |
|
214
|
|
|
$item = $volt->addChild('Item'); |
|
215
|
|
|
$item->addAttribute('Label', $arrValue['label']); |
|
216
|
|
|
$item->addAttribute('Value', $arrValue['value']); |
|
217
|
|
|
$item->addAttribute('State', $arrValue['state']); |
|
218
|
|
|
if (isset($arrValue['Min'])) $item->addAttribute('Min', $arrValue['min']); |
|
219
|
|
|
if (isset($arrValue['Max'])) $item->addAttribute('Max', $arrValue['max']); |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
$arrBuff = $this->fans(); |
|
223
|
|
View Code Duplication |
if (sizeof($arrBuff) > 0) { |
|
|
|
|
|
|
224
|
|
|
$fan = $this->xml->addChild('Fans'); |
|
225
|
|
|
foreach ($arrBuff as $arrValue) { |
|
226
|
|
|
$item = $fan->addChild('Item'); |
|
227
|
|
|
$item->addAttribute('Label', $arrValue['label']); |
|
228
|
|
|
$item->addAttribute('Value', $arrValue['value']); |
|
229
|
|
|
$item->addAttribute('State', $arrValue['state']); |
|
230
|
|
|
if (isset($arrValue['Min'])) $item->addAttribute('Min', $arrValue['min']); |
|
231
|
|
|
} |
|
232
|
|
|
} |
|
233
|
|
|
$arrBuff = $this->powers(); |
|
234
|
|
View Code Duplication |
if (sizeof($arrBuff) > 0) { |
|
|
|
|
|
|
235
|
|
|
$misc = $this->xml->addChild('Powers'); |
|
236
|
|
|
foreach ($arrBuff as $arrValue) { |
|
237
|
|
|
$item = $misc->addChild('Item'); |
|
238
|
|
|
$item->addAttribute('Label', $arrValue['label']); |
|
239
|
|
|
$item->addAttribute('Value', $arrValue['value']); |
|
240
|
|
|
$item->addAttribute('State', $arrValue['state']); |
|
241
|
|
|
if (isset($arrValue['Max'])) $item->addAttribute('Max', $arrValue['max']); |
|
242
|
|
|
} |
|
243
|
|
|
} |
|
244
|
|
|
$arrBuff = $this->currents(); |
|
245
|
|
View Code Duplication |
if (sizeof($arrBuff) > 0) { |
|
|
|
|
|
|
246
|
|
|
$misc = $this->xml->addChild('Currents'); |
|
247
|
|
|
foreach ($arrBuff as $arrValue) { |
|
248
|
|
|
$item = $misc->addChild('Item'); |
|
249
|
|
|
$item->addAttribute('Label', $arrValue['label']); |
|
250
|
|
|
$item->addAttribute('Value', $arrValue['value']); |
|
251
|
|
|
$item->addAttribute('State', $arrValue['state']); |
|
252
|
|
|
if (isset($arrValue['Max'])) $item->addAttribute('Max', $arrValue['max']); |
|
253
|
|
|
} |
|
254
|
|
|
} |
|
255
|
|
|
$arrBuff = $this->misc(); |
|
256
|
|
|
if (sizeof($arrBuff) > 0) { |
|
257
|
|
|
$misc = $this->xml->addChild('Misc'); |
|
258
|
|
|
foreach ($arrBuff as $arrValue) { |
|
259
|
|
|
$item = $misc->addChild('Item'); |
|
260
|
|
|
$item->addAttribute('Label', $arrValue['label']); |
|
261
|
|
|
$item->addAttribute('Value', $arrValue['value']); |
|
262
|
|
|
$item->addAttribute('State', $arrValue['state']); |
|
263
|
|
|
} |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
return $this->xml->getSimpleXmlElement(); |
|
|
|
|
|
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
} |
|
270
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.