3 # Copyright (C) 2006,2008,2009 Peter Palfrader <peter@palfrader.org>
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 # Need to allow /usr/local/bin/tw_cli info c0 u0 status in sudoers:
27 # nagios ALL=(ALL) NOPASSWD: /usr/local/bin/tw_cli info c0 u0 status
34 $ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin';
35 delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
37 my $TW_CLI = '/usr/local/bin/tw_cli';
38 my $SVN_REVISION_STRING = '$Rev: 410 $';
39 my ($SVN_REVISION) = ($SVN_REVISION_STRING =~ /([0-9]+)/);
40 $SVN_REVISION = 'unknown' unless defined $SVN_REVISION;
41 my $VERSION = '0.0.0.'.$SVN_REVISION;
55 Getopt::Long::config('bundling');
57 '--help' => \$params->{'help'},
58 '--version' => \$params->{'version'},
59 '--verbose' => \$params->{'verbose'},
60 '--controller=i' => \$params->{'controller'},
61 '--unit=i' => \$params->{'unit'},
62 '--no-sudo' => \$params->{'no-sudo'},
64 die ("$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help|--version] [--verbose] [--no-sudo] [--controller=<n>] [--unit=<n>]\n");
66 if ($params->{'help'}) {
67 print "$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help|--version] [--verbose] [--no-sudo] [--controller=<n>] [--unit=<n>]\n";
68 print "Checks status of 3ware raid arrays.\n";
71 if ($params->{'version'}) {
72 print "nagios-check-raid-3ware $VERSION\n";
73 print "nagios check for 3ware raids\n";
74 print "Copyright (c) 2006 Peter Palfrader <peter\@palfrader.org>\n";
78 $SIG{'__DIE__'} = sub {
84 print "Cannot find '$TW_CLI'.\n";
88 my $sudo = $params->{'no-sudo'} ? '' : 'sudo ';
89 my $command = "$sudo $TW_CLI info c$params->{'controller'} u$params->{'unit'} status";
90 print STDERR "Running $command\n" if $params->{'verbose'};
91 open (TW, "$command|") or die ("Cannot run $command: $!\n");
94 if ($CHILD_ERROR) { # program failed
95 die("$command returned with non-zero exit code: ".($CHILD_ERROR / 256)."\n");
103 next if $line =~ /^$/;
104 my ($device, $status) = $line =~ m#^(/c[0-9]+/u[0-9]+) status = ([A-Z]+)$#;
105 unless (defined($device) && defined($status)) {
106 print "Cannot parse line '$line'\n";
109 if ($status eq 'OK' ||
110 $status eq 'VERIFYING') {
111 $msg .= ($msg eq '' ? '' : '; '). "$device: $status";
112 $exit = $exit > $OK ? $exit : $OK;
113 } elsif ($status eq 'REBUILDING') {
114 $msg .= ($msg eq '' ? '' : '; '). "$device: $status";
115 $exit = $exit > $WARNING ? $exit : $WARNING;
116 } elsif ($status eq 'DEGRADED') {
117 $msg .= ($msg eq '' ? '' : '; '). "$device: $status";
118 $exit = $exit > $CRITICAL ? $exit : $CRITICAL;
119 } elsif ($status eq 'OFFLINE') {
120 $msg .= ($msg eq '' ? '' : '; '). "$device: $status";
121 $exit = $exit > $CRITICAL ? $exit : $CRITICAL;
123 $msg .= ($msg eq '' ? '' : '; '). "$device: UNKNOWN STATUS '$status'";
124 $exit = $exit > $UNKNOWN ? $exit : $UNKNOWN;
129 $msg = "No devices found";
130 die ("exit is not UNKNOWN but $exit") if ($exit != $UNKNOWN);