3 # Copyright (C) 2006 Peter Palfrader <peter@palfrader.org>
5 # Need to allow /usr/local/bin/tw_cli info c0 u0 status in sudoers:
7 # nagios ALL=(ALL) NOPASSWD: /usr/local/bin/tw_cli info c0 u0 status
14 $ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin';
15 delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
17 my $TW_CLI = '/usr/local/bin/tw_cli';
18 my $SVN_REVISION_STRING = '$Rev: 313 $';
19 my ($SVN_REVISION) = ($SVN_REVISION_STRING =~ /([0-9]+)/);
20 $SVN_REVISION = 'unknown' unless defined $SVN_REVISION;
21 my $VERSION = '0.0.0.'.$SVN_REVISION;
35 Getopt::Long::config('bundling');
37 '--help' => \$params->{'help'},
38 '--version' => \$params->{'version'},
39 '--verbose' => \$params->{'verbose'},
40 '--controller=i' => \$params->{'controller'},
41 '--unit=i' => \$params->{'unit'},
42 '--no-sudo' => \$params->{'no-sudo'},
44 die ("$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help|--version] [--verbose] [--no-sudo] [--controller=<n>] [--unit=<n>]\n");
46 if ($params->{'help'}) {
47 print "$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help|--version] [--verbose] [--no-sudo] [--controller=<n>] [--unit=<n>]\n";
48 print "Checks status of 3ware raid arrays.\n";
51 if ($params->{'version'}) {
52 print "nagios-check-raid-3ware $VERSION\n";
53 print "nagios check for 3ware raids\n";
54 print "Copyright (c) 2006 Peter Palfrader <peter\@palfrader.org>\n";
58 $SIG{'__DIE__'} = sub {
64 print "Cannot find '$TW_CLI'.\n";
68 my $sudo = $params->{'no-sudo'} ? '' : 'sudo ';
69 my $command = "$sudo $TW_CLI info c$params->{'controller'} u$params->{'unit'} status";
70 print STDERR "Running $command\n" if $params->{'verbose'};
71 open (TW, "$command|") or die ("Cannot run $command: $!\n");
74 if ($CHILD_ERROR) { # program failed
75 die("$command returned with non-zero exit code: ".($CHILD_ERROR / 256)."\n");
83 next if $line =~ /^$/;
84 my ($device, $status) = $line =~ m#^(/c[0-9]+/u[0-9]+) status = ([A-Z]+)$#;
85 unless (defined($device) && defined($status)) {
86 print "Cannot parse line '$line'\n";
89 if ($status eq 'OK' ||
90 $status eq 'VERIFYING') {
91 $msg .= ($msg eq '' ? '' : '; '). "$device: $status";
92 $exit = $exit > $OK ? $exit : $OK;
93 } elsif ($status eq 'DEGRADED') {
94 $msg .= ($msg eq '' ? '' : '; '). "$device: $status";
95 $exit = $exit > $CRITICAL ? $exit : $CRITICAL;
96 } elsif ($status eq 'OFFLINE') {
97 $msg .= ($msg eq '' ? '' : '; '). "$device: $status";
98 $exit = $exit > $CRITICAL ? $exit : $CRITICAL;
100 $msg .= ($msg eq '' ? '' : '; '). "$device: UNKNOWN STATUS '$status'";
101 $exit = $exit > $UNKNOWN ? $exit : $UNKNOWN;
106 $msg = "No devices found";
107 die ("exit is not UNKNOWN but $exit") if ($exit != $UNKNOWN);