packages: nagios-plugin-check_raid/check_raid - less if branches

glen glen at pld-linux.org
Thu Sep 10 21:40:31 CEST 2009


Author: glen                         Date: Thu Sep 10 19:40:31 2009 GMT
Module: packages                      Tag: HEAD
---- Log message:
- less if branches

---- Files affected:
packages/nagios-plugin-check_raid:
   check_raid (1.33 -> 1.34) 

---- Diffs:

================================================================
Index: packages/nagios-plugin-check_raid/check_raid
diff -u packages/nagios-plugin-check_raid/check_raid:1.33 packages/nagios-plugin-check_raid/check_raid:1.34
--- packages/nagios-plugin-check_raid/check_raid:1.33	Thu Sep 10 21:30:01 2009
+++ packages/nagios-plugin-check_raid/check_raid	Thu Sep 10 21:40:26 2009
@@ -74,7 +74,6 @@
 
 	open(my $fh , '-|', @CMD) or return;
 	while (<$fh>) {
-		chomp;
 		if (/^(\S+):/) { $d = $1; $sd = ''; next; }
 		if (/Submirror \d+:\s+(\S+)/) { $sd = $1; next; }
 		if (my($s) = /State: (\S.+)/) {
@@ -104,16 +103,15 @@
 			open($fh , '-|', @CMD) or next;
 		}
 		while (<$fh>) {
-			if (my($s, $n) = /Status\s*:\s*(\S+).*Logical Drive.*:\s*(\d+)/i) {
-				next unless valid($n);
-				if ($s ne 'ONLINE') {
-					$status = $ERRORS{CRITICAL};
-					$message .= "Megaide:$n:$s ";
-				} else {
-					$message .= "Megaide:$n:$s ";
-				}
-				last;
+			next unless (my($s, $n) = /Status\s*:\s*(\S+).*Logical Drive.*:\s*(\d+)/i);
+			next unless valid($n);
+			if ($s ne 'ONLINE') {
+				$status = $ERRORS{CRITICAL};
+				$message .= "Megaide:$n:$s ";
+			} else {
+				$message .= "Megaide:$n:$s ";
 			}
+			last;
 		}
 		close $fh;
 	}
@@ -125,15 +123,15 @@
 	open my $fh, '<', '/proc/mdstat' or return;
 	while (<$fh>) {
 		if (/^(\S+)\s+:/ ) { $n = $1; $f = ''; next; }
-		if (/(\S+)\[\d+\]\(F\)/ ) { $f = $1; next; }
-		if (my($s) = /\s*.*\[([U_]+)\]/ ) {
-			next unless valid($n);
-			if ($s =~ /_/) {
-				$status = $ERRORS{CRITICAL};
-				$message .= "md:$n:$f:$s ";
-			} else {
-				$message .= "md:$n:$s ";
-			}
+		next if (($f) = /(\S+)\[\d+\]\(F\)/);
+		next unless (my($s) = /\s*.*\[([U_]+)\]/);
+		next unless valid($n);
+
+		if ($s =~ /_/) {
+			$status = $ERRORS{CRITICAL};
+			$message .= "md:$n:$f:$s ";
+		} else {
+			$message .= "md:$n:$s ";
 		}
 	}
 	close $fh;
@@ -145,18 +143,16 @@
 
 	open(my $fh , '-|', @CMD) or return;
 	while (<$fh>) {
-		chomp;
-		if (my($n, $s) = m{/dev/(\S+) \S+ (\S+)}) {
-			next unless valid($n);
-			if ($s =~ /good|online/) {
-				# no worries
-			} elsif ($s =~ /sync/) {
-				$status = $ERRORS{WARNING} unless $status;
-			} else {
-				$status = $ERRORS{CRITICAL};
-			}
-			$message .= "md:$n:$s ";
+		next unless (my($n, $s) = m{/dev/(\S+) \S+ (\S+)});
+		next unless valid($n);
+		if ($s =~ /good|online/) {
+			# no worries
+		} elsif ($s =~ /sync/) {
+			$status = $ERRORS{WARNING} unless $status;
+		} else {
+			$status = $ERRORS{CRITICAL};
 		}
+		$message .= "md:$n:$s ";
 	}
 	close $fh;
 }
@@ -200,21 +196,18 @@
 	my @CMD = $ipssend;
 	unshift(@CMD, $sudo) if $> and $sudo;
 
-	my $n;
 	open(my $fh , '-|', @CMD) or return;
 	while (<$fh>) {
-		chomp;
-		if (/drive number (\d+)/i ) { $n = $1; next; }
+		next if (my($n) = /drive number (\d+)/i);
 		next unless valid($n);
+		next unless (my($s, $c) = /Status .*: (\S+)\s+(\S+)/);
 
-		if (my($s, $c) = /Status .*: (\S+)\s+(\S+)/ ) {
-			if ($c =~ /SYN|RBL/i ) { # resynching
-				$status = $ERRORS{WARNING} unless $status;
-			} elsif ($c !~ /OKY/i) { # not OK
-				$status = $ERRORS{CRITICAL};
-			}
-			$message .= "ips:$n:$s ";
+		if ($c =~ /SYN|RBL/i ) { # resynching
+			$status = $ERRORS{WARNING} unless $status;
+		} elsif ($c !~ /OKY/i) { # not OK
+			$status = $ERRORS{CRITICAL};
 		}
+		$message .= "ips:$n:$s ";
 	}
 	close $fh;
 }
@@ -247,18 +240,17 @@
 #COMMAND: logfile end
 #Executing: logfile end
 	while (<$read>) {
-		if (my ($dsk, $stat) = /(\d:\d\d?:\d+)\s+\S+:\S+\s+(\S+)/) {
-			next unless valid($dsk);
-			$dsk =~ s/:/\//g;
-			next unless valid($dsk);
-			$message .= "aac:$dsk:$stat ";
-			$status = $ERRORS{CRITICAL} if ($stat eq "Broken");
-			$status = $ERRORS{WARNING} if (!$status and $stat eq "Rebuild");
-			$status = $ERRORS{WARNING} if (!$status and $stat eq "Bld/Vfy");
-			$status = $ERRORS{CRITICAL} if ($stat eq "Missing");
-			$status = $ERRORS{WARNING} if (!$status and $stat eq "Verify");
-			$status = $ERRORS{WARNING} if (!$status and $stat eq "VfyRepl");
-		}
+		next unless (my ($dsk, $stat) = /(\d:\d\d?:\d+)\s+\S+:\S+\s+(\S+)/);
+		next unless valid($dsk);
+		$dsk =~ s/:/\//g;
+		next unless valid($dsk);
+		$message .= "aac:$dsk:$stat ";
+		$status = $ERRORS{CRITICAL} if ($stat eq "Broken");
+		$status = $ERRORS{WARNING} if (!$status and $stat eq "Rebuild");
+		$status = $ERRORS{WARNING} if (!$status and $stat eq "Bld/Vfy");
+		$status = $ERRORS{CRITICAL} if ($stat eq "Missing");
+		$status = $ERRORS{WARNING} if (!$status and $stat eq "Verify");
+		$status = $ERRORS{WARNING} if (!$status and $stat eq "VfyRepl");
 	}
 	close $read;
 }
@@ -277,18 +269,17 @@
 	close $write;
 
 	while (<$read>) {
-		if (my ($dsk, $stat) = /(\d:\d\d?:\d+)\s+\S+:\S+\s+(\S+)/) {
-			next unless valid($dsk);
-			$dsk =~ s/:/\//g;
-			next unless valid($dsk);
-			$message .= "aac:$dsk:$stat ";
-			$status = $ERRORS{CRITICAL} if ($stat eq "Broken");
-			$status = $ERRORS{WARNING} if (!$status and $stat eq "Rebuild");
-			$status = $ERRORS{WARNING} if (!$status and $stat eq "Bld/Vfy");
-			$status = $ERRORS{CRITICAL} if ($stat eq "Missing");
-			$status = $ERRORS{WARNING} if (!$status and $stat eq "Verify");
-			$status = $ERRORS{WARNING} if (!$status and $stat eq "VfyRepl");
-		}
+		next if (my ($dsk, $stat) = /(\d:\d\d?:\d+)\s+\S+:\S+\s+(\S+)/);
+		next unless valid($dsk);
+		$dsk =~ s/:/\//g;
+		next unless valid($dsk);
+		$message .= "aac:$dsk:$stat ";
+		$status = $ERRORS{CRITICAL} if ($stat eq "Broken");
+		$status = $ERRORS{WARNING} if (!$status and $stat eq "Rebuild");
+		$status = $ERRORS{WARNING} if (!$status and $stat eq "Bld/Vfy");
+		$status = $ERRORS{CRITICAL} if ($stat eq "Missing");
+		$status = $ERRORS{WARNING} if (!$status and $stat eq "Verify");
+		$status = $ERRORS{WARNING} if (!$status and $stat eq "VfyRepl");
 	}
 	close $read;
 }
