--- contrib/check_linux_raid.pl 2007-08-28 04:19:45.000000000 +0100 +++ contrib/check_linux_raid.pl.new 2008-01-21 17:28:18.000000000 +0000 @@ -3,6 +3,7 @@ # Copyright (c) 2002 ISOMEDIA, Inc. # originally written by Steve Milton # later updates by sean finney +# bux fixing & usage message by Alain Williams # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -26,6 +27,8 @@ use lib "/usr/local/nagios/libexec"; use utils qw(%ERRORS); +my ($progname) = $0 =~ m|([^/]+)$|; + # die with an error if we're not on Linux if ($^O ne 'linux') { print "This plugin only applicable on Linux.\n"; @@ -42,9 +45,22 @@ return "UNKNOWN"; } +sub usage { + print "Inspect Linux software raid devices and return a status for nagios\n"; + print "Usage:\n"; + print "$progname [--help | -h] [md-device ...]\n"; + print "A md-device might be: md0\n"; + print "If md-device is not given, all mds will be inspected\n"; + exit 0; +} + my $nextdev; -if(defined $ARGV[0]) { $nextdev = shift; } -else { $nextdev = "md[0-9]"; } +if(defined $ARGV[0]) { + $nextdev = shift; + usage() if($nextdev eq '--help' or $nextdev eq '-h'); +} else { + $nextdev = "md[0-9]+"; # All MD devices +} my $code = "UNKNOWN"; my $msg = ""; @@ -53,6 +69,7 @@ my %finish; my %active; my %devices; +my $debug; while(defined $nextdev){ open (MDSTAT, "< /proc/mdstat") or die "Failed to open /proc/mdstat"; @@ -60,14 +77,22 @@ while() { if (defined $device) { if (/(\[[_U]+\])/) { + print "status='$1' device '$device'\n" if($debug); $status{$device} = $1; } elsif (/recovery = (.*?)\s/) { $recovery{$device} = $1; ($finish{$device}) = /finish=(.*?min)/; - } elsif (/^\s*$/) { + } elsif (/^\s*$/) { # Start of another device - blank line. NB: may not be present + print "undef '$device' _='$_'\n" if($debug); $device=undef; + } elsif(/^md[0-9]+\s*:/) { # Start of another device - another way + print "undef '$device' _='$_'\n" if($debug); + undef $device; } - } elsif (/^($nextdev)\s*:/) { + } + + # No current device and this line matches the device pattern ? + if ( ! defined($device) and /^($nextdev)\s*:/) { $device=$1; $devices{$device}=$device; if (/active/) {