Subversion Repositories ALCASAR

Rev

Rev 2770 | 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) {
109
                    $arrBuff = preg_split('/\s+:\s+/', trim($detail));
110
                    if (count($arrBuff) == 2) {
111
                        switch (strtolower($arrBuff[0])) {
112
                        case 'model name':
113
                        case 'cpu':
114
                            $dev->setModel($arrBuff[1]);
115
                            break;
116
                        case 'cpu mhz':
117
                        case 'clock':
118
                            $dev->setCpuSpeed($arrBuff[1]);
119
                            break;
120
                        case 'cycle frequency [hz]':
121
                            $dev->setCpuSpeed($arrBuff[1] / 1000000);
122
                            break;
123
                        case 'cpu0clktck':
124
                            $dev->setCpuSpeed(hexdec($arrBuff[1]) / 1000000); // Linux sparc64
125
                            break;
126
                        case 'l2 cache':
127
                        case 'cache size':
128
                            $dev->setCache(preg_replace("/[a-zA-Z]/", "", $arrBuff[1]) * 1024);
129
                            break;
130
                        case 'bogomips':
131
                        case 'cpu0bogo':
132
                            $dev->setBogomips($arrBuff[1]);
133
                        }
134
                    }
135
                }
136
            }
137
        }
138
    }
139
 
140
    /**
141
     * PCI devices
142
     *
143
     * @return void
144
     */
145
    private function _pci()
146
    {
147
        if (CommonFunctions::rfts('/proc/pci', $bufr)) {
148
            $device = false;
149
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
150
            foreach ($bufe as $buf) {
151
                if (preg_match('/^\s*Bus\s/', $buf)) {
152
                    $device = true;
153
                    continue;
154
                }
155
                if ($device) {
156
                    $dev = new HWDevice();
157
                    $dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($buf)));
158
                    $this->sys->setPciDevices($dev);
159
/*
160
                    list($key, $value) = preg_split('/: /', $buf, 2);
161
                    if (!preg_match('/bridge/i', $key) && !preg_match('/USB/i', $key)) {
162
                        $dev = new HWDevice();
163
                        $dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($value)));
164
                        $this->sys->setPciDevices($dev);
165
                    }
166
*/
167
                    $device = false;
168
                }
169
            }
170
        }
171
    }
172
 
173
    /**
174
     * IDE devices
175
     *
176
     * @return void
177
     */
178
    private function _ide()
179
    {
180
        $bufd = CommonFunctions::gdc('/proc/ide', false);
181
        foreach ($bufd as $file) {
182
            if (preg_match('/^hd/', $file)) {
183
                $dev = new HWDevice();
184
                $dev->setName(trim($file));
185
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS && CommonFunctions::rfts("/proc/ide/".$file."/media", $buf, 1)) {
186
                    if (trim($buf) == 'disk') {
187
                        if (CommonFunctions::rfts("/proc/ide/".$file."/capacity", $buf, 1, 4096, false)) {
188
                            $dev->setCapacity(trim($buf) * 512);
189
                        }
190
                    }
191
                }
192
                $this->sys->setIdeDevices($dev);
193
            }
194
        }
195
    }
196
 
197
    /**
198
     * SCSI devices
199
     *
200
     * @return void
201
     */
202
    private function _scsi()
203
    {
204
        $get_type = false;
205
        if (CommonFunctions::rfts('/proc/scsi/scsi', $bufr, 0, 4096, PSI_DEBUG)) {
206
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
207
            foreach ($bufe as $buf) {
208
                if (preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $dev)) {
209
                    $get_type = true;
210
                    continue;
211
                }
212
                if ($get_type) {
213
                    preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
214
                    $dev = new HWDevice();
215
                    $dev->setName($dev[1].' '.$dev[2].' ('.$dev_type[1].')');
216
                    $this->sys->setScsiDevices($dev);
217
                    $get_type = false;
218
                }
219
            }
220
        }
221
    }
222
 
223
    /**
224
     * USB devices
225
     *
226
     * @return void
227
     */
228
    private function _usb()
229
    {
230
        if (CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) {
231
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
232
            $devnum = -1;
233
            $results = array();
234
            foreach ($bufe as $buf) {
235
                if (preg_match('/^T/', $buf)) {
236
                    $devnum++;
237
                    $results[$devnum] = "";
238
                } elseif (preg_match('/^S:/', $buf)) {
239
                    list($key, $value) = preg_split('/: /', $buf, 2);
240
                    list($key, $value2) = preg_split('/=/', $value, 2);
241
                    if (trim($key) != "SerialNumber") {
242
                        $results[$devnum] .= " ".trim($value2);
243
                    }
244
                }
245
            }
246
            foreach ($results as $var) {
247
                $dev = new HWDevice();
248
                $dev->setName($var);
249
                $this->sys->setUsbDevices($dev);
250
            }
251
        }
252
    }
253
 
254
    /**
255
     * Network devices
256
     * includes also rx/tx bytes
257
     *
258
     * @return void
259
     */
260
    private function _network()
