1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ipmiutil sensor class |
4
|
|
|
* |
5
|
|
|
* PHP version 5 |
6
|
|
|
* |
7
|
|
|
* @category PHP |
8
|
|
|
* @package PSI_Sensor |
9
|
|
|
* @author Michael Cramer <[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.ipmiutil.inc.php 661 2012-08-27 11:26:39Z namiltd $ |
13
|
|
|
* @link http://phpsysinfo.sourceforge.net |
14
|
|
|
*/ |
15
|
|
|
/** |
16
|
|
|
* getting information from ipmi-sensors |
17
|
|
|
* |
18
|
|
|
* @category PHP |
19
|
|
|
* @package PSI_Sensor |
20
|
|
|
* @author Michael Cramer <[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 IPMIutil extends Sensors |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* content to parse |
30
|
|
|
* |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
private $_lines = array(); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* fill the private content var through command or data access |
37
|
|
|
*/ |
38
|
|
View Code Duplication |
public function __construct() |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
parent::__construct(); |
41
|
|
|
switch (defined('PSI_SENSOR_IPMIUTIL_ACCESS')?strtolower(PSI_SENSOR_IPMIUTIL_ACCESS):'command') { |
42
|
|
|
case 'command': |
43
|
|
|
CommonFunctions::executeProgram('ipmiutil', 'sensor -stw', $lines); |
44
|
|
|
$this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY); |
45
|
|
|
break; |
46
|
|
|
case 'data': |
47
|
|
|
if (CommonFunctions::rfts(APP_ROOT.'/data/ipmiutil.txt', $lines)) { |
48
|
|
|
$this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY); |
49
|
|
|
} |
50
|
|
|
break; |
51
|
|
|
default: |
52
|
|
|
$this->error->addConfigError('__construct()', 'PSI_SENSOR_IPMIUTIL_ACCESS'); |
53
|
|
|
break; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* get temperature information |
59
|
|
|
* |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
|
View Code Duplication |
private function _temperature() |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
foreach ($this->_lines as $line) { |
65
|
|
|
$buffer = preg_split("/\s*\|\s*/", $line); |
66
|
|
|
if (isset($buffer[2]) && $buffer[2] == "Temperature" && $buffer[1] == "Full" && isset($buffer[6]) && preg_match("/^(\S+)\sC$/", $buffer[6], $value)) { |
67
|
|
|
$dev = new SensorDevice(); |
68
|
|
|
$dev->setName($buffer[4]); |
69
|
|
|
$dev->setValue($value[1]); |
70
|
|
|
if (isset($buffer[7]) && $buffer[7] == "Thresholds") { |
71
|
|
|
if ((isset($buffer[8]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[8], $limits)) |
72
|
|
|
||(isset($buffer[9]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[9], $limits)) |
73
|
|
|
||(isset($buffer[10]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[10], $limits)) |
74
|
|
|
||(isset($buffer[11]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[11], $limits))) { |
75
|
|
|
$dev->setMax($limits[1]); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
if ($buffer[5] != "OK") $dev->setEvent($buffer[5]); |
79
|
|
|
$this->mbinfo->setMbTemp($dev); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* get voltage information |
86
|
|
|
* |
87
|
|
|
* @return void |
88
|
|
|
*/ |
89
|
|
|
private function _voltage() |
90
|
|
|
{ |
91
|
|
|
foreach ($this->_lines as $line) { |
92
|
|
|
$buffer = preg_split("/\s*\|\s*/", $line); |
93
|
|
|
if (isset($buffer[2]) && $buffer[2] == "Voltage" && $buffer[1] == "Full" && isset($buffer[6]) && preg_match("/^(\S+)\sV$/", $buffer[6], $value)) { |
94
|
|
|
$dev = new SensorDevice(); |
95
|
|
|
$dev->setName($buffer[4]); |
96
|
|
|
$dev->setValue($value[1]); |
97
|
|
View Code Duplication |
if (isset($buffer[7]) && $buffer[7] == "Thresholds") { |
|
|
|
|
98
|
|
|
if ((isset($buffer[8]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[8], $limits)) |
99
|
|
|
||(isset($buffer[9]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[9], $limits)) |
100
|
|
|
||(isset($buffer[10]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[10], $limits)) |
101
|
|
|
||(isset($buffer[11]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[11], $limits))) { |
102
|
|
|
$dev->setMin($limits[1]); |
103
|
|
|
} |
104
|
|
|
if ((isset($buffer[8]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[8], $limits)) |
105
|
|
|
||(isset($buffer[9]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[9], $limits)) |
106
|
|
|
||(isset($buffer[10]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[10], $limits)) |
107
|
|
|
||(isset($buffer[11]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[11], $limits))) { |
108
|
|
|
$dev->setMax($limits[1]); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
if ($buffer[5] != "OK") $dev->setEvent($buffer[5]); |
112
|
|
|
$this->mbinfo->setMbVolt($dev); |
|
|
|
|
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* get fan information |
119
|
|
|
* |
120
|
|
|
* @return void |
121
|
|
|
*/ |
122
|
|
|
private function _fans() |
123
|
|
|
{ |
124
|
|
|
foreach ($this->_lines as $line) { |
125
|
|
|
$buffer = preg_split("/\s*\|\s*/", $line); |
126
|
|
|
if (isset($buffer[2]) && $buffer[2] == "Fan" && $buffer[1] == "Full" && isset($buffer[6]) && preg_match("/^(\S+)\sRPM$/", $buffer[6], $value)) { |
127
|
|
|
$dev = new SensorDevice(); |
128
|
|
|
$dev->setName($buffer[4]); |
129
|
|
|
$dev->setValue($value[1]); |
130
|
|
|
if (isset($buffer[7]) && $buffer[7] == "Thresholds") { |
131
|
|
View Code Duplication |
if ((isset($buffer[8]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[8], $limits)) |
|
|
|
|
132
|
|
|
||(isset($buffer[9]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[9], $limits)) |
133
|
|
|
||(isset($buffer[10]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[10], $limits)) |
134
|
|
|
||(isset($buffer[11]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[11], $limits))) { |
135
|
|
|
$dev->setMin($limits[1]); |
136
|
|
|
} elseif ((isset($buffer[8]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[8], $limits)) |
137
|
|
|
||(isset($buffer[9]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[9], $limits)) |
138
|
|
|
||(isset($buffer[10]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[10], $limits)) |
139
|
|
|
||(isset($buffer[11]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[11], $limits))) { |
140
|
|
|
if ($limits[1]<$value[1]) {//max instead min issue |
141
|
|
|
$dev->setMin($limits[1]); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
if ($buffer[5] != "OK") $dev->setEvent($buffer[5]); |
146
|
|
|
$this->mbinfo->setMbFan($dev); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* get power information |
153
|
|
|
* |
154
|
|
|
* @return void |
155
|
|
|
*/ |
156
|
|
View Code Duplication |
private function _power() |
|
|
|
|
157
|
|
|
{ |
158
|
|
|
foreach ($this->_lines as $line) { |
159
|
|
|
$buffer = preg_split("/\s*\|\s*/", $line); |
160
|
|
|
if (isset($buffer[2]) && $buffer[2] == "Current" && $buffer[1] == "Full" && isset($buffer[6]) && preg_match("/^(\S+)\sW$/", $buffer[6], $value)) { |
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
|
|
View Code Duplication |
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" && $buffer[1] == "Full" && isset($buffer[6]) && preg_match("/^(\S+)\sA$/", $buffer[6], $value)) { |
188
|
|
|
$dev = new SensorDevice(); |
189
|
|
|
$dev->setName($buffer[4]); |
190
|
|
|
$dev->setValue($value[1]); |
191
|
|
|
if (isset($buffer[7]) && $buffer[7] == "Thresholds") { |
192
|
|
|
if ((isset($buffer[8]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[8], $limits)) |
193
|
|
|
||(isset($buffer[9]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[9], $limits)) |
194
|
|
|
||(isset($buffer[10]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[10], $limits)) |
195
|
|
|
||(isset($buffer[11]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[11], $limits))) { |
196
|
|
|
$dev->setMax($limits[1]); |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
if ($buffer[5] != "OK") $dev->setEvent($buffer[5]); |
200
|
|
|
$this->mbinfo->setMbCurrent($dev); |
|
|
|
|
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* get the information |
207
|
|
|
* |
208
|
|
|
* @see PSI_Interface_Sensor::build() |
209
|
|
|
* |
210
|
|
|
* @return Void |
211
|
|
|
*/ |
212
|
|
|
public function build() |
213
|
|
|
{ |
214
|
|
|
$this->_temperature(); |
215
|
|
|
$this->_voltage(); |
216
|
|
|
$this->_fans(); |
217
|
|
|
$this->_power(); |
218
|
|
|
$this->_current(); |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|
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.