Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

class.JSONOutput.inc.php 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. <?php
  2. /**
  3. * JSON generator class
  4. *
  5. * PHP version 5
  6. *
  7. * @category PHP
  8. * @package PSI_OUTPUT
  9. * @author Damien ROTH <BigMichi1@users.sourceforge.net>
  10. * @copyright 2013 phpSysInfo
  11. * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  12. * @link http://phpsysinfo.sourceforge.net
  13. */
  14. class JSONOutput extends Output implements PSI_Interface_Output
  15. {
  16. /**
  17. * Sysinfo object where the information retrieval methods are included
  18. *
  19. * @var PSI_Interface_OS
  20. */
  21. private $_sysinfo;
  22. /**
  23. * @var System
  24. */
  25. private $_sys = null;
  26. /**
  27. * JSON array
  28. *
  29. * @var Array
  30. */
  31. private $_xml;
  32. /**
  33. * only plugin xml
  34. *
  35. * @var boolean
  36. */
  37. private $_pluginRequest = false;
  38. /**
  39. * complete xml
  40. *
  41. * @var boolean
  42. */
  43. private $_completeXML = false;
  44. /**
  45. * name of the plugin
  46. *
  47. * @var Array
  48. */
  49. private $_plugins = array();
  50. /**
  51. * set parameters for the generation process
  52. *
  53. * @param boolean $completeXML switch for complete xml with all plugins
  54. * @param string $plugin name of the plugin
  55. *
  56. * @return void
  57. */
  58. public function __construct($completeXML, $plugin = null)
  59. {
  60. parent::__construct();
  61. if ($completeXML) {
  62. $this->_plugins = CommonFunctions::getPlugins();
  63. }
  64. if ($plugin !== null) {
  65. if (!is_array($plugin)) {
  66. $plugin = array($plugin);
  67. }
  68. foreach ($plugin as $p) {
  69. if (in_array(strtolower($p), CommonFunctions::getPlugins())) {
  70. $this->_plugins[] = $p;
  71. }
  72. $this->_pluginRequest = true;
  73. }
  74. }
  75. $this->_prepare();
  76. }
  77. /**
  78. * generate the output
  79. *
  80. * @return void
  81. */
  82. private function _prepare()
  83. {
  84. if (!$this->_pluginRequest) {
  85. // Figure out which OS we are running on, and detect support
  86. if (!file_exists(APP_ROOT.'/includes/os/class.'.PSI_OS.'.inc.php')) {
  87. $this->error->addError("file_exists(class.".PSI_OS.".inc.php)", PSI_OS." is not currently supported");
  88. }
  89. // check if there is a valid sensor configuration in config.php
  90. $foundsp = array();
  91. if ( defined('PSI_SENSOR_PROGRAM') && is_string(PSI_SENSOR_PROGRAM) ) {
  92. if (preg_match(ARRAY_EXP, PSI_SENSOR_PROGRAM)) {
  93. $sensorprograms = eval(strtolower(PSI_SENSOR_PROGRAM));
  94. } else {
  95. $sensorprograms = array(strtolower(PSI_SENSOR_PROGRAM));
  96. }
  97. foreach ($sensorprograms as $sensorprogram) {
  98. if (!file_exists(APP_ROOT.'/includes/mb/class.'.$sensorprogram.'.inc.php')) {
  99. $this->error->addError("file_exists(class.".htmlspecialchars($sensorprogram).".inc.php)", "specified sensor program is not supported");
  100. } else {
  101. $foundsp[] = $sensorprogram;
  102. }
  103. }
  104. }
  105. /**
  106. * motherboard information
  107. *
  108. * @var serialized array
  109. */
  110. define('PSI_MBINFO', serialize($foundsp));
  111. // check if there is a valid hddtemp configuration in config.php
  112. $found = false;
  113. if (PSI_HDD_TEMP !== false) {
  114. $found = true;
  115. }
  116. /**
  117. * hddtemp information available or not
  118. *
  119. * @var boolean
  120. */
  121. define('PSI_HDDTEMP', $found);
  122. // check if there is a valid ups configuration in config.php
  123. $found = false;
  124. if (PSI_UPS_PROGRAM !== false) {
  125. if (!file_exists(APP_ROOT.'/includes/ups/class.'.strtolower(PSI_UPS_PROGRAM).'.inc.php')) {
  126. $found = false;
  127. $this->error->addError("file_exists(class.".htmlspecialchars(strtolower(PSI_UPS_PROGRAM)).".inc.php)", "specified UPS program is not supported");
  128. } else {
  129. $found = true;
  130. }
  131. }
  132. /**
  133. * ups information available or not
  134. *
  135. * @var boolean
  136. */
  137. define('PSI_UPSINFO', $found);
  138. // if there are errors stop executing the script until they are fixed
  139. if ($this->error->errorsExist()) {
  140. $this->error->errorsAsXML();
  141. }
  142. }
  143. }
  144. /**
  145. * render the output
  146. *
  147. * @return void
  148. */
  149. public function run()
  150. {
  151. $os = PSI_OS;
  152. $this->_sysinfo = new $os();
  153. $this->_sys = $this->_sysinfo->getSys();
  154. // Build JSON
  155. $this->_json = array();
  156. $this->_buildPSIHeader();
  157. $this->_buildVitals();
  158. $this->_buildNetwork();
  159. $this->_buildHardware();
  160. $this->_buildMemory();
  161. $this->_buildFilesystems();
  162. $this->_buildMbinfo();
  163. $this->_buildUpsinfo();
  164. $this->_buildPlugins();
  165. return json_encode($this->_json);
  166. }
  167. /**
  168. * Returns the plugins
  169. *
  170. * @return Array the loaded plugins
  171. */
  172. public function getPlugins()
  173. {
  174. return $this->_plugins;
  175. }
  176. private function _buildPSIHeader()
  177. {
  178. $this->_json = array(
  179. 'Generation' => array(
  180. 'version' => PSI_VERSION_STRING,
  181. 'timestamp' => time()
  182. ),
  183. 'Options' => array(
  184. 'tempFormat' => defined('PSI_TEMP_FORMAT') ? strtolower(PSI_TEMP_FORMAT) : 'c',
  185. 'byteFormat' => defined('PSI_BYTE_FORMAT') ? strtolower(PSI_BYTE_FORMAT) : 'auto_binary'
  186. )
  187. );
  188. if ( defined('PSI_REFRESH') ) {
  189. if (PSI_REFRESH === false) {
  190. $this->_json['Options']['refresh'] = 0;
  191. } elseif (PSI_REFRESH === true) {
  192. $this->_json['Options']['refresh'] = 1;
  193. } else {
  194. $this->_json['Options']['refresh'] = PSI_REFRESH;
  195. }
  196. } else {
  197. $this->_json['Options']['refresh'] = 60000;
  198. }
  199. if ( defined('PSI_FS_USAGE_THRESHOLD') ) {
  200. if (PSI_FS_USAGE_THRESHOLD === true) {
  201. $this->_json['Options']['threshold'] = 1;
  202. } elseif ((PSI_FS_USAGE_THRESHOLD !== false) && (PSI_FS_USAGE_THRESHOLD >= 1) && (PSI_FS_USAGE_THRESHOLD <= 99) ) {
  203. $this->_json['Options']['threshold'] = PSI_FS_USAGE_THRESHOLD;
  204. }
  205. } else {
  206. $this->_json['Options']['threshold'] = 90;
  207. }
  208. $this->_json['Options']['showPickListTemplate'] = defined('PSI_SHOW_PICKLIST_TEMPLATE') ? (PSI_SHOW_PICKLIST_TEMPLATE ? 'true' : 'false') : 'false';
  209. if (count($this->_plugins) > 0) {
  210. foreach ($this->_plugins as $plugin) {
  211. $this->_json['UsedPlugins']['Plugin'][] = $plugin;
  212. }
  213. }
  214. }
  215. private function _buildVitals()
  216. {
  217. $vitals = array(
  218. 'Hostname' => $this->_sys->getHostname(),
  219. 'IPAddr' => $this->_sys->getIp(),
  220. 'Kernel' => $this->_sys->getKernel(),
  221. 'Distro' => $this->_sys->getDistribution(),
  222. 'Distroicon' => $this->_sys->getDistributionIcon(),
  223. 'Uptime' => $this->_sys->getUptime(),
  224. 'Users' => $this->_sys->getUsers(),
  225. 'LoadAvg' => $this->_sys->getLoad()
  226. );
  227. if ($this->_sys->getLoadPercent() !== null) {
  228. $vitals['CPULoad'] = $this->_sys->getLoadPercent();
  229. }
  230. if ($this->_sysinfo->getLanguage() !== null) {
  231. $vitals['SysLang'] = $this->_sysinfo->getLanguage();
  232. }
  233. if ($this->_sysinfo->getEncoding() !== null) {
  234. $vitals['CodePage'] = $this->_sysinfo->getEncoding();
  235. }
  236. $this->_json['Vitals'] = $vitals;
  237. }
  238. /**
  239. * generate the network information
  240. *
  241. * @return void
  242. */
  243. private function _buildNetwork()
  244. {
  245. if ( defined('PSI_HIDE_NETWORK_INTERFACE') && is_string(PSI_HIDE_NETWORK_INTERFACE) ) {
  246. if (preg_match(ARRAY_EXP, PSI_HIDE_NETWORK_INTERFACE)) {
  247. $hideDevices = eval(PSI_HIDE_NETWORK_INTERFACE);
  248. } else {
  249. $hideDevices = array(PSI_HIDE_NETWORK_INTERFACE);
  250. }
  251. } else {
  252. $hideDevices = array();
  253. }
  254. foreach ($this->_sys->getNetDevices() as $dev) {
  255. if (!in_array(trim($dev->getName()), $hideDevices)) {
  256. $netdev = array(
  257. 'Name' => $dev->getName(),
  258. 'RxBytes' => $dev->getRxBytes(),
  259. 'TxBytes' => $dev->getTxBytes(),
  260. 'Err' => $dev->getErrors(),
  261. 'Drops' => $dev->getDrops()
  262. );
  263. if ( defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS && $dev->getInfo() )
  264. $netdev['Info'] = $dev->getInfo();
  265. $this->_json['Network']['NetDevice'][] = $netdev;
  266. }
  267. }
  268. }
  269. /**
  270. * generate the hardware information
  271. *
  272. * @return void
  273. */
  274. private function _buildHardware()
  275. {
  276. $devices = array(
  277. 'PCI' => 'getPciDevices()',
  278. 'USB' => 'getUsbDevices()',
  279. 'IDE' => 'getIdeDevices()',
  280. 'SCSI' => 'getScsiDevices()'
  281. );
  282. foreach ($devices as $devname=>$devfunc) {
  283. foreach (System::removeDupsAndCount(eval('return $this->_sys->'.$devfunc.';')) as $dev) {
  284. $device = array('Name' => $dev->getName());
  285. if ($dev->getCount() > 1) {
  286. $device['Count'] = $dev->getCount();
  287. }
  288. if ($dev->getCapacity() !== null) {
  289. $device['Capacity'] = $dev->getCapacity();
  290. }
  291. $this->_json['Hardware'][$devname][] = $device;
  292. }
  293. }
  294. foreach ($this->_sys->getCpus() as $oneCpu) {
  295. $cpu = array('Model' => $oneCpu->getModel());
  296. if ($oneCpu->getCpuSpeed() !== 0) {
  297. $cpu['CpuSpeed'] = $oneCpu->getCpuSpeed();
  298. }
  299. if ($oneCpu->getCpuSpeedMax() !== 0) {
  300. $cpu['CpuSpeedMax'] = $oneCpu->getCpuSpeedMax();
  301. }
  302. if ($oneCpu->getCpuSpeedMin() !== 0) {
  303. $cpu['CpuSpeedMin'] = $oneCpu->getCpuSpeedMin();
  304. }
  305. if ($oneCpu->getTemp() !== null) {
  306. $cpu['CpuTemp'] = $oneCpu->getTemp();
  307. }
  308. if ($oneCpu->getBusSpeed() !== null) {
  309. $cpu['BusSpeed'] = $oneCpu->getBusSpeed();
  310. }
  311. if ($oneCpu->getCache() !== null) {
  312. $cpu['Cache'] = $oneCpu->getCache();
  313. }
  314. if ($oneCpu->getVirt() !== null) {
  315. $cpu['Virt'] = $oneCpu->getVirt();
  316. }
  317. if ($oneCpu->getBogomips() !== null) {
  318. $cpu['Bogomips'] = $oneCpu->getBogomips();
  319. }
  320. if ($oneCpu->getLoad() !== null) {
  321. $cpu['Load'] = $oneCpu->getLoad();
  322. }
  323. $this->_json['Hardware']['CPU'][] = $cpu;
  324. }
  325. }
  326. /**
  327. * generate the memory information
  328. *
  329. * @return void
  330. */
  331. private function _buildMemory()
  332. {
  333. $memory = array(
  334. 'Free' => $this->_sys->getMemFree(),
  335. 'Used' => $this->_sys->getMemUsed(),
  336. 'Total' => $this->_sys->getMemTotal(),
  337. 'Percent' => $this->_sys->getMemPercentUsed(),
  338. 'Details' => array()
  339. );
  340. if ($this->_sys->getMemApplication() !== null) {
  341. $memory['Details']['App'] = $this->_sys->getMemApplication();
  342. $memory['Details']['AppPercent'] = $this->_sys->getMemPercentApplication();
  343. }
  344. if ($this->_sys->getMemBuffer() !== null) {
  345. $memory['Details']['Buffers'] = $this->_sys->getMemBuffer();
  346. $memory['Details']['BuffersPercent'] = $this->_sys->getMemPercentBuffer();
  347. }
  348. if ($this->_sys->getMemCache() !== null) {
  349. $memory['Details']['Cached'] = $this->_sys->getMemCache();
  350. $memory['Details']['CachedPercent'] = $this->_sys->getMemPercentCache();
  351. }
  352. if (count($this->_sys->getSwapDevices()) > 0) {
  353. $memory['Swap'] = array(
  354. 'Free' => $this->_sys->getSwapFree(),
  355. 'Used' => $this->_sys->getSwapUsed(),
  356. 'Total' => $this->_sys->getSwapTotal(),
  357. 'Percent' => $this->_sys->getSwapPercentUsed(),
  358. 'Devices' => array()
  359. );
  360. $i = 1;
  361. foreach ($this->_sys->getSwapDevices() as $dev) {
  362. $memory['Swap']['Mount'][] = $this->_fillDevice($dev, $i++);
  363. }
  364. }
  365. $this->_json['Memory'] = $memory;
  366. }
  367. /**
  368. * generate the filesysteminformation
  369. *
  370. * @return void
  371. */
  372. private function _buildFilesystems()
  373. {
  374. $hideMounts = $hideFstypes = $hideDisks = array();
  375. if ( defined('PSI_HIDE_MOUNTS') && is_string(PSI_HIDE_MOUNTS) ) {
  376. if (preg_match(ARRAY_EXP, PSI_HIDE_MOUNTS)) {
  377. $hideMounts = eval(PSI_HIDE_MOUNTS);
  378. } else {
  379. $hideMounts = array(PSI_HIDE_MOUNTS);
  380. }
  381. }
  382. if ( defined('PSI_HIDE_FS_TYPES') && is_string(PSI_HIDE_FS_TYPES) ) {
  383. if (preg_match(ARRAY_EXP, PSI_HIDE_FS_TYPES)) {
  384. $hideFstypes = eval(PSI_HIDE_FS_TYPES);
  385. } else {
  386. $hideFstypes = array(PSI_HIDE_FS_TYPES);
  387. }
  388. }
  389. if ( defined('PSI_HIDE_DISKS') && is_string(PSI_HIDE_DISKS) ) {
  390. if (preg_match(ARRAY_EXP, PSI_HIDE_DISKS)) {
  391. $hideDisks = eval(PSI_HIDE_DISKS);
  392. } else {
  393. $hideDisks = array(PSI_HIDE_DISKS);
  394. }
  395. }
  396. $i = 1;
  397. foreach ($this->_sys->getDiskDevices() as $disk) {
  398. if (!in_array($disk->getMountPoint(), $hideMounts, true)
  399. && !in_array($disk->getFsType(), $hideFstypes, true)
  400. && !in_array($disk->getName(), $hideDisks, true)) {
  401. $this->_json['FileSystem']['Mount'][] = $this->_fillDevice($disk, $i++);
  402. }
  403. }
  404. }
  405. /**
  406. * fill a xml element with atrributes from a disk device
  407. *
  408. * @param DiskDevice $dev DiskDevice
  409. * @param Integer $i counter
  410. *
  411. * @return Void
  412. */
  413. private function _fillDevice(DiskDevice $dev, $i)
  414. {
  415. $mount = array(
  416. 'MountPointID' => $i,
  417. 'FSType' => $dev->getFsType(),
  418. 'Name' => $dev->getName(),
  419. 'Free' => sprintf("%.0f", $dev->getFree()),
  420. 'Used' => sprintf("%.0f", $dev->getUsed()),
  421. 'Total' => sprintf("%.0f", $dev->getTotal()),
  422. 'Percent' => $dev->getPercentUsed()
  423. );
  424. if (PSI_SHOW_MOUNT_OPTION === true && $dev->getOptions() !== null) {
  425. $mount['MountOptions'] = preg_replace("/,/",", ",$dev->getOptions());
  426. }
  427. if ($dev->getPercentInodesUsed() !== null) {
  428. $mount['Inodes'] = $dev->getPercentInodesUsed();
  429. }
  430. if (PSI_SHOW_MOUNT_POINT === true) {
  431. $mount['MountPoint'] = $dev->getMountPoint();
  432. }
  433. return $mount;
  434. }
  435. /**
  436. * generate the motherboard information
  437. *
  438. * @return void
  439. */
  440. private function _buildMbinfo()
  441. {
  442. $mbinfo = array();
  443. if ((sizeof(unserialize(PSI_MBINFO))>0) || PSI_HDDTEMP) {
  444. $mbinfo['Temperature'] = array();
  445. if (sizeof(unserialize(PSI_MBINFO))>0) {
  446. foreach (unserialize(PSI_MBINFO) as $mbinfoclass) {
  447. $mbinfo_data = new $mbinfoclass();
  448. $mbinfo_detail = $mbinfo_data->getMBInfo();
  449. foreach ($mbinfo_detail->getMbTemp() as $dev) {
  450. $item = array(
  451. 'Label' => $dev->getName(),
  452. 'Value' => $dev->getValue()
  453. );
  454. if ($dev->getMax() !== null) {
  455. $item['Max'] = $dev->getMax();
  456. }
  457. if ( defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "" ) {
  458. $item['Event'] = $dev->getEvent();
  459. }
  460. $mbinfo['Temperature'][] = $item;
  461. }
  462. }
  463. }
  464. if (PSI_HDDTEMP) {
  465. $hddtemp = new HDDTemp();
  466. $hddtemp_data = $hddtemp->getMBInfo();
  467. foreach ($hddtemp_data->getMbTemp() as $dev) {
  468. $item = array(
  469. 'Label' => $dev->getName(),
  470. 'Value' => $dev->getValue()
  471. );
  472. if ($dev->getMax() !== null) {
  473. $item['Max'] = $dev->getMax();
  474. }
  475. $mbinfo['Temperature'][] = $item;
  476. }
  477. }
  478. }
  479. if (sizeof(unserialize(PSI_MBINFO))>0) {
  480. foreach ($mbinfo_detail->getMbFan() as $dev) {
  481. $item = array(
  482. 'Label' => $dev->getName(),
  483. 'Value' => $dev->getValue()
  484. );
  485. if ($dev->getMin() !== null) {
  486. $item['Min'] = $dev->getMin();
  487. }
  488. if ( defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "" ) {
  489. $item['Event'] = $dev->getEvent();
  490. }
  491. $mbinfo['Fans'][] = $item;
  492. }
  493. foreach ($mbinfo_detail->getMbVolt() as $dev) {
  494. $item = array(
  495. 'Label' => $dev->getName(),
  496. 'Value' => $dev->getValue()
  497. );
  498. if ($dev->getMin() !== null) {
  499. $item['Min'] = $dev->getMin();
  500. }
  501. if ($dev->getMax() !== null) {
  502. $item['Max'] = $dev->getMax();
  503. }
  504. if ( defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "" ) {
  505. $item['Event'] = $dev->getEvent();
  506. }
  507. $mbinfo['Voltage'][] = $item;
  508. }
  509. foreach ($mbinfo_detail->getMbPower() as $dev) {
  510. $item = array(
  511. 'Label' => $dev->getName(),
  512. 'Value' => $dev->getValue()
  513. );
  514. if ($dev->getMax() !== null) {
  515. $item['Max'] = $dev->getMax();
  516. }
  517. if ( defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "" ) {
  518. $item['Event'] = $dev->getEvent();
  519. }
  520. $mbinfo['Power'][] = $item;
  521. }
  522. foreach ($mbinfo_detail->getMbCurrent() as $dev) {
  523. $item = array(
  524. 'Label' => $dev->getName(),
  525. 'Value' => $dev->getValue()
  526. );
  527. if ($dev->getMax() !== null) {
  528. $item['Max'] = $dev->getMax();
  529. }
  530. if ( defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "" ) {
  531. $item['Event'] = $dev->getEvent();
  532. }
  533. $mbinfo['Current'][] = $item;
  534. }
  535. }
  536. if (count($mbinfo) > 0)
  537. $this->_json['MBInfo'] = $mbinfo;
  538. }
  539. /**
  540. * generate the ups information
  541. *
  542. * @return void
  543. */
  544. private function _buildUpsinfo()
  545. {
  546. $upsinfo = array();
  547. if ( defined('PSI_UPS_APCUPSD_CGI_ENABLE') && PSI_UPS_APCUPSD_CGI_ENABLE) {
  548. $upsinfo['ApcupsdCgiLinks'] = true;
  549. }
  550. if (PSI_UPSINFO) {
  551. $upsinfoclass = PSI_UPS_PROGRAM;
  552. $upsinfo_data = new $upsinfoclass();
  553. $upsinfo_detail = $upsinfo_data->getUPSInfo();
  554. foreach ($upsinfo_detail->getUpsDevices() as $ups) {
  555. $item = array(
  556. 'Name' => $ups->getName(),
  557. 'Model' => $ups->getModel(),
  558. 'Mode' => $ups->getMode(),
  559. 'StartTime' => $ups->getStartTime(),
  560. 'Status' => $ups->getStatus()
  561. );
  562. if ($ups->getTemperatur() !== null)
  563. $item['Temperature'] = $ups->getTemperatur();
  564. if ($ups->getOutages() !== null)
  565. $item['OutagesCount'] = $ups->getOutages();
  566. if ($ups->getLastOutage() !== null)
  567. $item['LastOutage'] = $ups->getLastOutage();
  568. if ($ups->getLastOutageFinish() !== null)
  569. $item['LastOutageFinish'] = $ups->getLastOutageFinish();
  570. if ($ups->getLineVoltage() !== null)
  571. $item['LineVoltage'] = $ups->getLineVoltage();
  572. if ($ups->getLoad() !== null)
  573. $item['LoadPercent'] = $ups->getLoad();
  574. if ($ups->getBatteryDate() !== null)
  575. $item['BatteryDate'] = $ups->getBatteryDate();
  576. if ($ups->getBatteryVoltage() !== null)
  577. $item['BatteryVoltage'] = $ups->getBatteryVoltage();
  578. if ($ups->getBatterCharge() !== null)
  579. $item['BatteryChargePercent'] = $ups->getBatterCharge();
  580. if ($ups->getTimeLeft() !== null)
  581. $item['TimeLeftMinutes'] = $ups->getTimeLeft();
  582. $upsinfo[] = $item;
  583. }
  584. }
  585. if (count($upsinfo) > 0)
  586. $this->_json['UPSInfo']['UPS'] = $upsinfo;
  587. }
  588. /**
  589. * Includes the plugins to the main data array
  590. *
  591. * @return void
  592. */
  593. private function _buildPlugins()
  594. {
  595. if (count($this->_plugins) > 0) {
  596. $plugins = array();
  597. foreach ($this->_plugins as $plugin) {
  598. $object = new $plugin($this->_sysinfo->getEncoding());
  599. $object->execute();
  600. $data = $object->getData();
  601. if ($data !== null) {
  602. $plugins[get_class($object)] = $data;
  603. }
  604. }
  605. if (count($plugins) > 0) {
  606. $this->_json['Plugins'] = $plugins;
  607. }
  608. }
  609. }
  610. }