Subversion Repositories ALCASAR

Rev

Rev 3037 | Details | Compare with Previous | Last modification | View Log

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