@@ -324,16 +315,15 @@
 			open($fh , '-|', @CMD) or next;
 		}
 		while (<$fh>) {
-			if (my($n, $s) = /logical drive\s*:\s*(\d+).*, state\s*:\s*(\S+)/i) {
-				next unless valid($n);
-				if ($s ne 'optimal') {
-					$status = $ERRORS{CRITICAL};
-					$message .= "Megaraid:$n:$s ";
-				} else {
-					$message .= "Megaraid:$n:$s ";
-				}
-				last;
+			next if (my($n, $s) = /logical drive\s*:\s*(\d+).*, state\s*:\s*(\S+)/i);
+			next unless valid($n);
+			if ($s ne 'optimal') {
+				$status = $ERRORS{CRITICAL};
+				$message .= "Megaraid:$n:$s ";
+			} else {
+				$message .= "Megaraid:$n:$s ";
 			}
+			last;
 		}
 		close $fh;
 	}
@@ -355,12 +345,11 @@
 		while (<$fh>) {
 			chomp;
 			last if (/Array Drives:/); # Stop after the Logical Drive block
-			if (my ($num, $s) = m/^\s+Number:\s+(\d+)\s+Status:\s+(\S+)$/) {
-				if ($s ne "ok") {
-					$status = $ERRORS{CRITICAL} unless $status;
-				}
-				$message .= "gdth:$controller,$num:$s ";
+			next if (my ($num, $s) = m/^\s+Number:\s+(\d+)\s+Status:\s+(\S+)$/);
+			if ($s ne "ok") {
+				$status = $ERRORS{CRITICAL} unless $status;
 			}
+			$message .= "gdth:$controller,$num:$s ";
 		}
 		close($fh);
 	}
