=================================================================== RCS file: /cvs/nagios/check_bioctl/check_bioctl,v retrieving revision 1.15 retrieving revision 1.20 diff -u -r1.15 -r1.20 --- nagios/check_bioctl/check_bioctl 2009/11/23 22:24:45 1.15 +++ nagios/check_bioctl/check_bioctl 2014/06/27 19:59:56 1.20 @@ -1,5 +1,5 @@ #!/usr/bin/perl -T -# $RedRiver: check_bioctl,v 1.14 2009/11/23 21:58:04 andrew Exp $ +# $AFresh1: check_bioctl,v 1.19 2011/12/27 02:23:57 andrew Exp $ ######################################################################## # check_bioctl *** A nagios check for OpenBSD bioctl # @@ -7,10 +7,11 @@ ######################################################################## use strict; use warnings; +use 5.010; local %ENV = (); -my $NAGIOS_OUTPUT = 0; +my $NAGIOS_OUTPUT = 1; my $License = <<'EOL'; Copyright (c) 2009 Andrew Fresh @@ -29,6 +30,7 @@ my $PROGNAME = 'check_bioctl'; my $BIOCTL = '/sbin/bioctl'; +my $SUDO = '/usr/bin/sudo'; 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); @@ -81,7 +83,7 @@ } if ($opt_V) { - print_revision( $PROGNAME, '$Revision: 1.15 $ ' ); + print_revision(); exit $ERRORS{'OK'}; } @@ -114,7 +116,7 @@ } } if ( $have_results == 0 ) { - print "No results found\n"; + say 'No results found'; } exit $ERRORS{$state}; @@ -123,7 +125,7 @@ my %volumes; foreach my $d ( @{$devices} ) { - open my $bioctl, q{-|}, $BIOCTL, $d + open my $bioctl, q{-|}, $SUDO, $BIOCTL, $d or die "Couldn't open bioctl: $!\n"; LINE: while ( my $line = <$bioctl> ) { my ( $i, $item ) = parse_bioctl_line($line); @@ -149,45 +151,33 @@ return %volumes; } -{ - my $vid; - my $controller; +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 ( $c, $id, $status, $size, $dev, $details, $name ) = @o; - my $index = $id; - if ($c) { - $vid = $id; - $controller = $c; - } - else { - $index = "$vid.$id"; - } - - return $index, - { - controller => $controller, - id => $id, - status => $status, - size => $size, - device => $dev, - details => $details, - name => $name, - volume_id => $vid, - }; + 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 { @@ -223,7 +213,7 @@ EOL - print_revision( $PROGNAME, '$Revision: 1.15 $' ); + print_revision(); print $License; @@ -231,10 +221,10 @@ } sub print_revision { - my ( $prog, $rev ) = @_; + my $rev = '$Revision: 1.20 $'; $rev =~ s/^\D+([\d\.]+)\D+$/v$1/xms; - print "$prog $rev\n"; + say "$PROGNAME $rev"; return 1; }