=================================================================== RCS file: /cvs/nagios/check_bioctl/check_bioctl,v retrieving revision 1.14 retrieving revision 1.21 diff -u -r1.14 -r1.21 --- nagios/check_bioctl/check_bioctl 2009/11/23 21:58:04 1.14 +++ nagios/check_bioctl/check_bioctl 2017/02/08 16:31:55 1.21 @@ -1,5 +1,5 @@ #!/usr/bin/perl -T -# $RedRiver: check_bioctl,v 1.13 2009/11/23 21:57:31 andrew Exp $ +# $AFresh1: check_bioctl,v 1.20 2014/06/27 18:59:56 andrew Exp $ ######################################################################## # check_bioctl *** A nagios check for OpenBSD bioctl # @@ -7,6 +7,7 @@ ######################################################################## use strict; use warnings; +use 5.010; local %ENV = (); @@ -29,6 +30,7 @@ my $PROGNAME = 'check_bioctl'; my $BIOCTL = '/sbin/bioctl'; +my $DOAS = '/usr/bin/doas'; use POSIX; my $PREFIX; @@ -42,7 +44,7 @@ use utils qw($TIMEOUT %ERRORS &support); $SIG{'ALRM'} = sub { - print "ERROR: $PROGNAME timeout\n"; + say "ERROR: $PROGNAME timeout"; exit $ERRORS{'UNKNOWN'}; }; alarm($TIMEOUT); @@ -64,7 +66,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 +83,7 @@ } if ($opt_V) { - print_revision( $PROGNAME, '$Revision: 1.14 $ ' ); + print_revision(); exit $ERRORS{'OK'}; } @@ -95,7 +96,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++; @@ -115,7 +116,7 @@ } } if ( $have_results == 0 ) { - print "No results found\n"; + say 'No results found'; } exit $ERRORS{$state}; @@ -124,7 +125,7 @@ my %volumes; foreach my $d ( @{$devices} ) { - open my $bioctl, q{-|}, $BIOCTL, $d + open my $bioctl, q{-|}, $DOAS, $BIOCTL, $d or die "Couldn't open bioctl: $!\n"; LINE: while ( my $line = <$bioctl> ) { my ( $i, $item ) = parse_bioctl_line($line); @@ -150,74 +151,50 @@ return %volumes; } -{ - my $vid; +sub parse_bioctl_line { + ($_) = @_; + chomp; - sub parse_bioctl_line { - my ($line) = @_; - chomp $line; + my @o = map { s/^\s+|\s+$//g; $_ } split; + return if $o[0] eq 'Volume'; - # 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'; + state $vid = ''; + state $controller; - foreach (@o) { - s/^\s+//xms; - s/\s+$//xms; - } - - my ( $controller, $id, $status, $size, $dev, $details, $name ) = @o; - my $index = $id; - if ($controller) { - $vid = $id; - } - 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; + my $index = "$vid.$o[0]"; + if ( $o[0] !~ /^\d+$/ ) { + $controller = shift @o; + $vid = $o[0]; + $index = $vid; } + + 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; @@ -236,7 +213,7 @@ EOL - print_revision( $PROGNAME, '$Revision: 1.14 $' ); + print_revision(); print $License; @@ -244,10 +221,10 @@ } sub print_revision { - my ( $prog, $rev ) = @_; + my $rev = '$Revision: 1.21 $'; $rev =~ s/^\D+([\d\.]+)\D+$/v$1/xms; - print "$prog $rev\n"; + say "$PROGNAME $rev"; return 1; }