| version 1.15, 2009/11/23 22:24:45 |
version 1.19, 2011/12/27 02:23:57 |
|
|
| #!/usr/bin/perl -T |
#!/usr/bin/perl -T |
| # $RedRiver: check_bioctl,v 1.14 2009/11/23 21:58:04 andrew Exp $ |
# $AFresh1$ |
| ######################################################################## |
######################################################################## |
| # check_bioctl *** A nagios check for OpenBSD bioctl |
# check_bioctl *** A nagios check for OpenBSD bioctl |
| # |
# |
|
|
| ######################################################################## |
######################################################################## |
| use strict; |
use strict; |
| use warnings; |
use warnings; |
| |
use 5.010; |
| |
|
| local %ENV = (); |
local %ENV = (); |
| |
|
| my $NAGIOS_OUTPUT = 0; |
my $NAGIOS_OUTPUT = 1; |
| |
|
| my $License = <<'EOL'; |
my $License = <<'EOL'; |
| Copyright (c) 2009 Andrew Fresh <andrew@afresh1.com> |
Copyright (c) 2009 Andrew Fresh <andrew@afresh1.com> |
|
|
| use utils qw($TIMEOUT %ERRORS &support); |
use utils qw($TIMEOUT %ERRORS &support); |
| |
|
| $SIG{'ALRM'} = sub { |
$SIG{'ALRM'} = sub { |
| print "ERROR: $PROGNAME timeout\n"; |
say "ERROR: $PROGNAME timeout"; |
| exit $ERRORS{'UNKNOWN'}; |
exit $ERRORS{'UNKNOWN'}; |
| }; |
}; |
| alarm($TIMEOUT); |
alarm($TIMEOUT); |
|
|
| } |
} |
| |
|
| if ($opt_V) { |
if ($opt_V) { |
| print_revision( $PROGNAME, '$Revision$ ' ); |
print_revision(); |
| exit $ERRORS{'OK'}; |
exit $ERRORS{'OK'}; |
| } |
} |
| |
|
|
|
| } |
} |
| } |
} |
| if ( $have_results == 0 ) { |
if ( $have_results == 0 ) { |
| print "No results found\n"; |
say 'No results found'; |
| } |
} |
| exit $ERRORS{$state}; |
exit $ERRORS{$state}; |
| |
|
|
|
| return %volumes; |
return %volumes; |
| } |
} |
| |
|
| { |
sub parse_bioctl_line { |
| my $vid; |
($_) = @_; |
| my $controller; |
chomp; |
| |
|
| sub parse_bioctl_line { |
my @o = map { s/^\s+|\s+$//g; $_ } split; |
| my ($line) = @_; |
return if $o[0] eq 'Volume'; |
| chomp $line; |
|
| |
|
| # Do these by columns cuZ that is the easiest for now |
state $vid = ''; |
| my @o = unpack( "A6 A1 A11 A15 A7 A9 A*", $line ); |
state $controller; |
| return if $o[0] eq 'Volume'; |
|
| |
|
| foreach (@o) { |
my $index = "$vid.$o[0]"; |
| s/^\s+//xms; |
if ( $o[0] !~ /^\d+$/ ) { |
| s/\s+$//xms; |
$controller = shift @o; |
| } |
$vid = $o[0]; |
| |
$index = $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, |
|
| { |
|
| controller => $controller, |
|
| id => $id, |
|
| status => $status, |
|
| size => $size, |
|
| device => $dev, |
|
| details => $details, |
|
| name => $name, |
|
| volume_id => $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 { |
sub check_status { |
|
|
| |
|
| EOL |
EOL |
| |
|
| print_revision( $PROGNAME, '$Revision$' ); |
print_revision(); |
| |
|
| print $License; |
print $License; |
| |
|
|
|
| } |
} |
| |
|
| sub print_revision { |
sub print_revision { |
| my ( $prog, $rev ) = @_; |
my $rev = '$Revision$'; |
| $rev =~ s/^\D+([\d\.]+)\D+$/v$1/xms; |
$rev =~ s/^\D+([\d\.]+)\D+$/v$1/xms; |
| |
|
| print "$prog $rev\n"; |
say "$PROGNAME $rev"; |
| |
|
| return 1; |
return 1; |
| } |
} |