@@ -371,13 +360,11 @@
 		open my $fh, '<', $file or return;
 		my ($controller) = $file =~ m{([^/]+$)};
 		while (<$fh>) {
-			chomp;
-			if (my ($c, $t, $l, $s) = m/TID=\d+,\s+\(Channel=(\d+),\s+Target=(\d+),\s+Lun=(\d+)\)\s+\((\S+)\)/) {
-				if ($s ne "online") {
-					$status = $ERRORS{CRITICAL} unless $status;
-				}
-				$message .= "dpt_i2o:$c,$t,$l:$s ";
+			next if (my ($c, $t, $l, $s) = m/TID=\d+,\s+\(Channel=(\d+),\s+Target=(\d+),\s+Lun=(\d+)\)\s+\((\S+)\)/);
+			if ($s ne "online") {
+				$status = $ERRORS{CRITICAL} unless $status;
 			}
+			$message .= "dpt_i2o:$c,$t,$l:$s ";
 		}
 		close($fh);
 	}
@@ -401,7 +388,7 @@
 
 	for my $c (@c) {
 		# check each unit on controllers
-		open($fh , '-|', @CMD, 'info', $c, 'unitstatus') or return;
+		open($fh , '-|', @CMD, 'info', $c, 'unitstatus') or next;
 		while (<$fh>) {
 			next unless (my($u, $s, $p) = /^(u\d+)\s+\S+\s+(\S+)\s+(\S+)/);
 
@@ -413,13 +400,15 @@
 				$message .= "3ware:/$c/$u $s $p% ";
 
 			} elsif ($s eq 'DEGRADED') {
-				open(my $fh , '-|', @CMD, 'info', $c, 'drivestatus') or return;
+				open(my $fh , '-|', @CMD, 'info', $c, 'drivestatus');
 				my $ds = '';
-				while (<$fh>) {
-					next unless (my($p, $s) = /^(p\d+)\s+(\S+)\s+\Q$u\E/);
-					$ds .= "$p:$s ";
+				if ($fh) {
+					while (<$fh>) {
+						next unless (my($p, $s) = /^(p\d+)\s+(\S+)\s+\Q$u\E/);
+						$ds .= "$p:$s ";
+					}
+					close $fh;
 				}
-				close $fh;
 				$message .= "3ware:/$c/$u $s $ds ";
 				$status = $ERRORS{CRITICAL};
 			} else {
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/nagios-plugin-check_raid/check_raid?r1=1.33&r2=1.34&f=u



More information about the pld-cvs-commit mailing list