Code

check_snmp: Remove that is_numeric madness
[nagiosplug.git] / contrib / check_linux_raid.pl
index 85d5dc4a8da5c6a697765ad9773bb8d76031e146..77e75f6d0aa787890944d0a6a1bc19b219689c0b 100644 (file)
 #
 # Usage:   check_raid [raid-name]
 # Example: check_raid md0
-#          WARNING md0 status=[UUU_U], recovery=46.4%, finish=123.0min
+#        WARNING md0 status=[UUU_U], recovery=46.4%, finish=123.0min
 
 use strict;
-use lib utils.pm;
+use lib "/usr/local/nagios/libexec";
 use utils qw(%ERRORS);
 
 # die with an error if we're not on Linux
@@ -44,7 +44,7 @@ sub max_state($$){
 
 my $nextdev;
 if(defined $ARGV[0]) { $nextdev = shift; }
-else { $nextdev = "md[0-9]"; }
+else { $nextdev = "md[0-9]+"; }
 
 my $code = "UNKNOWN";
 my $msg = "";
@@ -61,19 +61,19 @@ while(defined $nextdev){
                if (defined $device) {
                        if (/(\[[_U]+\])/) {
                                $status{$device} = $1;
-                               $device = undef;
                        } elsif (/recovery = (.*?)\s/) {  
                                $recovery{$device} = $1;
                                ($finish{$device}) = /finish=(.*?min)/;
-                               $device = undef;
+                               $device=undef;
+                       } elsif (/^\s*$/) {
+                               $device=undef;
                        }
-               } else {
-                       if (/^($nextdev)\s*:/) {
-                               $device=$1;
-                               $devices{$device}=$device;
-                               if (/active/) {
-                                       $active{$device} = 1;
-                               }
+               } elsif (/^($nextdev)\s*:/) {
+                       $device=$1;
+                       $devices{$device}=$device;
+                       if (/\sactive/) {
+                               $status{$device} = ''; # Shall be filled later if available
+                               $active{$device} = 1;
                        }
                }
        }
@@ -81,8 +81,12 @@ while(defined $nextdev){
 }
 
 foreach my $k (sort keys %devices){
-       if ($status{$k} =~ /_/) {
-               if ($recovery{$k}) {
+       if (!exists($status{$k})) {
+               $msg .= sprintf " %s inactive with no status information.",
+                       $devices{$k};
+               $code = max_state($code, "CRITICAL");
+       } elsif ($status{$k} =~ /_/) {
+               if (defined $recovery{$k}) {
                        $msg .= sprintf " %s status=%s, recovery=%s, finish=%s.",
                                $devices{$k}, $status{$k}, $recovery{$k}, $finish{$k};
                        $code = max_state($code, "WARNING");
@@ -95,10 +99,11 @@ foreach my $k (sort keys %devices){
                $code = max_state($code, "OK");
        } else {
                if ($active{$k}) {
-                       $msg .= sprintf " %s active with no status information.\n",
+                       $msg .= sprintf " %s active with no status information.",
                                $devices{$k};
                        $code = max_state($code, "OK");
                } else {
+                       # This should't run anymore, but is left as a catch-all
                        $msg .= sprintf " %s does not exist.\n", $devices{$k};
                        $code = max_state($code, "CRITICAL");
                }