|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* HP-UX System Class |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @category PHP |
|
8
|
|
|
* @package PSI HPUX OS class |
|
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.HPUX.inc.php 596 2012-07-05 19:37:48Z namiltd $ |
|
13
|
|
|
* @link http://phpsysinfo.sourceforge.net |
|
14
|
|
|
*/ |
|
15
|
|
|
/** |
|
16
|
|
|
* HP-UX sysinfo class |
|
17
|
|
|
* get all the required information from HP-UX system |
|
18
|
|
|
* |
|
19
|
|
|
* @category PHP |
|
20
|
|
|
* @package PSI HPUX OS class |
|
21
|
|
|
* @author Michael Cramer <[email protected]> |
|
22
|
|
|
* @copyright 2009 phpSysInfo |
|
23
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
|
24
|
|
|
* @version Release: 3.0 |
|
25
|
|
|
* @link http://phpsysinfo.sourceforge.net |
|
26
|
|
|
*/ |
|
27
|
|
|
class HPUX extends OS |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Virtual Host Name |
|
31
|
|
|
* |
|
32
|
|
|
* @return void |
|
33
|
|
|
*/ |
|
34
|
|
View Code Duplication |
private function _hostname() |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
if (PSI_USE_VHOST === true) { |
|
37
|
|
|
$this->sys->setHostname(getenv('SERVER_NAME')); |
|
38
|
|
|
} else { |
|
39
|
|
|
if (CommonFunctions::executeProgram('hostname', '', $ret)) { |
|
40
|
|
|
$this->sys->setHostname($ret); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* HP-UX Version |
|
47
|
|
|
* |
|
48
|
|
|
* @return void |
|
49
|
|
|
*/ |
|
50
|
|
|
private function _kernel() |
|
51
|
|
|
{ |
|
52
|
|
|
if (CommonFunctions::executeProgram('uname', '-srvm', $ret)) { |
|
53
|
|
|
$this->sys->setKernel($ret); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* UpTime |
|
59
|
|
|
* time the system is running |
|
60
|
|
|
* |
|
61
|
|
|
* @return void |
|
62
|
|
|
*/ |
|
63
|
|
View Code Duplication |
private function _uptime() |
|
|
|
|
|
|
64
|
|
|
{ |
|
65
|
|
|
if (CommonFunctions::executeProgram('uptime', '', $buf)) { |
|
66
|
|
|
if (preg_match("/up (\d+) days,\s*(\d+):(\d+),/", $buf, $ar_buf)) { |
|
67
|
|
|
$min = $ar_buf[3]; |
|
68
|
|
|
$hours = $ar_buf[2]; |
|
69
|
|
|
$days = $ar_buf[1]; |
|
70
|
|
|
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Processor Load |
|
77
|
|
|
* optionally create a loadbar |
|
78
|
|
|
* |
|
79
|
|
|
* @return void |
|
80
|
|
|
*/ |
|
81
|
|
View Code Duplication |
private function _loadavg() |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
if (CommonFunctions::executeProgram('uptime', '', $buf)) { |
|
84
|
|
|
if (preg_match("/average: (.*), (.*), (.*)$/", $buf, $ar_buf)) { |
|
85
|
|
|
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* CPU information |
|
92
|
|
|
* All of the tags here are highly architecture dependant |
|
93
|
|
|
* |
|
94
|
|
|
* @return void |
|
95
|
|
|
*/ |
|
96
|
|
|
private function _cpuinfo() |
|
97
|
|
|
{ |
|
98
|
|
|
if (CommonFunctions::rfts('/proc/cpuinfo', $bufr)) { |
|
99
|
|
|
$processors = preg_split('/\s?\n\s?\n/', trim($bufr)); |
|
100
|
|
|
foreach ($processors as $processor) { |
|
101
|
|
|
$dev = new CpuDevice(); |
|
102
|
|
|
$details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY); |
|
103
|
|
|
foreach ($details as $detail) { |
|
104
|
|
|
$arrBuff = preg_split('/\s+:\s+/', trim($detail)); |
|
105
|
|
|
if (count($arrBuff) == 2) { |
|
106
|
|
|
switch (strtolower($arrBuff[0])) { |
|
107
|
|
|
case 'model name': |
|
108
|
|
|
case 'cpu': |
|
109
|
|
|
$dev->setModel($arrBuff[1]); |
|
110
|
|
|
break; |
|
111
|
|
|
case 'cpu mhz': |
|
112
|
|
|
case 'clock': |
|
113
|
|
|
$dev->setCpuSpeed($arrBuff[1]); |
|
114
|
|
|
break; |
|
115
|
|
|
case 'cycle frequency [hz]': |
|
116
|
|
|
$dev->setCpuSpeed($arrBuff[1] / 1000000); |
|
117
|
|
|
break; |
|
118
|
|
|
case 'cpu0clktck': |
|
119
|
|
|
$dev->setCpuSpeed(hexdec($arrBuff[1]) / 1000000); // Linux sparc64 |
|
120
|
|
|
break; |
|
121
|
|
|
case 'l2 cache': |
|
122
|
|
|
case 'cache size': |
|
123
|
|
|
$dev->setCache(preg_replace("/[a-zA-Z]/", "", $arrBuff[1]) * 1024); |
|
124
|
|
|
break; |
|
125
|
|
|
case 'bogomips': |
|
126
|
|
|
case 'cpu0bogo': |
|
127
|
|
|
$dev->setBogomips($arrBuff[1]); |
|
128
|
|
|
break; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* PCI devices |
|
138
|
|
|
* |
|
139
|
|
|
* @return void |
|
140
|
|
|
*/ |
|
141
|
|
|
private function _pci() |
|
142
|
|
|
{ |
|
143
|
|
|
if (CommonFunctions::rfts('/proc/pci', $bufr)) { |
|
144
|
|
|
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
|
145
|
|
View Code Duplication |
foreach ($bufe as $buf) { |
|
|
|
|
|
|
146
|
|
|
if (preg_match('/^\s*Bus\s/', $buf)) { |
|
147
|
|
|
$device = true; |
|
148
|
|
|
continue; |
|
149
|
|
|
} |
|
150
|
|
|
if ($device) { |
|
|
|
|
|
|
151
|
|
|
$dev = new HWDevice(); |
|
152
|
|
|
$dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($buf))); |
|
153
|
|
|
$this->sys->setPciDevices($dev); |
|
154
|
|
|
/* |
|
|
|
|
|
|
155
|
|
|
list($key, $value) = preg_split('/: /', $buf, 2); |
|
156
|
|
|
if (!preg_match('/bridge/i', $key) && !preg_match('/USB/i', $key)) { |
|
157
|
|
|
$dev = new HWDevice(); |
|
158
|
|
|
$dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($value))); |
|
159
|
|
|
$this->sys->setPciDevices($dev); |
|
160
|
|
|
} |
|
161
|
|
|
*/ |
|
162
|
|
|
$device = false; |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* IDE devices |
|
170
|
|
|
* |
|
171
|
|
|
* @return void |
|
172
|
|
|
*/ |
|
173
|
|
|
private function _ide() |
|
174
|
|
|
{ |
|
175
|
|
|
$bufd = CommonFunctions::gdc('/proc/ide', false); |
|
176
|
|
|
foreach ($bufd as $file) { |
|
177
|
|
|
if (preg_match('/^hd/', $file)) { |
|
178
|
|
|
$dev = new HWDevice(); |
|
179
|
|
|
$dev->setName(trim($file)); |
|
180
|
|
View Code Duplication |
if (CommonFunctions::rfts("/proc/ide/".$file."/media", $buf, 1)) { |
|
|
|
|
|
|
181
|
|
|
if (trim($buf) == 'disk') { |
|
182
|
|
|
if (CommonFunctions::rfts("/proc/ide/".$file."/capacity", $buf, 1, 4096, false)) { |
|
183
|
|
|
$dev->setCapacity(trim($buf) * 512 / 1024); |
|
184
|
|
|
} |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
$this->sys->setIdeDevices($dev); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* SCSI devices |
|
194
|
|
|
* |
|
195
|
|
|
* @return void |
|
196
|
|
|
*/ |
|
197
|
|
|
private function _scsi() |
|
198
|
|
|
{ |
|
199
|
|
|
$get_type = false; |
|
200
|
|
|
if (CommonFunctions::rfts('/proc/scsi/scsi', $bufr, 0, 4096, PSI_DEBUG)) { |
|
201
|
|
|
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
|
202
|
|
View Code Duplication |
foreach ($bufe as $buf) { |
|
|
|
|
|
|
203
|
|
|
if (preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $dev)) { |
|
204
|
|
|
$get_type = true; |
|
205
|
|
|
continue; |
|
206
|
|
|
} |
|
207
|
|
|
if ($get_type) { |
|
208
|
|
|
preg_match('/Type:\s+(\S+)/i', $buf, $dev_type); |
|
209
|
|
|
$dev = new HWDevice(); |
|
210
|
|
|
$dev->setName($dev[1].' '.$dev[2].' ('.$dev_type[1].')'); |
|
211
|
|
|
$this->sys->setScsiDevices($dev); |
|
212
|
|
|
$get_type = false; |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
} |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* USB devices |
|
220
|
|
|
* |
|
221
|
|
|
* @return void |
|
222
|
|
|
*/ |
|
223
|
|
|
private function _usb() |
|
224
|
|
|
{ |
|
225
|
|
|
if (CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) { |
|
226
|
|
|
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
|
227
|
|
|
foreach ($bufe as $buf) { |
|
228
|
|
|
if (preg_match('/^T/', $buf)) { |
|
229
|
|
|
$devnum += 1; |
|
|
|
|
|
|
230
|
|
|
$results[$devnum] = ""; |
|
|
|
|
|
|
231
|
|
|
} elseif (preg_match('/^S:/', $buf)) { |
|
232
|
|
|
list($key, $value) = preg_split('/: /', $buf, 2); |
|
233
|
|
|
list($key, $value2) = preg_split('/=/', $value, 2); |
|
234
|
|
|
if (trim($key) != "SerialNumber") { |
|
235
|
|
|
$results[$devnum] .= " ".trim($value2); |
|
|
|
|
|
|
236
|
|
|
} |
|
237
|
|
|
} |
|
238
|
|
|
} |
|
239
|
|
|
foreach ($results as $var) { |
|
240
|
|
|
$dev = new HWDevice(); |
|
241
|
|
|
$dev->setName($var); |
|
242
|
|
|
$this->sys->setUsbDevices($dev); |
|
243
|
|
|
} |
|
244
|
|
|
} |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* Network devices |
|
249
|
|
|
* includes also rx/tx bytes |
|
250
|
|
|
* |
|
251
|
|
|
* @return void |
|
252
|
|
|
*/ |
|
253
|
|
View Code Duplication |
private function _network() |
|
|
|
|
|
|
254
|
|
|
{ |
|
255
|
|
|
if (CommonFunctions::executeProgram('netstat', '-ni | tail -n +2', $netstat)) { |
|
256
|
|
|
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY); |
|
257
|
|
|
foreach ($lines as $line) { |
|
258
|
|
|
$ar_buf = preg_split("/\s+/", $line); |
|
259
|
|
|
if (! empty($ar_buf[0]) && ! empty($ar_buf[3])) { |
|
260
|
|
|
$dev = new NetDevice(); |
|
261
|
|
|
$dev->setName($ar_buf[0]); |
|
262
|
|
|
$dev->setRxBytes($ar_buf[4]); |
|
263
|
|
|
$dev->setTxBytes($ar_buf[6]); |
|
264
|
|
|
$dev->setErrors($ar_buf[5] + $ar_buf[7]); |
|
265
|
|
|
$dev->setDrops($ar_buf[8]); |
|
266
|
|
|
$this->sys->setNetDevices($dev); |
|
267
|
|
|
} |
|
268
|
|
|
} |
|
269
|
|
|
} |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* Physical memory information and Swap Space information |
|
274
|
|
|
* |
|
275
|
|
|
* @return void |
|
276
|
|
|
*/ |
|
277
|
|
|
private function _memory() |
|
278
|
|
|
{ |
|
279
|
|
|
if (CommonFunctions::rfts('/proc/meminfo', $bufr)) { |
|
280
|
|
|
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
|
281
|
|
|
foreach ($bufe as $buf) { |
|
282
|
|
|
if (preg_match('/Mem:\s+(.*)$/', $buf, $ar_buf)) { |
|
283
|
|
|
$ar_buf = preg_split('/\s+/', $ar_buf[1], 6); |
|
284
|
|
|
$this->sys->setMemTotal($ar_buf[0]); |
|
285
|
|
|
$this->sys->setMemUsed($ar_buf[1]); |
|
286
|
|
|
$this->sys->setMemFree($ar_buf[2]); |
|
287
|
|
|
$this->sys->setMemApplication($ar_buf[3]); |
|
288
|
|
|
$this->sys->setMemBuffer($ar_buf[4]); |
|
289
|
|
|
$this->sys->setMemCache($ar_buf[5]); |
|
290
|
|
|
} |
|
291
|
|
|
// Get info on individual swap files |
|
292
|
|
|
if (CommonFunctions::rfts('/proc/swaps', $swaps)) { |
|
293
|
|
|
$swapdevs = preg_split("/\n/", $swaps, -1, PREG_SPLIT_NO_EMPTY); |
|
294
|
|
|
for ($i = 1, $max = (sizeof($swapdevs) - 1); $i < $max; $i++) { |
|
295
|
|
|
$ar_buf = preg_split('/\s+/', $swapdevs[$i], 6); |
|
296
|
|
|
$dev = new DiskDevice(); |
|
297
|
|
|
$dev->setMountPoint($ar_buf[0]); |
|
298
|
|
|
$dev->setName("SWAP"); |
|
299
|
|
|
$dev->setFsType('swap'); |
|
300
|
|
|
$dev->setTotal($ar_buf[2] * 1024); |
|
301
|
|
|
$dev->setUsed($ar_buf[3] * 1024); |
|
302
|
|
|
$dev->setFree($dev->getTotal() - $dev->getUsed()); |
|
303
|
|
|
$this->sys->setSwapDevices($dev); |
|
304
|
|
|
} |
|
305
|
|
|
} |
|
306
|
|
|
} |
|
307
|
|
|
} |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
/** |
|
311
|
|
|
* filesystem information |
|
312
|
|
|
* |
|
313
|
|
|
* @return void |
|
314
|
|
|
*/ |
|
315
|
|
View Code Duplication |
private function _filesystems() |
|
|
|
|
|
|
316
|
|
|
{ |
|
317
|
|
|
if (CommonFunctions::executeProgram('df', '-kP', $df, PSI_DEBUG)) { |
|
318
|
|
|
$mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY); |
|
319
|
|
|
if (CommonFunctions::executeProgram('mount', '-v', $s, PSI_DEBUG)) { |
|
320
|
|
|
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY); |
|
321
|
|
|
while (list(, $line) = each($lines)) { |
|
322
|
|
|
$a = preg_split('/ /', $line, -1, PREG_SPLIT_NO_EMPTY); |
|
323
|
|
|
$fsdev[$a[0]] = $a[4]; |
|
|
|
|
|
|
324
|
|
|
} |
|
325
|
|
|
} |
|
326
|
|
|
foreach ($mounts as $mount) { |
|
327
|
|
|
$ar_buf = preg_split("/\s+/", $mount, 6); |
|
328
|
|
|
$dev = new DiskDevice(); |
|
329
|
|
|
$dev->setName($ar_buf[0]); |
|
330
|
|
|
$dev->setTotal($ar_buf[1] * 1024); |
|
331
|
|
|
$dev->setUsed($ar_buf[2] * 1024); |
|
332
|
|
|
$dev->setFree($ar_buf[3] * 1024); |
|
333
|
|
|
$dev->setMountPoint($ar_buf[5]); |
|
334
|
|
|
if (isset($fsdev[$ar_buf[0]])) { |
|
335
|
|
|
$dev->setFsType($fsdev[$ar_buf[0]]); |
|
336
|
|
|
} |
|
337
|
|
|
$this->sys->setDiskDevices($dev); |
|
338
|
|
|
} |
|
339
|
|
|
} |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
/** |
|
343
|
|
|
* Distribution |
|
344
|
|
|
* |
|
345
|
|
|
* @return void |
|
346
|
|
|
*/ |
|
347
|
|
|
private function _distro() |
|
348
|
|
|
{ |
|
349
|
|
|
$this->sys->setDistribution('HP-UX'); |
|
350
|
|
|
$this->sys->setDistributionIcon('HPUX.png'); |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
/** |
|
354
|
|
|
* get the information |
|
355
|
|
|
* |
|
356
|
|
|
* @see PSI_Interface_OS::build() |
|
357
|
|
|
* |
|
358
|
|
|
* @return Void |
|
359
|
|
|
*/ |
|
360
|
|
|
public function build() |
|
361
|
|
|
{ |
|
362
|
|
|
$this->_distro(); |
|
363
|
|
|
$this->_hostname(); |
|
364
|
|
|
$this->_kernel(); |
|
365
|
|
|
$this->_uptime(); |
|
366
|
|
|
$this->_users(); |
|
367
|
|
|
$this->_loadavg(); |
|
368
|
|
|
$this->_cpuinfo(); |
|
369
|
|
|
$this->_pci(); |
|
370
|
|
|
$this->_ide(); |
|
371
|
|
|
$this->_scsi(); |
|
372
|
|
|
$this->_usb(); |
|
373
|
|
|
$this->_network(); |
|
374
|
|
|
$this->_memory(); |
|
375
|
|
|
$this->_filesystems(); |
|
376
|
|
|
} |
|
377
|
|
|
} |
|
378
|
|
|
|
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.