forked from phpsysinfo/phpsysinfo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.ipmi.inc.php
197 lines (190 loc) · 6.14 KB
/
class.ipmi.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/**
* ipmi sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <[email protected]>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.ipmi.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from ipmitool
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <[email protected]>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class IPMI extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private content var through command or data access
*/
public function __construct()
{
parent::__construct();
switch (defined('PSI_SENSOR_IPMI_ACCESS')?strtolower(PSI_SENSOR_IPMI_ACCESS):'command') {
case 'command':
CommonFunctions::executeProgram('ipmitool', 'sensor', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case 'data':
if (CommonFunctions::rfts(APP_ROOT.'/data/ipmi.txt', $lines)) {
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_IPMI_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if ($buffer[2] == "degrees C" && $buffer[3] != "na") {
$dev = new SensorDevice();
$dev->setName($buffer[0]);
$dev->setValue($buffer[1]);
if ($buffer[8] != "na") $dev->setMax($buffer[8]);
switch ($buffer[3]) {
case "nr": $dev->setEvent("Non-Recoverable"); break;
case "cr": $dev->setEvent("Critical"); break;
case "nc": $dev->setEvent("Non-Critical"); break;
}
$this->mbinfo->setMbTemp($dev);
}
}
}
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if ($buffer[2] == "Volts" && $buffer[3] != "na") {
$dev = new SensorDevice();
$dev->setName($buffer[0]);
$dev->setValue($buffer[1]);
if ($buffer[5] != "na") $dev->setMin($buffer[5]);
if ($buffer[8] != "na") $dev->setMax($buffer[8]);
switch ($buffer[3]) {
case "nr": $dev->setEvent("Non-Recoverable"); break;
case "cr": $dev->setEvent("Critical"); break;
case "nc": $dev->setEvent("Non-Critical"); break;
}
$this->mbinfo->setMbVolt($dev);
}
}
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if ($buffer[2] == "RPM" && $buffer[3] != "na") {
$dev = new SensorDevice();
$dev->setName($buffer[0]);
$dev->setValue($buffer[1]);
if ($buffer[8] != "na") {
$dev->setMin($buffer[8]);
} elseif (($buffer[5] != "na") && ($buffer[5]<$buffer[1])) { //max instead min issue
$dev->setMin($buffer[5]);
}
switch ($buffer[3]) {
case "nr": $dev->setEvent("Non-Recoverable"); break;
case "cr": $dev->setEvent("Critical"); break;
case "nc": $dev->setEvent("Non-Critical"); break;
}
$this->mbinfo->setMbFan($dev);
}
}
}
/**
* get power information
*
* @return void
*/
private function _power()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if ($buffer[2] == "Watts" && $buffer[3] != "na") {
$dev = new SensorDevice();
$dev->setName($buffer[0]);
$dev->setValue($buffer[1]);
if ($buffer[8] != "na") $dev->setMax($buffer[8]);
switch ($buffer[3]) {
case "nr": $dev->setEvent("Non-Recoverable"); break;
case "cr": $dev->setEvent("Critical"); break;
case "nc": $dev->setEvent("Non-Critical"); break;
}
$this->mbinfo->setMbPower($dev);
}
}
}
/**
* get current information
*
* @return void
*/
private function _current()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if ($buffer[2] == "Amps" && $buffer[3] != "na") {
$dev = new SensorDevice();
$dev->setName($buffer[0]);
$dev->setValue($buffer[1]);
if ($buffer[8] != "na") $dev->setMax($buffer[8]);
switch ($buffer[3]) {
case "nr": $dev->setEvent("Non-Recoverable"); break;
case "cr": $dev->setEvent("Critical"); break;
case "nc": $dev->setEvent("Non-Critical"); break;
}
$this->mbinfo->setMbCurrent($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
$this->_power();
$this->_current();
}
}