=================================================================== RCS file: /cvs/nagios/check_bioctl/check_bioctl,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- nagios/check_bioctl/check_bioctl 2009/11/23 21:58:04 1.14 +++ nagios/check_bioctl/check_bioctl 2009/11/23 22:24:45 1.15 @@ -1,5 +1,5 @@ #!/usr/bin/perl -T -# $RedRiver: check_bioctl,v 1.13 2009/11/23 21:57:31 andrew Exp $ +# $RedRiver: check_bioctl,v 1.14 2009/11/23 21:58:04 andrew Exp $ ######################################################################## # check_bioctl *** A nagios check for OpenBSD bioctl # @@ -10,7 +10,7 @@ local %ENV = (); -my $NAGIOS_OUTPUT = 1; +my $NAGIOS_OUTPUT = 0; my $License = <<'EOL'; Copyright (c) 2009 Andrew Fresh @@ -64,7 +64,6 @@ Invalid => 'CRITICAL', ); -my $state = 'UNKNOWN'; # tells whether the it is warning, critical, or OK my @devices; my $opt_h; my $opt_V; @@ -82,7 +81,7 @@ } if ($opt_V) { - print_revision( $PROGNAME, '$Revision: 1.14 $ ' ); + print_revision( $PROGNAME, '$Revision: 1.15 $ ' ); exit $ERRORS{'OK'}; } @@ -95,7 +94,7 @@ my %STATES = check_status( \%VOLUMES ); my $have_results = 0; -$state = 'OK'; +my $state = 'OK'; foreach my $error ( sort { $ERRORS{$b} <=> $ERRORS{$a} } keys %ERRORS ) { if ( exists $STATES{$error} ) { $have_results++; @@ -152,6 +151,7 @@ { my $vid; + my $controller; sub parse_bioctl_line { my ($line) = @_; @@ -166,17 +166,18 @@ s/\s+$//xms; } - my ( $controller, $id, $status, $size, $dev, $details, $name ) = @o; + my ( $c, $id, $status, $size, $dev, $details, $name ) = @o; my $index = $id; - if ($controller) { - $vid = $id; + if ($c) { + $vid = $id; + $controller = $c; } else { $index = "$vid.$id"; } - my %item = ( - type => 'volume', + return $index, + { controller => $controller, id => $id, status => $status, @@ -185,9 +186,7 @@ details => $details, name => $name, volume_id => $vid, - ); - - return $index, \%item; + }; } } @@ -195,29 +194,17 @@ my ($volumes) = @_; my %states; - foreach my $device ( sort keys %{$volumes} ) { - foreach my $index ( sort keys %{ $volumes->{$device} } ) { - my $cur_volume = $volumes->{$device}->{$index}; - my $cur_state = $Status_Map{ $cur_volume->{'status'} } - || 'UNKNOWN'; + foreach my $d ( sort keys %{$volumes} ) { + foreach my $i ( sort { $a <=> $b } keys %{ $volumes->{$d} } ) { + my $volume = $volumes->{$d}->{$i}; + my $state = $Status_Map{ $volume->{'status'} } || 'UNKNOWN'; - if ( $cur_volume->{'device'} =~ /^\d+:\d/xms ) { - push @{ $states{$cur_state} }, - sprintf( - "%5s %-7s %-11s %s", - $cur_volume->{'volume'}{'controller'}, - $cur_volume->{'device'}, - $cur_volume->{'status'}, - $cur_volume->{'name'} - ); - } - else { - push @{ $states{$cur_state} }, - sprintf( "%5s %-7s %s", - $cur_volume->{'controller'}, - $cur_volume->{'device'}, - $cur_volume->{'status'} ); - } + push @{ $states{$state} }, + sprintf( + "%5s %-7s %-11s %s", + $volume->{'controller'}, $volume->{'device'}, + $volume->{'status'}, $volume->{'name'} + ); } } return %states; @@ -236,7 +223,7 @@ EOL - print_revision( $PROGNAME, '$Revision: 1.14 $' ); + print_revision( $PROGNAME, '$Revision: 1.15 $' ); print $License;