Subversion Repositories vnag

Rev

Rev 37 | 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 /* <ViaThinkSoftSignature>
62 daniel-mar 2
kDLkg8lpkGUPmjU+Y6sWh3rOd8GSVnmq9wUcKJ+7XiVweZiNjoyUTZvAw/58fhWmH
3
N2+qCMoFCeFwxbBVxgROA31xaIDWbWi9i+iYagX9OHF+BA5ZAHhpHscbOxaCiN+iN
4
FualKnWi5rgleimA4mvhvaDRHXOw75McTTWssIuxMU/SaHwNKYS8AIDj5CPtlXMdV
5
Hd+yC82qk0hRAnlptRT9wc/J4NvmB3r02pSIOk0x5OqdyAID4ijiXLy2erM7UMwIY
6
MRwWHKIbxDGW4YgaP3E0kYp/ARenaouE9dKmzeBAmuLDJRs9gXm9GMQMbUwjdQIA3
7
qC1eSYAbojcwAH8cjmfDOeQt6ro6igMKBAzZEqRJKOk9LGpeP2mTg8zQzYX3ImST5
8
KmVW7KHLtvxxCs9fLyZhrwbt98Etx9zhd2ObeS5RFzJV7JOoEc9wHbtkCWNhFAUqg
9
PEzB1kpjhibpA23aZZL2Zz99TWKRqscxy2Rzk1U6eIHt6jhQY6sQHjJN8rgZIXHiJ
10
QFQFKF8COYgiO4a7UhKbJKvaeQqaA91NZI9mvboyNUQidi9PUV0stzV7p6XTJEFrq
11
WyyQdqrsWJ7jtvBl+zMjwMmtFlnWH51niI8KqhiOXdHN68Kc56FhPN4EBiadriXxN
12
LioxFCijfjn+748jXRBCjE//raAvvvMuW+SATPMQ3Nz7qqsFaqbhcvWMW8j1aGo2i
13
7h/lRGuSgFG+WUpJ+N7VTVLVsJBYq8lHsMdiqOtyK4FqCLLXSbxiFKi09jEaCUsnx
14
p7sjiVts/+oclV2QyPJ1ZvXDZCd4D9cXFBMRmFFd8vSV9DIZYavewd2NgrJFqGvAU
15
fzZTI7G88b/Zlq8aoTT/iueMg51yTGJb+yKKq8jDf+SS7YnrePSrUBC87oBZQYlmz
16
Sk1HU1hek7JRwL/8HOv/lK8Rv/V2Kr6Tykl0dG/Cha0M3cr8SCIYRFx6wXnecXLxX
17
mqZns0JHW8VCyzStM69o0P81dKnKTV1/PgWMeGtx9ZUL8DqZUQobHOiU1lfvclsLi
18
XnrNBkCDc8Vvfxqs14Nw1AuTRRhWAF8SXremC2nxTsvOrjDk/xqonDosLN18U/QLY
19
sdxoGGbgZ4sOb7IxjkdpzA9Y8xIuAZrs+w+uDHPpm986G4Ey354eQW+lmtE2CZmIb
20
wwIJwpUJxhpsT0KZkn8GpGhYt8V+xkvg5UIlexHLXT9m/YX+Q9x5vG1Q0z2Wx+hlH
21
acKXH7LKVVBeGwgyCHr7Isc/6ZFc6ft4MBXDuji256Jrur8RTIUmHMUSOD22Q8kBr
22
bdxGFSsI1eigrjuTwSOA9wGahPGgJgrfrUxRZJoGqttuqq8APlRYaOck1ZjoKPLQT
37 daniel-mar 23
g==
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 2021-08-06
33
 *
34
 * Changelog:
35
 * 2021-08-06   1.0   Initial release
36
 */
37
 
38
declare(ticks=1);
39
 
