| 2770 |
rexy |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* lmsensor sensor class, getting information from lmsensor
|
|
|
4 |
*
|
|
|
5 |
* PHP version 5
|
|
|
6 |
*
|
|
|
7 |
* @category PHP
|
|
|
8 |
* @package PSI_Sensor
|
|
|
9 |
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
|
|
|
10 |
* @copyright 2009 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 LMSensors extends Sensors
|
|
|
16 |
{
|
|
|
17 |
/**
|
| 3287 |
rexy |
18 |
* array of values
|
| 2770 |
rexy |
19 |
*
|
|
|
20 |
* @var array
|
|
|
21 |
*/
|
| 3287 |
rexy |
22 |
private $_values = array();
|
| 325 |
richard |
23 |
|
| 2770 |
rexy |
24 |
/**
|
|
|
25 |
* fill the private content var through command or data access
|
|
|
26 |
*/
|
|
|
27 |
public function __construct()
|
|
|
28 |
{
|
|
|
29 |
parent::__construct();
|
|
|
30 |
$lines = "";
|
| 3100 |
rexy |
31 |
if ((PSI_OS == 'Linux') && (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT'))) switch (defined('PSI_SENSOR_LMSENSORS_ACCESS')?strtolower(PSI_SENSOR_LMSENSORS_ACCESS):'command') {
|
| 2770 |
rexy |
32 |
case 'command':
|
|
|
33 |
CommonFunctions::executeProgram("sensors", "", $lines);
|
|
|
34 |
break;
|
|
|
35 |
case 'data':
|
| 3100 |
rexy |
36 |
if (!defined('PSI_EMU_PORT')) {
|
|
|
37 |
CommonFunctions::rftsdata('lmsensors.tmp', $lines);
|
|
|
38 |
}
|
| 2770 |
rexy |
39 |
break;
|
|
|
40 |
default:
|
|
|
41 |
$this->error->addConfigError('__construct()', '[sensor_lmsensors] ACCESS');
|
|
|
42 |
}
|
| 325 |
richard |
43 |
|
| 2770 |
rexy |
44 |
if (trim($lines) !== "") {
|
| 3287 |
rexy |
45 |
$lines = str_replace("\r\n", "\n", $lines);
|
| 2770 |
rexy |
46 |
$lines = str_replace(":\n", ":", $lines);
|
|
|
47 |
$lines = str_replace("\n\n", "\n", $lines);
|
| 3287 |
rexy |
48 |
$lines = preg_replace("/\n\s+\(/m", " (", $lines);
|
|
|
49 |
$_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
50 |
|
|
|
51 |
$applearray1 = array(
|
|
|
52 |
"A" => "Ambient",
|
|
|
53 |
"B" => "Battery",
|
|
|
54 |
"C" => "CPU",
|
|
|
55 |
"G" => "GPU",
|
|
|
56 |
"H" => "Harddisk Bay",
|
|
|
57 |
"h" => "Heatpipe",
|
|
|
58 |
"L" => "LCD",
|
|
|
59 |
"M" => "Memory",
|
|
|
60 |
"m" => "Memory Contr.",
|
|
|
61 |
"N" => "Northbridge",
|
|
|
62 |
"O" => "Optical Drive",
|
|
|
63 |
"p" => "Power supply",
|
|
|
64 |
"S" => "Slot",
|
|
|
65 |
"s" => "Slot",
|
|
|
66 |
"W" => "Airport"
|
|
|
67 |
);
|
|
|
68 |
$applearray3 = array(
|
|
|
69 |
"H" => "Heatsink",
|
|
|
70 |
"P" => "Proximity",
|
|
|
71 |
"D" => "Die"
|
|
|
72 |
);
|
|
|
73 |
|
|
|
74 |
$tmpvalue=array();
|
|
|
75 |
$applesmc = false;
|
|
|
76 |
$sname = '';
|
|
|
77 |
foreach ($_lines as $line) {
|
|
|
78 |
if ((trim($line) !== "") && (strpos($line, ':') === false)) {
|
|
|
79 |
if (sizeof($tmpvalue)>0) {
|
|
|
80 |
$this->_values[] = $tmpvalue;
|
|
|
81 |
$tmpvalue = array();
|
|
|
82 |
}
|
|
|
83 |
$sname = trim($line);
|
|
|
84 |
$applesmc = ($sname === "applesmc-isa-0300");
|
|
|
85 |
if (preg_match('/^([^-]+)-/', $sname, $snamebuf)) {
|
|
|
86 |
$sname = $snamebuf[1];
|
|
|
87 |
} else {
|
|
|
88 |
$sname = '';
|
|
|
89 |
}
|
|
|
90 |
} else {
|
|
|
91 |
if (preg_match("/^(.+):(.+)$/", trim($line), $data) && ($data[1]!=="Adapter")) {
|
|
|
92 |
if ($applesmc && (strlen($data[1]) == 4) && ($data[1][0] == "T")) {
|
|
|
93 |
if (isset($applearray1[$data[1][1]])) $data[1] .= " ".$applearray1[$data[1][1]];
|
|
|
94 |
if (isset($applearray3[$data[1][3]])) $data[1] .= " ".$applearray3[$data[1][3]];
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
$arrtemp=array();
|
|
|
98 |
if ($sname !== "" ) {
|
|
|
99 |
$arrtemp["name"] = $data[1]." (".$sname.")";
|
|
|
100 |
} else {
|
|
|
101 |
$arrtemp["name"] = $data[1];
|
|
|
102 |
}
|
|
|
103 |
if (preg_match("/^([^\(]+)\s+\(/", $data[2], $tmp) || preg_match("/^(.+)\s+ALARM$/", $data[2], $tmp)) {
|
|
|
104 |
if (($tmp[1] = trim($tmp[1])) == "") {
|
|
|
105 |
$arrtemp["value"] = "ALARM";
|
|
|
106 |
} else {
|
|
|
107 |
$arrtemp["value"] = $tmp[1];
|
|
|
108 |
}
|
|
|
109 |
if (preg_match("/\s(ALARM)\s*$/", $data[2]) || preg_match("/\s(ALARM)\s+\(/", $data[2]) || preg_match("/\s(ALARM)\s+sensor\s+=/", $data[2])) {
|
|
|
110 |
$arrtemp["alarm"]="ALARM";
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
if (preg_match_all("/\(([^\)]+\s+=\s+[^\)]+)\)/", $data[2], $tmp2)) foreach ($tmp2[1] as $tmp3) {
|
|
|
114 |
$arrtmp3 = preg_split('/,/', $tmp3);
|
|
|
115 |
foreach ($arrtmp3 as $tmp4) if (preg_match("/^(\S+)\s+=\s+(.*)$/", trim($tmp4), $tmp5)) {
|
|
|
116 |
$arrtemp[$tmp5[1]]=trim($tmp5[2]);
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
} else {
|
|
|
120 |
$arrtemp["value"] = trim($data[2]);
|
|
|
121 |
}
|
|
|
122 |
$tmpvalue[] = $arrtemp;
|
|
|
123 |
}
|
|
|
124 |
}
|
|
|
125 |
}
|
|
|
126 |
if (sizeof($tmpvalue)>0) $this->_values[] = $tmpvalue;
|
| 2770 |
rexy |
127 |
}
|
|
|
128 |
}
|
| 325 |
richard |
129 |
|
| 2770 |
rexy |
130 |
/**
|
|
|
131 |
* get temperature information
|
|
|
132 |
*
|
|
|
133 |
* @return void
|
|
|
134 |
*/
|
|
|
135 |
private function _temperature()
|
|
|
136 |
{
|
| 3287 |
rexy |
137 |
foreach ($this->_values as $sensors) foreach ($sensors as $sensor){
|
|
|
138 |
if (isset($sensor["value"])) {
|
|
|
139 |
$limit = "";
|
|
|
140 |
if (preg_match("/^\+?(-?[\d\.]+)[^\w\r\n\t]+C$/", $sensor["value"], $tmpbuf) ||
|
|
|
141 |
((isset($sensor[$limit="crit"]) || isset($sensor[$limit="high"]) || isset($sensor[$limit="hyst"])) && preg_match("/^\+?(-?[\d\.]+)[^\w\r\n\t]+C$/", $sensor[$limit]))) {
|
|
|
142 |
$dev = new SensorDevice();
|
|
|
143 |
$dev->setName($sensor["name"]);
|
|
|
144 |
if ($limit != "") {
|
|
|
145 |
$dev->setValue($sensor["value"]);
|
|
|
146 |
$dev->setEvent("FAULT");
|
| 2770 |
rexy |
147 |
} else {
|
| 3287 |
rexy |
148 |
if ($tmpbuf[1] == -110.8) {
|
|
|
149 |
$dev->setValue("FAULT");
|
|
|
150 |
$dev->setEvent("FAULT");
|
|
|
151 |
} else {
|
|
|
152 |
$dev->setValue(floatval($tmpbuf[1]));
|
|
|
153 |
if (isset($sensor["alarm"])) $dev->setEvent("ALARM");
|
|
|
154 |
}
|
| 2770 |
rexy |
155 |
}
|
| 325 |
richard |
156 |
|
| 3287 |
rexy |
157 |
if (isset($sensor[$limit="crit"]) && preg_match("/^\+?(-?[\d\.]+)[^\w\r\n\t]+C$/", $sensor[$limit], $tmpbuf) && (($tmpbuf[1]=floatval($tmpbuf[1])) > 0)) {
|
|
|
158 |
$dev->setMax(floatval($tmpbuf[1]));
|
|
|
159 |
} elseif (isset($sensor[$limit="high"]) && preg_match("/^\+?(-?[\d\.]+)[^\w\r\n\t]+C$/", $sensor[$limit], $tmpbuf) && (($tmpbuf[1]=floatval($tmpbuf[1])) > 0) && ($tmpbuf[1]<65261.8)) {
|
|
|
160 |
$dev->setMax(floatval($tmpbuf[1]));
|
| 2770 |
rexy |
161 |
}
|
| 325 |
richard |
162 |
|
| 3287 |
rexy |
163 |
$this->mbinfo->setMbTemp($dev);
|
| 2770 |
rexy |
164 |
}
|
|
|
165 |
}
|
|
|
166 |
}
|
|
|
167 |
}
|
| 325 |
richard |
168 |
|
| 2770 |
rexy |
169 |
/**
|
|
|
170 |
* get fan information
|
|
|
171 |
*
|
|
|
172 |
* @return void
|
|
|
173 |
*/
|
|
|
174 |
private function _fans()
|
|
|
175 |
{
|
| 3287 |
rexy |
176 |
foreach ($this->_values as $sensors) foreach ($sensors as $sensor){
|
|
|
177 |
if (isset($sensor["value"])) {
|
|
|
178 |
$limit = "";
|
|
|
179 |
if (preg_match("/^(\d+) RPM$/", $sensor["value"], $tmpbuf) ||
|
|
|
180 |
((isset($sensor[$limit="min"]) || isset($sensor[$limit="max"])) && preg_match("/^(\d+) RPM$/", $sensor[$limit]))) {
|
|
|
181 |
$dev = new SensorDevice();
|
|
|
182 |
$dev->setName($sensor["name"]);
|
|
|
183 |
if ($limit != "") {
|
|
|
184 |
$dev->setValue($sensor["value"]);
|
|
|
185 |
$dev->setEvent("FAULT");
|
| 2770 |
rexy |
186 |
} else {
|
| 3287 |
rexy |
187 |
$dev->setValue($tmpbuf[1]);
|
| 2770 |
rexy |
188 |
}
|
| 3287 |
rexy |
189 |
if (isset($sensor["alarm"])) $dev->setEvent("ALARM");
|
|
|
190 |
|
|
|
191 |
if (isset($sensor[$limit="min"]) && preg_match("/^(\d+) RPM$/", $sensor[$limit], $tmpbuf) && ($tmpbuf[1] > 0)) {
|
|
|
192 |
$dev->setMin($tmpbuf[1]);
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
$this->mbinfo->setMbFan($dev);
|
| 2770 |
rexy |
196 |
}
|
|
|
197 |
}
|
| 325 |
richard |
198 |
}
|
|
|
199 |
}
|
|
|
200 |
|
| 3287 |
rexy |
201 |
|
| 2770 |
rexy |
202 |
/**
|
|
|
203 |
* get voltage information
|
|
|
204 |
*
|
|
|
205 |
* @return void
|
|
|
206 |
*/
|
|
|
207 |
private function _voltage()
|
|
|
208 |
{
|
| 3287 |
rexy |
209 |
foreach ($this->_values as $sensors) foreach ($sensors as $sensor){
|
|
|
210 |
if (isset($sensor["value"])) {
|
|
|
211 |
$limit = "";
|
|
|
212 |
if (preg_match("/^\+?(-?[\d\.]+) (m?)V$/", $sensor["value"], $tmpbuf) ||
|
|
|
213 |
((isset($sensor[$limit="min"]) || isset($sensor[$limit="max"])) && preg_match("/^\+?(-?[\d\.]+) (m?)V$/", $sensor[$limit]))) {
|
|
|
214 |
$dev = new SensorDevice();
|
|
|
215 |
$dev->setName($sensor["name"]);
|
|
|
216 |
if ($limit != "") {
|
|
|
217 |
$dev->setValue($sensor["value"]);
|
|
|
218 |
$dev->setEvent("FAULT");
|
| 2770 |
rexy |
219 |
} else {
|
| 3287 |
rexy |
220 |
if ($tmpbuf[2] == "m") {
|
|
|
221 |
$dev->setValue(floatval($tmpbuf[1])/1000);
|
|
|
222 |
} else {
|
|
|
223 |
$dev->setValue(floatval($tmpbuf[1]));
|
|
|
224 |
}
|
| 2770 |
rexy |
225 |
}
|
| 3287 |
rexy |
226 |
if (isset($sensor["alarm"])) $dev->setEvent("ALARM");
|
|
|
227 |
|
|
|
228 |
if (isset($sensor[$limit="min"]) && preg_match("/^\+?(-?[\d\.]+) (m?)V$/", $sensor[$limit], $tmpbuf)) {
|
|
|
229 |
$dev->setMin(floatval($tmpbuf[1]));
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
if (isset($sensor[$limit="max"]) && preg_match("/^\+?(-?[\d\.]+) (m?)V$/", $sensor[$limit], $tmpbuf)) {
|
|
|
233 |
$dev->setMax(floatval($tmpbuf[1]));
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
$this->mbinfo->setMbVolt($dev);
|
| 2770 |
rexy |
237 |
}
|
|
|
238 |
}
|
|
|
239 |
}
|
| 325 |
richard |
240 |
}
|
|
|
241 |
|
| 2770 |
rexy |
242 |
/**
|
|
|
243 |
* get power information
|
|
|
244 |
*
|
|
|
245 |
* @return void
|
|
|
246 |
*/
|
|
|
247 |
private function _power()
|
|
|
248 |
{
|
| 3287 |
rexy |
249 |
foreach ($this->_values as $sensors) foreach ($sensors as $sensor){
|
|
|
250 |
if (isset($sensor["value"])) {
|
|
|
251 |
$limit = "";
|
|
|
252 |
if (preg_match("/^\+?(-?[\d\.]+) W$/", $sensor["value"], $tmpbuf) ||
|
|
|
253 |
(isset($sensor[$limit="crit"]) && preg_match("/^\+?(-?[\d\.]+) W$/", $sensor[$limit]))) {
|
|
|
254 |
$dev = new SensorDevice();
|
|
|
255 |
$dev->setName($sensor["name"]);
|
|
|
256 |
if ($limit != "") {
|
|
|
257 |
$dev->setValue($sensor["value"]);
|
|
|
258 |
$dev->setEvent("FAULT");
|
| 2770 |
rexy |
259 |
} else {
|
| 3287 |
rexy |
260 |
$dev->setValue(floatval($tmpbuf[1]));
|
| 2770 |
rexy |
261 |
}
|
| 3287 |
rexy |
262 |
if (isset($sensor["alarm"])) $dev->setEvent("ALARM");
|
| 325 |
richard |
263 |
|
| 3287 |
rexy |
264 |
if (isset($sensor[$limit="crit"]) && preg_match("/^\+?(-?[\d\.]+) W$/", $sensor[$limit], $tmpbuf)) {
|
|
|
265 |
$dev->setMax(floatval($tmpbuf[1]));
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
$this->mbinfo->setMbPower($dev);
|
| 2770 |
rexy |
269 |
}
|
|
|
270 |
}
|
|
|
271 |
}
|
| 325 |
richard |
272 |
}
|
|
|
273 |
|
| 3287 |
rexy |
274 |
|
| 2770 |
rexy |
275 |
/**
|
|
|
276 |
* get current information
|
|
|
277 |
*
|
|
|
278 |
* @return void
|
|
|
279 |
*/
|
|
|
280 |
private function _current()
|
|
|
281 |
{
|
| 3287 |
rexy |
282 |
foreach ($this->_values as $sensors) foreach ($sensors as $sensor){
|
|
|
283 |
if (isset($sensor["value"])) {
|
|
|
284 |
$limit = "";
|
|
|
285 |
if (preg_match("/^\+?(-?[\d\.]+) A$/", $sensor["value"], $tmpbuf) ||
|
|
|
286 |
(isset($sensor[$limit="crit"]) && preg_match("/^\+?(-?[\d\.]+) A$/", $sensor[$limit]))) {
|
|
|
287 |
$dev = new SensorDevice();
|
|
|
288 |
$dev->setName($sensor["name"]);
|
|
|
289 |
if ($limit != "") {
|
|
|
290 |
$dev->setValue($sensor["value"]);
|
|
|
291 |
$dev->setEvent("FAULT");
|
| 2770 |
rexy |
292 |
} else {
|
| 3287 |
rexy |
293 |
$dev->setValue(floatval($tmpbuf[1]));
|
| 2770 |
rexy |
294 |
}
|
| 3287 |
rexy |
295 |
if (isset($sensor["alarm"])) $dev->setEvent("ALARM");
|
|
|
296 |
|
|
|
297 |
if (isset($sensor[$limit="min"]) && preg_match("/^\+?(-?[\d\.]+) A$/", $sensor[$limit], $tmpbuf)) {
|
|
|
298 |
$dev->setMin(floatval($tmpbuf[1]));
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
if (isset($sensor[$limit="max"]) && preg_match("/^\+?(-?[\d\.]+) A$/", $sensor[$limit], $tmpbuf)) {
|
|
|
302 |
$dev->setMax(floatval($tmpbuf[1]));
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
$this->mbinfo->setMbCurrent($dev);
|
| 2770 |
rexy |
306 |
}
|
|
|
307 |
}
|
|
|
308 |
}
|
| 325 |
richard |
309 |
}
|
|
|
310 |
|
| 2770 |
rexy |
311 |
/**
|
|
|
312 |
* get other information
|
|
|
313 |
*
|
|
|
314 |
* @return void
|
|
|
315 |
*/
|
|
|
316 |
private function _other()
|
|
|
317 |
{
|
| 3287 |
rexy |
318 |
foreach ($this->_values as $sensors) foreach ($sensors as $sensor){
|
|
|
319 |
if (isset($sensor["value"])) {
|
|
|
320 |
if ((preg_match("/^[^\-\+\d]/", $sensor["value"]) || preg_match("/^\d+$/", $sensor["value"])) && ($sensor["value"] !== 'failed') &&
|
|
|
321 |
!isset($sensor[$limit="min"]) && !isset($sensor[$limit="max"]) && !isset($sensor[$limit="crit"]) && !isset($sensor[$limit="high"]) && !isset($sensor[$limit="hyst"])) {
|
|
|
322 |
$dev = new SensorDevice();
|
|
|
323 |
$dev->setName($sensor["name"]);
|
|
|
324 |
$dev->setValue($sensor["value"]);
|
|
|
325 |
if (isset($sensor["alarm"])) $dev->setEvent("ALARM");
|
|
|
326 |
|
|
|
327 |
$this->mbinfo->setMbOther($dev);
|
| 2770 |
rexy |
328 |
}
|
|
|
329 |
}
|
| 325 |
richard |
330 |
}
|
|
|
331 |
}
|
|
|
332 |
|
| 2770 |
rexy |
333 |
/**
|
|
|
334 |
* get the information
|
|
|
335 |
*
|
|
|
336 |
* @see PSI_Interface_Sensor::build()
|
|
|
337 |
*
|
| 3037 |
rexy |
338 |
* @return void
|
| 2770 |
rexy |
339 |
*/
|
|
|
340 |
public function build()
|
|
|
341 |
{
|
|
|
342 |
$this->_temperature();
|
| 3287 |
rexy |
343 |
$this->_fans();
|
| 2770 |
rexy |
344 |
$this->_voltage();
|
|
|
345 |
$this->_power();
|
|
|
346 |
$this->_current();
|
|
|
347 |
$this->_other();
|
| 325 |
richard |
348 |
}
|
|
|
349 |
}
|