261
    {
262
        if (CommonFunctions::executeProgram('netstat', '-ni | tail -n +2', $netstat)) {
263
            $lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
264
            foreach ($lines as $line) {
265
                $ar_buf = preg_split("/\s+/", $line);
266
                if (! empty($ar_buf[0]) && ! empty($ar_buf[3])) {
267
                    $dev = new NetDevice();
268
                    $dev->setName($ar_buf[0]);
269
                    $dev->setRxBytes($ar_buf[4]);
270
                    $dev->setTxBytes($ar_buf[6]);
271
                    $dev->setErrors($ar_buf[5] + $ar_buf[7]);
272
                    $dev->setDrops($ar_buf[8]);
273
                    $this->sys->setNetDevices($dev);
274
                }
275
            }
276
        }
277
    }
278
 
279
    /**
280
     * Physical memory information and Swap Space information
281
     *
282
     * @return void
283
     */
284
    private function _memory()
285
    {
286
        if (CommonFunctions::rfts('/proc/meminfo', $bufr)) {
287
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
288
            foreach ($bufe as $buf) {
289
                if (preg_match('/Mem:\s+(.*)$/', $buf, $ar_buf)) {
290
                    $ar_buf = preg_split('/\s+/', $ar_buf[1], 6);
291
                    $this->sys->setMemTotal($ar_buf[0]);
292
                    $this->sys->setMemUsed($ar_buf[1]);
293
                    $this->sys->setMemFree($ar_buf[2]);
294
                    $this->sys->setMemApplication($ar_buf[3]);
295
                    $this->sys->setMemBuffer($ar_buf[4]);
296
                    $this->sys->setMemCache($ar_buf[5]);
297
                }
298
                // Get info on individual swap files
299
                if (CommonFunctions::rfts('/proc/swaps', $swaps)) {
300
                    $swapdevs = preg_split("/\n/", $swaps, -1, PREG_SPLIT_NO_EMPTY);
301
                    for ($i = 1, $max = (sizeof($swapdevs) - 1); $i < $max; $i++) {
302
                        $ar_buf = preg_split('/\s+/', $swapdevs[$i], 6);
303
                        $dev = new DiskDevice();
304
                        $dev->setMountPoint($ar_buf[0]);
305
                        $dev->setName("SWAP");
306
                        $dev->setFsType('swap');
307
                        $dev->setTotal($ar_buf[2] * 1024);
308
                        $dev->setUsed($ar_buf[3] * 1024);
309
                        $dev->setFree($dev->getTotal() - $dev->getUsed());
310
                        $this->sys->setSwapDevices($dev);
311
                    }
312
                }
313
            }
314
        }
315
    }
316
 
317
    /**
318
     * filesystem information
319
     *
320
     * @return void
321
     */
322
    private function _filesystems()
323
    {
324
        if (CommonFunctions::executeProgram('df', '-kP', $df, PSI_DEBUG)) {
325
            $mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
326
            if (CommonFunctions::executeProgram('mount', '-v', $s, PSI_DEBUG)) {
327
                $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
328
                foreach ($lines as $line) {
329
                    $a = preg_split('/ /', $line, -1, PREG_SPLIT_NO_EMPTY);
330
                    $fsdev[$a[0]] = $a[4];
331
                }
332
            }
333
            foreach ($mounts as $mount) {
334
                $ar_buf = preg_split("/\s+/", $mount, 6);
335
                $dev = new DiskDevice();
336
                $dev->setName($ar_buf[0]);
337
                $dev->setTotal($ar_buf[1] * 1024);
338
                $dev->setUsed($ar_buf[2] * 1024);
339
                $dev->setFree($ar_buf[3] * 1024);
340
                $dev->setMountPoint($ar_buf[5]);
341
                if (isset($fsdev[$ar_buf[0]])) {
342
                    $dev->setFsType($fsdev[$ar_buf[0]]);
343
                }
344
                $this->sys->setDiskDevices($dev);
345
            }
346
        }
347
    }
348
 
349
    /**
350
     * Distribution
351
     *
352
     * @return void
353
     */
354
    private function _distro()
355
    {
356
        $this->sys->setDistribution('HP-UX');
357
        $this->sys->setDistributionIcon('HPUX.png');
358
    }
359
 
360
    /**
361
     * get the information
362
     *
363
     * @see PSI_Interface_OS::build()
364
     *
3037 rexy 365
     * @return void
2770 rexy 366
     */
367
    public function build()
368
    {
369
        if (!$this->blockname || $this->blockname==='vitals') {
370
            $this->_distro();
371
            $this->_hostname();
372
            $this->_kernel();
373
            $this->_uptime();
374
            $this->_users();
375
            $this->_loadavg();
376
        }
377
        if (!$this->blockname || $this->blockname==='hardware') {
378
            $this->_cpuinfo();
379
            $this->_pci();
380
            $this->_ide();
381
            $this->_scsi();
382
            $this->_usb();
383
        }
384
        if (!$this->blockname || $this->blockname==='memory') {
385
            $this->_memory();
386
        }
387
        if (!$this->blockname || $this->blockname==='filesystem') {
388
            $this->_filesystems();
389
        }
3037 rexy 390
        if (!$this->blockname || $this->blockname==='network') {
391
            $this->_network();
392
        }
2770 rexy 393
    }
394
}