Subversion Repositories ALCASAR

Rev

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