Subversion Repositories vnag

Rev

Rev 62 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. <?php /* <ViaThinkSoftSignature>
  2. uj6Nn/5AixWCYFnSHOzNN+6Lcdw/Lq5AZkZbw5P4dDOh20Fsd04emPXxNgG7g754j
  3. qEnVgpmfgMIh97e/MpIvUr3RxglnNvz+ZiJywZZZGQj/wN3rHyn7UsjOq1CRts1LN
  4. qG/NObM5JVTBYCZkjSK6U2lxmpTgKZgwAwfSaSvp/KIChenFdvAVYmCMU/kJddMp1
  5. b44Y96U1JziUMe4VoMnCFzeO7YKHmlfmoJJKvSEQOOKBKcWny0yqh/uv8mK40F5Wg
  6. OP3zBBp+vMrvihBFvHJzewwBfud/FXHFWhsSuAj1NzllmDJ0G+59h52DYzWigoOsJ
  7. HeqVo3bsqLIJdeM/vZsZkZfl3uDBtK2brEUAKsu09s/k2uz+WwmGPu7Nnk8z7n/qo
  8. R6WIWABQ8/8ltd9/GF2uuaeUH4I/vfad8rbKQz9bkhtpIhZpHbXc5UdxTqdzG1z2e
  9. QRpiPkWuqCTPV2bAMq1IJ0W0A37Q0lDE990O5UXWYnvG78MVk01IBpJnoJswXvHkT
  10. 69H4aeFEWaQbqoAkELbua6CEXruKCVKAK7t67Qfv3yoNSMD0IHvHpKQc2TRG89mAf
  11. WY1+h8AY3WNHAsjRSeS5p6cPaU6kfcF6vDfY+j20KYdZCyTd0tm4QTz0WC7ONz5aW
  12. ZIQT8U/g05EYJgwWL533V3QcgNFgL0h/ee3LtKAHE0e16q0OkZWx8ZxN82zh3aJmc
  13. c88lK4zzbKpMSi4vYcmlfpnCQIdMuq5NKWDcB5xErbKaLNuTnYYoKNxSnMMTwbVkG
  14. efEzMBp4j6cfA5tYlyldW+odwRjvJyKyGtfXQspeuL0hPeG7978+L3bPIDbiWdYlR
  15. a3md3Nibaxf1IW4pW7WL8QvHQlp1EV1ji/Fj0en44+J9+vdVRIimXBSZcy20sxuP/
  16. vFnn1QY1Vu88dAGgtaFw0JA7yam51QN8mwxb3LHHaouac596PaogZxytkbSdLEkYt
  17. /ERN0rDeV1z0c+IkIbUFeiYsZGMWQJOYWgxpT+2G9RIrtKTvws+ys7G0nJPMd9uO8
  18. 9zIJCNwoxJIdact5pQ+JM/ty14u7i3QSX6QpAQ51FZyzWjYtpk6VCwplrfgD7qnW6
  19. Nz0OKVUszbNLvoT40s5rJR00AYY0vdhppa840Mx8gpZRmf44aFh37sZ9LwLAYSM2V
  20. XCxzpoH3/Xd2zqhvwXNBXV4gifLI9igRJOrpLA6lskdDaTfeNmmcTKKMaayX8mg5R
  21. H0i/e+ZHyuKpVEYdoee4wFjX4k0UIsUYvKH/VNVNkRnm8S0ENYv+RQcPv8xNaHiwL
  22. zRPKlv2dUaWmz0d0oOrYRbgesS+TLEMxIp5zGx5qlKqLSz4xW9EPm+kJFTYP2HGiW
  23. A==
  24. </ViaThinkSoftSignature> */ ?>
  25. <?php
  26.  
  27. /*
  28.  * VNag - Nagios Framework for PHP
  29.  * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
  30.  * Licensed under the terms of the Apache 2.0 license
  31.  *
  32.  * Revision 2023-10-13
  33.  */
  34.  
  35. declare(ticks=1);
  36.  
  37. class HpSmartArrayCheck extends VNag {
  38.         private $argSlot = null;
  39.  
  40.         public function __construct() {
  41.                 parent::__construct();
  42.  
  43.                 if ($this->is_http_mode()) {
  44.                         // Don't allow the standard arguments via $_REQUEST
  45.                         $this->registerExpectedStandardArguments('');
  46.                 } else {
  47.                         $this->registerExpectedStandardArguments('Vhtv');
  48.                 }
  49.  
  50.                 $this->addExpectedArgument($this->argSlot = new VNagArgument('s', 'slot', VNagArgument::VALUE_REQUIRED, 'slot', 'The slot of the Smart Array controller.', null));
  51.  
  52.                 $this->getHelpManager()->setPluginName('vnag_hp_smartarray');
  53.                 $this->getHelpManager()->setVersion('1.2');
  54.                 $this->getHelpManager()->setShortDescription('This plugin checks the controller and disk status of a HP SmartArray RAID controller (using ssacli).');
  55.                 $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
  56.                 $this->getHelpManager()->setSyntax('$SCRIPTNAME$ --slot slotnumber');
  57.                 $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
  58.         }
  59.  
  60.         private function ssacli_physical_disk_status($slot) {
  61.                 $mock_file = __DIR__.'/status_pd.mock';
  62.  
  63.                 if (file_exists($mock_file)) return array(0, file_get_contents($mock_file));
  64.  
  65.                 $cmd = 'ssacli ctrl '.escapeshellarg('slot='.$slot).' pd all show status';
  66.  
  67.                 $out = array();
  68.                 exec($cmd, $out, $ec);
  69.  
  70.                 return array($ec, implode("\n", $out));
  71.         }
  72.  
  73.         private function ssacli_logical_disk_status($slot) {
  74.                 $mock_file = __DIR__.'/status_ld.mock';
  75.  
  76.                 if (file_exists($mock_file)) return array(0, file_get_contents($mock_file));
  77.  
  78.                 $cmd = 'ssacli ctrl '.escapeshellarg('slot='.$slot).' ld all show status';
  79.  
  80.                 $out = array();
  81.                 exec($cmd, $out, $ec);
  82.  
  83.                 return array($ec, implode("\n", $out));
  84.         }
  85.  
  86.         private function ssacli_controller_status($slot) {
  87.  
  88.                 // When slot is invalid, you receive an output to STDOUT with ExitCode 1
  89.                 // "Error: The controller identified by "slot=0" was not detected."
  90.  
  91.                 $mock_file = __DIR__.'/status_ctrl.mock';
  92.  
  93.                 if (file_exists($mock_file)) return array(0, file_get_contents($mock_file));
  94.  
  95.                 $cmd = 'ssacli ctrl '.escapeshellarg('slot='.$slot).' show status';
  96.  
  97.                 $out = array();
  98.                 exec($cmd, $out, $ec);
  99.  
  100.                 return array($ec, implode("\n", $out));
  101.         }
  102.  
  103.         private function check_all($slot, &$ok) {
  104.                 list($ec, $cont) = $this->ssacli_physical_disk_status($slot);
  105.                 if ($ec != 0) {
  106.                         $this->setStatus(VNag::STATUS_UNKNOWN);
  107.                         $this->setHeadline("Error checking physical disk status: $cont", true);
  108.                         $ok = false;
  109.                 } else {
  110.                         $cont = explode("\n", $cont);
  111.                         foreach ($cont as $s) {
  112.                                 $s = trim($s);
  113.                                 if ($s == '') continue;
  114.                                 if (strpos($s,': OK') !== false) continue;
  115.                                 $this->setStatus(VNag::STATUS_WARNING);
  116.                                 $this->setHeadline($s, true);
  117.                                 $ok = false;
  118.                         }
  119.                 }
  120.  
  121.                 list($ec, $cont) = $this->ssacli_controller_status($slot);
  122.                 $cont = explode("\n", $cont);
  123.                 foreach ($cont as $s) {
  124.                         $s = trim($s);
  125.                         if ($s == '') continue;
  126.                         if (preg_match('@Smart Array (.+) in Slot (.+)@', $s, $dummy)) continue;
  127.                         if (strpos($s,': OK') !== false) continue;
  128.                         $this->setStatus(VNag::STATUS_WARNING);
  129.                         $this->setHeadline($s, true);
  130.                         $ok = false;
  131.                 }
  132.  
  133.                 list($ec, $cont) = $this->ssacli_logical_disk_status($slot);
  134.                 $cont = explode("\n", $cont);
  135.                 foreach ($cont as $s) {
  136.                         $s = trim($s);
  137.                         if ($s == '') continue;
  138.                         if (strpos($s,': OK') !== false) continue;
  139.                         $this->setStatus(VNag::STATUS_WARNING);
  140.                         $this->setHeadline($s, true);
  141.                         $ok = false;
  142.                 }
  143.         }
  144.  
  145.         protected function cbRun() {
  146.                 $slot = $this->argSlot->available() ? $this->argSlot->getValue() : '';
  147.  
  148.                 if ($slot == '') {
  149.                         throw new VNagException("Require slot argument");
  150.                 }
  151.  
  152.                 $ok = true;
  153.  
  154.                 $this->check_all($slot, $ok);
  155.  
  156.                 if ($ok) {
  157.                         $this->setStatus(VNag::STATUS_OK);
  158.                         $this->setHeadline("All OK at slot $slot");
  159.                 }
  160.         }
  161. }
  162.