/branches/namiltd-ini/plugins/ipmiinfo/class.ipmiinfo.inc.php

# · PHP · 194 lines · 140 code · 10 blank · 44 comment · 24 complexity · ca5d9cb0cdeec6d5c11c065a9c1f7177 MD5 · raw file

  1. <?php
  2. /**
  3. * ipmiinfo Plugin
  4. *
  5. * PHP version 5
  6. *
  7. * @category PHP
  8. * @package PSI_Plugin_ipmiinfo
  9. * @author Mieczyslaw Nalewaj <namiltd@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.ipmiinfo.inc.php 661 2012-08-27 11:26:39Z namiltd $
  13. * @link http://phpsysinfo.sourceforge.net
  14. */
  15. /**
  16. * ipmiinfo plugin, which displays all ipmi informations available
  17. *
  18. * @category PHP
  19. * @package PSI_Plugin_ipmiinfo
  20. * @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
  21. * @copyright 2009 phpSysInfo
  22. * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  23. * @version Release: 3.0
  24. * @link http://phpsysinfo.sourceforge.net
  25. */
  26. class ipmiinfo extends PSI_Plugin {
  27. private $_lines;
  28. public function __construct($enc) {
  29. parent::__construct(__CLASS__, $enc);
  30. $this->_lines = array();
  31. }
  32. /**
  33. * get temperature information
  34. *
  35. * @return array temperatures in array with label
  36. */
  37. private function temperature()
  38. {
  39. $result = array ();
  40. $i = 0;
  41. foreach ($this->_lines as $line) {
  42. $buffer = preg_split("/[ ]+\|[ ]+/", $line);
  43. if ($buffer[2] == "degrees C" && $buffer[3] != "na") {
  44. $result[$i]['label'] = $buffer[0];
  45. $result[$i]['value'] = $buffer[1];
  46. $result[$i]['state'] = $buffer[3];
  47. $result[$i]['limit'] = $buffer[8];
  48. $i++;
  49. }
  50. }
  51. return $result;
  52. }
  53. /**
  54. * get fan information
  55. *
  56. * @return array fans in array with label
  57. */
  58. private function fans()
  59. {
  60. $result = array ();
  61. $i = 0;
  62. foreach ($this->_lines as $line) {
  63. $buffer = preg_split("/[ ]+\|[ ]+/", $line);
  64. if ($buffer[2] == "RPM" && $buffer[3] != "na") {
  65. $result[$i]['label'] = $buffer[0];
  66. $result[$i]['value'] = $buffer[1];
  67. $result[$i]['state'] = $buffer[3];
  68. $result[$i]['min'] = $buffer[8];
  69. $i++;
  70. }
  71. }
  72. return $result;
  73. }
  74. /**
  75. * get voltage information
  76. *
  77. * @return array voltage in array with label
  78. */
  79. private function voltage()
  80. {
  81. $result = array ();
  82. $i = 0;
  83. foreach ($this->_lines as $line) {
  84. $buffer = preg_split("/[ ]+\|[ ]+/", $line);
  85. if ($buffer[2] == "Volts" && $buffer[3] != "na") {
  86. $result[$i]['label'] = $buffer[0];
  87. $result[$i]['value'] = $buffer[1];
  88. $result[$i]['state'] = $buffer[3];
  89. $result[$i]['min'] = $buffer[5];
  90. $result[$i]['max'] = $buffer[8];
  91. $i++;
  92. }
  93. }
  94. return $result;
  95. }
  96. /**
  97. * get misc information
  98. *
  99. * @return array misc in array with label
  100. */
  101. private function misc()
  102. {
  103. $result = array ();
  104. $i = 0;
  105. foreach ($this->_lines as $line) {
  106. $buffer = preg_split("/[ ]+\|[ ]+/", $line);
  107. if ($buffer[2] == "discrete" && $buffer[3] != "na") {
  108. $result[$i]['label'] = $buffer[0];
  109. $result[$i]['value'] = $buffer[1];
  110. $result[$i]['state'] = $buffer[3];
  111. $i++;
  112. }
  113. }
  114. return $result;
  115. }
  116. public function execute() {
  117. $this->_lines = array();
  118. switch (strtolower(PSI_PLUGIN_IPMIINFO_ACCESS)) {
  119. case 'command':
  120. $lines = "";
  121. if ((CommonFunctions::executeProgram('ipmitool', 'sensor', $lines))&&(!empty($lines)))
  122. $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
  123. break;
  124. case 'data':
  125. if ((CommonFunctions::rfts(APP_ROOT."/data/ipmiinfo.txt", $lines))&&(!empty($lines)))
  126. $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
  127. break;
  128. default:
  129. $this->error->addConfigError('__construct()', 'PSI_PLUGIN_IPMIINFO_ACCESS');
  130. break;
  131. }
  132. }
  133. public function xml()
  134. {
  135. if ( empty($this->_lines))
  136. return $this->xml->getSimpleXmlElement();
  137. $arrBuff = $this->temperature();
  138. if (sizeof($arrBuff) > 0) {
  139. $temp = $this->xml->addChild("Temperature");
  140. foreach ($arrBuff as $arrValue) {
  141. $item = $temp->addChild('Item');
  142. $item->addAttribute('Label', $arrValue['label']);
  143. $item->addAttribute('Value', $arrValue['value']);
  144. $item->addAttribute('State', $arrValue['state']);
  145. $item->addAttribute('Limit', $arrValue['limit']);
  146. }
  147. }
  148. $arrBuff = $this->fans();
  149. if (sizeof($arrBuff) > 0) {
  150. $fan = $this->xml->addChild('Fans');
  151. foreach ($arrBuff as $arrValue) {
  152. $item = $fan->addChild('Item');
  153. $item->addAttribute('Label', $arrValue['label']);
  154. $item->addAttribute('Value', $arrValue['value']);
  155. $item->addAttribute('State', $arrValue['state']);
  156. $item->addAttribute('Min', $arrValue['min']);
  157. }
  158. }
  159. $arrBuff = $this->voltage();
  160. if (sizeof($arrBuff) > 0) {
  161. $volt = $this->xml->addChild('Voltage');
  162. foreach ($arrBuff as $arrValue) {
  163. $item = $volt->addChild('Item');
  164. $item->addAttribute('Label', $arrValue['label']);
  165. $item->addAttribute('Value', $arrValue['value']);
  166. $item->addAttribute('State', $arrValue['state']);
  167. $item->addAttribute('Min', $arrValue['min']);
  168. $item->addAttribute('Max', $arrValue['max']);
  169. }
  170. }
  171. $arrBuff = $this->misc();
  172. if (sizeof($arrBuff) > 0) {
  173. $misc = $this->xml->addChild('Misc');
  174. foreach ($arrBuff as $arrValue) {
  175. $item = $misc->addChild('Item');
  176. $item->addAttribute('Label', $arrValue['label']);
  177. $item->addAttribute('Value', $arrValue['value']);
  178. $item->addAttribute('State', $arrValue['state']);
  179. }
  180. }
  181. return $this->xml->getSimpleXmlElement();
  182. }
  183. }
  184. ?>