=================================================================== RCS file: /cvs/nagios/check_bioctl/check_bioctl,v retrieving revision 1.13 retrieving revision 1.18 diff -u -r1.13 -r1.18 --- nagios/check_bioctl/check_bioctl 2009/11/23 21:57:31 1.13 +++ nagios/check_bioctl/check_bioctl 2011/12/27 02:12:38 1.18 @@ -1,5 +1,5 @@ #!/usr/bin/perl -T -# $RedRiver: check_bioctl,v 1.12 2009/11/23 21:52:53 andrew Exp $ +# $RedRiver: check_bioctl,v 1.15 2009/11/23 22:24:45 andrew Exp $ ######################################################################## # check_bioctl *** A nagios check for OpenBSD bioctl # @@ -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.13 $ ' ); + print_revision( $PROGNAME, '$Revision: 1.18 $ ' ); 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,73 +151,54 @@ { my $vid; + my $controller; sub parse_bioctl_line { - my ($line) = @_; - chomp $line; + ($_) = @_; + chomp; - # Do these by columns cuZ that is the easiest for now - my @o = unpack( "A6 A1 A11 A15 A7 A9 A*", $line ); + my @o = map { s/^\s+|\s+$//g; $_ } split; return if $o[0] eq 'Volume'; - foreach (@o) { - s/^\s+//xms; - s/\s+$//xms; - } + $vid ||= ''; - my ( $controller, $id, $status, $size, $dev, $details, $name ) = @o; - my $index = $id; - if ($controller) { - $vid = $id; + my $index = "$vid.$o[0]"; + if ( $o[0] !~ /^\d+$/ ) { + $controller = shift @o; + $vid = $o[0]; + $index = $vid; } - else { - $index = "$vid.$id"; - } - my %item = ( - type => 'volume', - controller => $controller, - id => $id, - status => $status, - size => $size, - device => $dev, - details => $details, - name => $name, - volume_id => $vid, - ); - - return $index, \%item; + return $index, + { + controller => $controller, + volume_id => $vid, + id => shift @o, + status => shift @o, + size => shift @o, + device => shift @o, + name => shift @o, + description => join ' ', + @o, + }; } } -} sub check_status { 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; @@ -237,7 +217,7 @@ EOL - print_revision( $PROGNAME, '$Revision: 1.13 $' ); + print_revision( $PROGNAME, '$Revision: 1.18 $' ); print $License;