=================================================================== RCS file: /cvs/nagios/check_bioctl/check_bioctl,v retrieving revision 1.12 retrieving revision 1.15 diff -u -r1.12 -r1.15 --- nagios/check_bioctl/check_bioctl 2009/11/23 21:52:53 1.12 +++ 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.11 2009/11/23 21:45:58 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.12 $ ' ); + 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++; @@ -126,9 +125,9 @@ foreach my $d ( @{$devices} ) { open my $bioctl, q{-|}, $BIOCTL, $d or die "Couldn't open bioctl: $!\n"; - while ( my $line = <$bioctl> ) { + LINE: while ( my $line = <$bioctl> ) { my ( $i, $item ) = parse_bioctl_line($line); - next unless defined $i; + next LINE if !defined $i; $volumes{$d}{$i} = $item; } ## no critic 'die' @@ -152,71 +151,60 @@ { my $vid; -sub parse_bioctl_line { - my ($line) = @_; - chomp $line; + my $controller; - # Do these by columns cuZ that is the easiest for now - my @o = unpack( "A6 A1 A11 A15 A7 A9 A*", $line ); - return if $o[0] eq 'Volume'; + sub parse_bioctl_line { + my ($line) = @_; + chomp $line; - foreach (@o) { - s/^\s+//xms; - s/\s+$//xms; - } + # Do these by columns cuZ that is the easiest for now + my @o = unpack( "A6 A1 A11 A15 A7 A9 A*", $line ); + return if $o[0] eq 'Volume'; - my ( $controller, $id, $status, $size, $dev, $details, $name ) = @o; - my $index = $id; - if ($controller) { - $vid = $id; - } - else { - $index = "$vid.$id"; - } + foreach (@o) { + s/^\s+//xms; + s/\s+$//xms; + } - my %item = ( - type => 'volume', - controller => $controller, - id => $id, - status => $status, - size => $size, - device => $dev, - details => $details, - name => $name, - volume_id => $vid, - ); + my ( $c, $id, $status, $size, $dev, $details, $name ) = @o; + my $index = $id; + if ($c) { + $vid = $id; + $controller = $c; + } + else { + $index = "$vid.$id"; + } - return $index, \%item; + return $index, + { + controller => $controller, + id => $id, + status => $status, + size => $size, + device => $dev, + details => $details, + name => $name, + volume_id => $vid, + }; + } } -} 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; @@ -235,7 +223,7 @@ EOL - print_revision( $PROGNAME, '$Revision: 1.12 $' ); + print_revision( $PROGNAME, '$Revision: 1.15 $' ); print $License;