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zIJCNwoxJIdact5pQ+JM/ty14u7i3QSX6QpAQ51FZyzWjYtpk6VCwplrfgD7qnW6
Nz0OKVUszbNLvoT40s5rJR00AYY0vdhppa840Mx8gpZRmf44aFh37sZ9LwLAYSM2V
XCxzpoH3/Xd2zqhvwXNBXV4gifLI9igRJOrpLA6lskdDaTfeNmmcTKKMaayX8mg5R
H0i/e+ZHyuKpVEYdoee4wFjX4k0UIsUYvKH/VNVNkRnm8S0ENYv+RQcPv8xNaHiwL
zRPKlv2dUaWmz0d0oOrYRbgesS+TLEMxIp5zGx5qlKqLSz4xW9EPm+kJFTYP2HGiW
A==
</ViaThinkSoftSignature> */ ?>
<?php
/*
* VNag - Nagios Framework for PHP
* Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
* Licensed under the terms of the Apache 2.0 license
*
* Revision 2023-10-13
*/
declare(ticks=1);
class HpSmartArrayCheck extends VNag {
private $argSlot = null;
public function __construct() {
parent::__construct();
if ($this->is_http_mode()) {
// Don't allow the standard arguments via $_REQUEST
$this->registerExpectedStandardArguments('');
} else {
$this->registerExpectedStandardArguments('Vhtv');
}
$this->addExpectedArgument($this->argSlot = new VNagArgument('s', 'slot', VNagArgument::VALUE_REQUIRED, 'slot', 'The slot of the Smart Array controller.', null));
$this->getHelpManager()->setPluginName('vnag_hp_smartarray');
$this->getHelpManager()->setVersion('1.2');
$this->getHelpManager()->setShortDescription('This plugin checks the controller and disk status of a HP SmartArray RAID controller (using ssacli).');
$this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
$this->getHelpManager()->setSyntax('$SCRIPTNAME$ --slot slotnumber');
$this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
}
private function ssacli_physical_disk_status($slot) {
$mock_file = __DIR__.'/status_pd.mock';
$cmd = 'ssacli ctrl '.escapeshellarg('slot='.$slot).' pd all show status';
}
private function ssacli_logical_disk_status($slot) {
$mock_file = __DIR__.'/status_ld.mock';
$cmd = 'ssacli ctrl '.escapeshellarg('slot='.$slot).' ld all show status';
}
private function ssacli_controller_status($slot) {
// When slot is invalid, you receive an output to STDOUT with ExitCode 1
// "Error: The controller identified by "slot=0" was not detected."
$mock_file = __DIR__.'/status_ctrl.mock';
}
private function check_all($slot, &$ok) {
list($ec, $cont) = $this->ssacli_physical_disk_status($slot);
if ($ec != 0) {
$this->setStatus(VNag::STATUS_UNKNOWN);
$this->setHeadline("Error checking physical disk status: $cont", true);
$ok = false;
} else {
foreach ($cont as $s) {
if ($s == '') continue;
if (strpos($s,': OK') !== false) continue;
$this->setStatus(VNag::STATUS_WARNING);
$this->setHeadline($s, true);
$ok = false;
}
}
list($ec, $cont) = $this->ssacli_controller_status($slot);
foreach ($cont as $s) {
if ($s == '') continue;
if (preg_match('@Smart Array (.+) in Slot (.+)@', $s, $dummy)) continue;
if (strpos($s,': OK') !== false) continue;
$this->setStatus(VNag::STATUS_WARNING);
$this->setHeadline($s, true);
$ok = false;
}
list($ec, $cont) = $this->ssacli_logical_disk_status($slot);
foreach ($cont as $s) {
if ($s == '') continue;
if (strpos($s,': OK') !== false) continue;
$this->setStatus(VNag::STATUS_WARNING);
$this->setHeadline($s, true);
$ok = false;
}
}
protected function cbRun() {
$slot = $this->argSlot->available() ? $this->argSlot->getValue() : '';
if ($slot == '') {
throw new VNagException("Require slot argument");
}
$ok = true;
$this->check_all($slot, $ok);
if ($ok) {
$this->setStatus(VNag::STATUS_OK);
$this->setHeadline("All OK at slot $slot");
}
}
}