PageRenderTime 58ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/3.0.18/includes/os/class.HPUX.inc.php

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