40
class HpSmartArrayCheck extends VNag {
41
        private $argSlot = null;
42
 
43
        public function __construct() {
44
                parent::__construct();
45
 
46
                if ($this->is_http_mode()) {
47
                        // Don't allow the standard arguments via $_REQUEST
48
                        $this->registerExpectedStandardArguments('');
49
                } else {
50
                        $this->registerExpectedStandardArguments('Vhtv');
51
                }
52
 
53
                $this->addExpectedArgument($this->argSlot = new VNagArgument('s', 'slot', VNagArgument::VALUE_REQUIRED, 'slot', 'The slot of the Smart Array controller.', null));
54
 
55
                $this->getHelpManager()->setPluginName('vnag_hp_smartarray');
56
                $this->getHelpManager()->setVersion('1.2');
57
                $this->getHelpManager()->setShortDescription('This plugin checks the controller and disk status of a HP SmartArray RAID controller (using ssacli).');
58
                $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
59
                $this->getHelpManager()->setSyntax('$SCRIPTNAME$ --slot slotnumber');
60
                $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
61
        }
62
 
63
        private function ssacli_physical_disk_status($slot) {
64
                $mock_file = __DIR__.'/status_pd.mock';
65
 
66
                if (file_exists($mock_file)) return array(0, file_get_contents($mock_file));
67
 
68
                $cmd = 'ssacli ctrl '.escapeshellarg('slot='.$slot).' pd all show status';
69
 
70
                $out = array();
71
                exec($cmd, $out, $ec);
72
 
73
                return array($ec, implode("\n", $out));
74
        }
75
 
76
        private function ssacli_logical_disk_status($slot) {
77
                $mock_file = __DIR__.'/status_ld.mock';
78
 
79
                if (file_exists($mock_file)) return array(0, file_get_contents($mock_file));
80
 
81
                $cmd = 'ssacli ctrl '.escapeshellarg('slot='.$slot).' ld all show status';
82
 
83
                $out = array();
84
                exec($cmd, $out, $ec);
85
 
86
                return array($ec, implode("\n", $out));
87
        }
88
 
89
        private function ssacli_controller_status($slot) {
90
 
91
                // When slot is invalid, you receive an output to STDOUT with ExitCode 1
92
                // "Error: The controller identified by "slot=0" was not detected."
93
 
94
                $mock_file = __DIR__.'/status_ctrl.mock';
95
 
96
                if (file_exists($mock_file)) return array(0, file_get_contents($mock_file));
97
 
98
                $cmd = 'ssacli ctrl '.escapeshellarg('slot='.$slot).' show status';
99
 
100
                $out = array();
101
                exec($cmd, $out, $ec);
102
 
103
                return array($ec, implode("\n", $out));
104
        }
105
 
106
        private function check_all($slot, &$ok) {
107
                list($ec, $cont) = $this->ssacli_physical_disk_status($slot);
108
                if ($ec != 0) {
109
                        $this->setStatus(VNag::STATUS_UNKNOWN);
62 daniel-mar 110
                        $this->setHeadline("Error checking physical disk status: $cont", true);
37 daniel-mar 111
                        $ok = false;
112
                } else {
113
                        $cont = explode("\n", $cont);
114
                        foreach ($cont as $s) {
115
                                $s = trim($s);
116
                                if ($s == '') continue;
117
                                if (strpos($s,': OK') !== false) continue;
118
                                $this->setStatus(VNag::STATUS_WARNING);
62 daniel-mar 119
                                $this->setHeadline($s, true);
37 daniel-mar 120
                                $ok = false;
121
                        }
122
                }
123
 
124
                list($ec, $cont) = $this->ssacli_controller_status($slot);
125
                $cont = explode("\n", $cont);
126
                foreach ($cont as $s) {
127
                        $s = trim($s);
128
                        if ($s == '') continue;
129
                        if (preg_match('@Smart Array (.+) in Slot (.+)@', $s, $dummy)) continue;
130
                        if (strpos($s,': OK') !== false) continue;
131
                        $this->setStatus(VNag::STATUS_WARNING);
62 daniel-mar 132
                        $this->setHeadline($s, true);
37 daniel-mar 133
                        $ok = false;
134
                }
135
 
136
                list($ec, $cont) = $this->ssacli_logical_disk_status($slot);
137
                $cont = explode("\n", $cont);
138
                foreach ($cont as $s) {
139
                        $s = trim($s);
140
                        if ($s == '') continue;
141
                        if (strpos($s,': OK') !== false) continue;
142
                        $this->setStatus(VNag::STATUS_WARNING);
62 daniel-mar 143
                        $this->setHeadline($s, true);
37 daniel-mar 144
                        $ok = false;
145
                }
146
        }
147
 
148
        protected function cbRun() {
149
                $slot = $this->argSlot->available() ? $this->argSlot->getValue() : '';
150
 
151
                if ($slot == '') {
152
                        throw new Exception("Require slot argument");
153
                }
154
 
155
                $ok = true;
156
 
157
                $this->check_all($slot, $ok);
158
 
159
                if ($ok) {
160
                        $this->setStatus(VNag::STATUS_OK);
161
                        $this->setHeadline("All OK at slot $slot");
162
                }
163
        }
164
}