[project @ peter@palfrader.org-20080414210537-nxv7xzwb11fw1mzs]
authorPeter Palfrader <peter@palfrader.org>
Mon, 14 Apr 2008 21:05:37 +0000 (17:05 -0400)
committerPeter Palfrader <peter@palfrader.org>
Mon, 14 Apr 2008 21:05:37 +0000 (17:05 -0400)
dsa-check-raid-sw: cleaner output

dsa-nagios-nrpe-config/debian/changelog
dsa-nagios-nrpe-config/dsa-check-raid-sw

index d5d5782..595db7d 100644 (file)
@@ -1,3 +1,9 @@
+dsa-nagios-nrpe-config (30) unstable; urgency=low
+
+  * dsa-check-raid-sw: cleaner output.
+
+ -- Peter Palfrader <weasel@debian.org>  Mon, 14 Apr 2008 17:05:17 -0400
+
 dsa-nagios-nrpe-config (29) unstable; urgency=low
 
   * dsa-check-dabackup: terser output.
index f971d66..0297036 100755 (executable)
@@ -84,9 +84,8 @@ alarm($timeout);
 
 # Start checking the file...
 open (FH, $stat) or print("UNKNOWN: Cannot open $stat: $!\n"), exit $ERRORS{'UNKNOWN'};
-$state = $ERRORS{'OK'};
-$msg ="";
 
+my @failed = ();
 my @resyncing = ();
 my $device = '';
 
@@ -96,8 +95,7 @@ while (<FH>) {
        if ($line =~ /^(md\S*) /) {
                $device = $1;
        } elsif( $line =~ / \[_|_\]|U_|_U /) {
-               $state = $ERRORS{'CRITICAL'};
-               $msg = $msg . $device . ": - ";
+               push @failed, $device;
        }
        elsif ( $line =~ / resync /) {
                #       [==>..................]  resync = 10.3% (15216320/146994624) finish=2153.2min speed=1018K/sec
@@ -109,14 +107,20 @@ while (<FH>) {
 }
 close (FH);
 
-if ( $state == $ERRORS{'CRITICAL'} ) { 
-       print "CRITICAL - Device(s) $msg have failed\n"; 
-} elsif ( scalar @resyncing > 0 ) {
+if (scalar @failed > 0) {
+       if (scalar @failed == 1) {
+               print "CRITICAL - Device $failed[0] has failed.\n";
+       } else {
+               print "CRITICAL - Devices ".join(", ", @failed)." have failed.\n"
+       };
+       exit $ERRORS{'CRITICAL'};
+} elsif (scalar @resyncing > 0 ) {
        print "WARNING: Resyncing: ".(join "; ", @resyncing)."\n";
-       $state = $ERRORS{'WARNING'};
-} elsif ( $state == $ERRORS{'OK'} )
-        { print "OK - All devices are online\n"; }
-exit $state;
+       exit $ERRORS{'WARNING'};
+} else {
+       print "OK - All devices are online\n";
+       exit $ERRORS{'OK'};
+};
 
 
 sub print_usage () {