/[nagios-plugins-perl]/trunk/plugins/check_compellent.pl
ViewVC logotype

Contents of /trunk/plugins/check_compellent.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 206 - (show annotations) (download)
Thu Oct 18 14:14:07 2018 UTC (2 years, 1 month ago) by racvision
File MIME type: text/plain
File size: 9918 byte(s)
Check_compellent : backport patch depuis la prod
1 #!/usr/bin/perl -w
2 #
3 # Copyright (c) 2015 - St├ęphane Urbanovski <s.urbanovski@ac-nancy-metz.fr>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty
12 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # you should have received a copy of the GNU General Public License
16 # along with this program (or with Nagios); if not, write to the
17 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA
19 #
20 #
21
22 use strict;
23 use warnings;
24 use Net::SNMP;
25 # use Getopt::Long;
26 use Nagios::Plugin qw /:DEFAULT %STATUS_TEXT/;
27 use Locale::gettext;
28 use POSIX qw(setlocale);
29
30 use Data::Dumper;
31
32 my $DEBUG = 0;
33 my ( $vsnmp, $timeout ) = ( 1, 2 );
34 my $version = '1.0';
35
36 my $np = Nagios::Plugin->new(
37 version => $version,
38 blurb => 'Check Compellent storage health',
39 usage => "Usage: %s -H|--host <host> [-p|--port=<port>] [-c|--communaute=<community>]",
40 timeout => 10
41 );
42
43 $np->add_arg (
44 spec => 'host|H=s',
45 help => 'Name of the host to test',
46 required => 1,
47 );
48
49 $np->add_arg (
50 spec => 'port|p=i',
51 help => 'SNMP port',
52 default => 161,
53 );
54
55 $np->add_arg (
56 spec => 'community|c=s',
57 help => 'SNMP community',
58 default => 'public',
59 );
60
61 $np->add_arg (
62 spec => 'target|T=s',
63 help => 'Object type to be checked (controler, enclosure, disk, volume, server)',
64 default => 'controler',
65 );
66
67 $np->add_arg (
68 spec => 'oid|o=s',
69 help => 'Use Compellent or Dell Storage OID',
70 default => 'compellent',
71 );
72
73 $np->add_arg (
74 spec => 'debug|d',
75 help => _gt('Debug level'),
76 );
77
78 $np->getopts;
79 my $host = $np->opts->get('host');
80 my $port = $np->opts->get('port');
81 my $comm = $np->opts->get('community');
82
83 my $target = $np->opts->get('target');
84 my $base_oid = $np->opts->get('oid');
85
86 $DEBUG = $np->opts->get('debug');
87
88 if ( $base_oid eq 'compellent' ) {
89 $base_oid = '.1.3.6.1.4.1.16139';
90
91 } elsif ( $base_oid eq 'dell' ) {
92 $base_oid = '.1.3.6.1.4.1.674.11000.2000.500.1';
93 }
94 if ( $target eq 'all' ) {
95 $target = 'controler,enclosure,power,disk,server,volume';
96
97 }
98
99 my ( $status, $message, $longOutput) = (OK, '?', '');
100
101 my ( $session, $error ) = Net::SNMP->session(
102 -hostname => $host,
103 -community => $comm,
104 -timeout => $timeout,
105 -version => $vsnmp,
106 -port => $port,
107 );
108
109 if ( !defined $session ) {
110 $np->nagios_exit( UNKNOWN, "ERROR: %s." );
111 }
112
113
114 # ===================================================
115 # CONTROLER STATUS
116 # ===================================================
117
118 if ( $target =~ /\bcontroler\b/ ) {
119 my %tableDef = (
120 'name' => 'controler',
121 'oid' => $base_oid . '.2.13.1',
122 'rows' => {
123 '.2' => {
124 'name' => 'Status',
125 'translate' => {
126 1 => 'OK',
127 2 => 'DOWN',
128 3 => 'DEGRADED',
129 }
130 },
131 '.4' => {
132 'name' => 'Name',
133 },
134 '.5' => {
135 'name' => 'IP',
136 },
137 '.8' => {
138 'name' => 'Service TAG',
139 },
140 '.12' => {
141 'name' => 'Leader',
142 'translate' => {
143 1 => 'YES',
144 2 => 'NO',
145 }
146 },
147 }
148 );
149
150 my $tableValues = getSnmpTable(\%tableDef);
151 checkTableStatus(\%tableDef,$tableValues);
152 }
153
154 # ===================================================
155 # ENCLOSURE STATUS
156 # ===================================================
157 if ( $target =~ /\benclosure\b/ ) {
158 my %tableDef = (
159 'name' => 'enclosures',
160 'oid' => $base_oid . '.2.15.1',
161 'rows' => {
162 '.3' => {
163 'name' => 'Status',
164 'translate' => {
165 1 => 'OK',
166 2 => 'DOWN',
167 3 => 'DEGRADED',
168 }
169 },
170 '.4' => {
171 'name' => 'Name',
172 },
173 '.6' => {
174 'name' => 'Type',
175 },
176 '.7' => {
177 'name' => 'Model',
178 },
179 '.9' => {
180 'name' => 'Service Tag',
181 },
182 '.10' => {
183 'name' => 'Asset Tag',
184 },
185 }
186 );
187
188 my $tableValues = getSnmpTable(\%tableDef);
189 checkTableStatus(\%tableDef,$tableValues);
190 }
191
192 # ===================================================
193 # POWER STATUS
194 # ===================================================
195 if ( $target =~ /\bpower\b/ ) {
196 my %tableDef = (
197 'name' => 'power supplies',
198 'oid' => $base_oid . '.2.17.1',
199 'idx2' => 'Ctrl%s %s',
200 'rows' => {
201 '.3' => {
202 'name' => 'Status',
203 'translate' => {
204 1 => 'OK',
205 2 => 'DOWN',
206 3 => 'DEGRADED',
207 }
208 },
209 '.4' => {
210 'name' => 'Name',
211 },
212 }
213 );
214
215 my $tableValues = getSnmpTable(\%tableDef);
216 checkTableStatus(\%tableDef,$tableValues);
217 }
218 # ===================================================
219 # DISK STATUS
220 # ===================================================
221 if ( $target =~ /\bdisk\b/ ) {
222 my %tableDef = (
223 'name' => 'disks',
224 'oid' => $base_oid . '.2.14.1',
225 'rows' => {
226 '.3' => {
227 'name' => 'Status',
228 'translate' => {
229 1 => 'OK',
230 2 => 'DOWN',
231 3 => 'DEGRADED',
232 }
233 },
234 '.4' => {
235 'name' => 'Position',
236 },
237 '.6' => {
238 'name' => 'Message',
239 },
240 '.9' => {
241 'name' => 'Size',
242 },
243 }
244 );
245
246 my $tableValues = getSnmpTable(\%tableDef);
247 checkTableStatus(\%tableDef,$tableValues);
248 }
249
250
251
252 # ===================================================
253 # SERVER STATUS
254 # ===================================================
255 if ( $target =~ /\bserver\b/ ) {
256 my %tableDef = (
257 'name' => 'servers',
258 'oid' => $base_oid . '.2.27.1',
259 'rows' => {
260 '.3' => {
261 'name' => 'Status',
262 'translate' => {
263 1 => 'OK',
264 2 => 'DOWN',
265 3 => 'DEGRADED',
266 }
267 },
268 '.4' => {
269 'name' => 'Name',
270 },
271 '.5' => {
272 'name' => 'Connectivity',
273 'translate' => {
274 1 => 'OK',
275 2 => 'DOWN',
276 3 => 'PARTIAL',
277 }
278 },
279 '.6' => {
280 'name' => 'Number of path',
281 },
282 }
283 );
284
285 my $tableValues = getSnmpTable(\%tableDef);
286 checkTableStatus(\%tableDef,$tableValues);
287 }
288
289
290 # ===================================================
291 # VOLUME STATUS
292 # ===================================================
293 if ( $target =~ /\bvolume\b/ ) {
294 my %tableDef = (
295 'oid' => $base_oid . '.2.26.1',
296 'name' => 'volumes',
297 'rows' => {
298 '.3' => {
299 'name' => 'Status',
300 'translate' => {
301 1 => 'OK',
302 2 => 'DOWN',
303 3 => 'DEGRADED',
304 }
305 },
306 '.4' => {
307 'name' => 'Name',
308 },
309 }
310 );
311
312 my $tableValues = getSnmpTable(\%tableDef);
313 checkTableStatus(\%tableDef,$tableValues);
314 }
315
316
317 ($status, $message) = $np->check_messages('join' => ', ');
318
319 # $np->_fake_exit(1);
320 # Nagios::Plugin::Functions->_fake_exit(1);
321 # $np->nagios_exit( $status, $message );
322
323 print $STATUS_TEXT{$status}." - $message\n";
324
325 if ( $np->opts->verbose ) {
326 print $longOutput;
327 }
328
329 exit $status;
330
331 sub checkTableStatus {
332 my ($tableDef,$tableValues) = (@_);
333 my %itemByStatus = ();
334 my $count = 0;
335 foreach my $id (keys %{$tableValues}) {
336 $count ++;
337 ## XH 20171110 : if Name is unknow (disks), set it to Position
338 if ( !defined($tableValues->{$id}{'Name'})) {
339 $tableValues->{$id}{'Name'} = $tableValues->{$id}{'Position'};
340 }
341 ##
342 if ( defined($tableValues->{$id}{'Status'}) && $tableValues->{$id}{'Status'} ne 'OK' ) {
343 if ( !defined($itemByStatus{$tableValues->{$id}{'Status'}}) ) {
344 $itemByStatus{$tableValues->{$id}{'Status'}} = [];
345 }
346 push(@{$itemByStatus{$tableValues->{$id}{'Status'}}},$tableValues->{$id}{'Name'});
347 }
348 if ( $np->opts->verbose ) {
349 $longOutput .= sprintf(_gt("%s is in status %s\n"),$tableValues->{$id}{'Name'},$tableValues->{$id}{'Status'});
350 }
351 }
352 print STDERR ' itemByStatus='.Dumper(\%itemByStatus) if $DEBUG;;
353 $np->add_message(OK, sprintf(_gt("All %s (%d) are OK"),$tableDef->{'name'},$count) );
354 foreach my $s (keys %itemByStatus) {
355 if ( scalar($itemByStatus{$s}) ) {
356 $np->add_message(CRITICAL, sprintf(_gt("%s in %s state: %s"),ucfirst($tableDef->{'name'}),$s,join(',',@{$itemByStatus{$s}})) );
357 }
358 }
359
360 print STDERR ' tableValues='.Dumper($tableValues) if $DEBUG;
361 }
362
363
364 sub getSnmpTable {
365 my ($tableDef) = (@_);
366
367 logD("Getting ".$tableDef->{'name'}." informations (oid = ".$tableDef->{'oid'}.")...");
368
369 my $snmpRet = $session->get_table( $tableDef->{'oid'} );
370 if ( !defined $snmpRet ) {
371 $np->nagios_exit( UNKNOWN, "Unable to get SNMP values" );
372 }
373
374 # print Dumper($snmpRet);
375
376 my %tableValues = ();
377 my $oidLength = length($tableDef->{'oid'});
378
379 foreach my $o (sort keys %{$snmpRet}) {
380
381 if ( ($o =~ /^[\d\.]+$/) ) {
382 my $o1 = substr($o,0, $oidLength);
383 if ( substr($o,0, $oidLength) eq $tableDef->{'oid'} ) {
384 my $o2 = substr($o,$oidLength);
385 my $value = $snmpRet->{$o};
386 $value =~ s/^\s*(.*?)\s*$/$1/; # trim
387
388 my ($id1, $id2, $id) = (0 , 0 , '');
389
390 if ( $o2 =~ /^(\.\d+?)\.(\d+)$/ ) { # 1D tables
391 ($o2, $id1, $id2) = ($1,$2,0);
392 $id = $id1;
393
394 } elsif ( $o2 =~ /^(\.\d+?)\.(\d+)\.(\d+)$/ ) { # 2D tables
395 ($o2, $id1, $id2) = ($1, $3, $2);
396 $id = $id2.'.'.$id1;
397
398 } else {
399 logW('Invalid oid (2): '.$o);
400 }
401 logD("oid=$o => o1=$o1 o2=$o2 id1=$id1 id2=$id2 id=$id value='$value'");
402
403 if ( defined( $tableDef->{'rows'}{$o2}) ) {
404 if ( ! defined($tableValues{$id}) ) {
405 $tableValues{$id} = {};
406 }
407
408 if ( defined($tableDef->{'rows'}{$o2}{'translate'}{$value}) ) {
409 $value = $tableDef->{'rows'}{$o2}{'translate'}{$value};
410 }
411 if ( $id2 && $tableDef->{'rows'}{$o2}{'name'} eq 'Name' ) {
412 $value = sprintf($tableDef->{'idx2'},$id2,$value);
413 }
414 $tableValues{$id}{$tableDef->{'rows'}{$o2}{'name'}} = $value;
415 }
416
417 } else {
418 logW('Unknown table oid : \''.$o.'\' (should start with \''.$tableDef->{'oid'}.'\')');
419
420 }
421 } else {
422 logW('Invalid oid (1) : '.$o);
423 }
424 }
425
426 return \%tableValues
427 }
428
429
430 sub logD {
431 print STDERR 'DEBUG: '.$_[0]."\n" if ($DEBUG);
432 }
433 sub logW {
434 print STDERR 'WARNING: '.$_[0]."\n" if ($DEBUG);
435 }
436 # Gettext wrapper
437 sub _gt {
438 return gettext($_[0]);
439 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.8