Rev 77 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
37 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * VNag - Nagios Framework for PHP |
||
5 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
||
6 | * Licensed under the terms of the Apache 2.0 license |
||
7 | * |
||
77 | daniel-mar | 8 | * Revision 2023-10-13 |
37 | daniel-mar | 9 | */ |
10 | |||
11 | declare(ticks=1); |
||
12 | |||
13 | class HpSmartArrayCheck extends VNag { |
||
14 | private $argSlot = null; |
||
15 | |||
16 | public function __construct() { |
||
17 | parent::__construct(); |
||
18 | |||
19 | if ($this->is_http_mode()) { |
||
20 | // Don't allow the standard arguments via $_REQUEST |
||
21 | $this->registerExpectedStandardArguments(''); |
||
22 | } else { |
||
23 | $this->registerExpectedStandardArguments('Vhtv'); |
||
24 | } |
||
25 | |||
26 | $this->addExpectedArgument($this->argSlot = new VNagArgument('s', 'slot', VNagArgument::VALUE_REQUIRED, 'slot', 'The slot of the Smart Array controller.', null)); |
||
27 | |||
28 | $this->getHelpManager()->setPluginName('vnag_hp_smartarray'); |
||
79 | daniel-mar | 29 | $this->getHelpManager()->setVersion('2023-10-13'); |
37 | daniel-mar | 30 | $this->getHelpManager()->setShortDescription('This plugin checks the controller and disk status of a HP SmartArray RAID controller (using ssacli).'); |
31 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
||
32 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ --slot slotnumber'); |
||
33 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
||
34 | } |
||
35 | |||
36 | private function ssacli_physical_disk_status($slot) { |
||
37 | $mock_file = __DIR__.'/status_pd.mock'; |
||
38 | |||
39 | if (file_exists($mock_file)) return array(0, file_get_contents($mock_file)); |
||
40 | |||
41 | $cmd = 'ssacli ctrl '.escapeshellarg('slot='.$slot).' pd all show status'; |
||
42 | |||
43 | $out = array(); |
||
44 | exec($cmd, $out, $ec); |
||
45 | |||
46 | return array($ec, implode("\n", $out)); |
||
47 | } |
||
48 | |||
49 | private function ssacli_logical_disk_status($slot) { |
||
50 | $mock_file = __DIR__.'/status_ld.mock'; |
||
51 | |||
52 | if (file_exists($mock_file)) return array(0, file_get_contents($mock_file)); |
||
53 | |||
54 | $cmd = 'ssacli ctrl '.escapeshellarg('slot='.$slot).' ld all show status'; |
||
55 | |||
56 | $out = array(); |
||
57 | exec($cmd, $out, $ec); |
||
58 | |||
59 | return array($ec, implode("\n", $out)); |
||
60 | } |
||
61 | |||
62 | private function ssacli_controller_status($slot) { |
||
63 | |||
64 | // When slot is invalid, you receive an output to STDOUT with ExitCode 1 |
||
65 | // "Error: The controller identified by "slot=0" was not detected." |
||
66 | |||
67 | $mock_file = __DIR__.'/status_ctrl.mock'; |
||
68 | |||
69 | if (file_exists($mock_file)) return array(0, file_get_contents($mock_file)); |
||
70 | |||
71 | $cmd = 'ssacli ctrl '.escapeshellarg('slot='.$slot).' show status'; |
||
72 | |||
73 | $out = array(); |
||
74 | exec($cmd, $out, $ec); |
||
75 | |||
76 | return array($ec, implode("\n", $out)); |
||
77 | } |
||
78 | |||
79 | private function check_all($slot, &$ok) { |
||
80 | list($ec, $cont) = $this->ssacli_physical_disk_status($slot); |
||
81 | if ($ec != 0) { |
||
82 | $this->setStatus(VNag::STATUS_UNKNOWN); |
||
62 | daniel-mar | 83 | $this->setHeadline("Error checking physical disk status: $cont", true); |
37 | daniel-mar | 84 | $ok = false; |
85 | } else { |
||
86 | $cont = explode("\n", $cont); |
||
87 | foreach ($cont as $s) { |
||
88 | $s = trim($s); |
||
89 | if ($s == '') continue; |
||
90 | if (strpos($s,': OK') !== false) continue; |
||
91 | $this->setStatus(VNag::STATUS_WARNING); |
||
62 | daniel-mar | 92 | $this->setHeadline($s, true); |
37 | daniel-mar | 93 | $ok = false; |
94 | } |
||
95 | } |
||
96 | |||
97 | list($ec, $cont) = $this->ssacli_controller_status($slot); |
||
98 | $cont = explode("\n", $cont); |
||
99 | foreach ($cont as $s) { |
||
100 | $s = trim($s); |
||
101 | if ($s == '') continue; |
||
102 | if (preg_match('@Smart Array (.+) in Slot (.+)@', $s, $dummy)) continue; |
||
103 | if (strpos($s,': OK') !== false) continue; |
||
104 | $this->setStatus(VNag::STATUS_WARNING); |
||
62 | daniel-mar | 105 | $this->setHeadline($s, true); |
37 | daniel-mar | 106 | $ok = false; |
107 | } |
||
108 | |||
109 | list($ec, $cont) = $this->ssacli_logical_disk_status($slot); |
||
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); |
||
62 | daniel-mar | 116 | $this->setHeadline($s, true); |
37 | daniel-mar | 117 | $ok = false; |
118 | } |
||
119 | } |
||
120 | |||
121 | protected function cbRun() { |
||
122 | $slot = $this->argSlot->available() ? $this->argSlot->getValue() : ''; |
||
123 | |||
124 | if ($slot == '') { |
||
77 | daniel-mar | 125 | throw new VNagException("Require slot argument"); |
37 | daniel-mar | 126 | } |
127 | |||
128 | $ok = true; |
||
129 | |||
130 | $this->check_all($slot, $ok); |
||
131 | |||
132 | if ($ok) { |
||
133 | $this->setStatus(VNag::STATUS_OK); |
||
134 | $this->setHeadline("All OK at slot $slot"); |
||
135 | } |
||
136 | } |
||
137 | } |