version 1.14, 2009/11/23 21:58:04 |
version 1.18, 2011/12/27 02:12:38 |
|
|
#!/usr/bin/perl -T |
#!/usr/bin/perl -T |
# $RedRiver: check_bioctl,v 1.13 2009/11/23 21:57:31 andrew Exp $ |
# $RedRiver: check_bioctl,v 1.15 2009/11/23 22:24:45 andrew Exp $ |
######################################################################## |
######################################################################## |
# check_bioctl *** A nagios check for OpenBSD bioctl |
# check_bioctl *** A nagios check for OpenBSD bioctl |
# |
# |
|
|
Invalid => 'CRITICAL', |
Invalid => 'CRITICAL', |
); |
); |
|
|
my $state = 'UNKNOWN'; # tells whether the it is warning, critical, or OK |
|
my @devices; |
my @devices; |
my $opt_h; |
my $opt_h; |
my $opt_V; |
my $opt_V; |
|
|
my %STATES = check_status( \%VOLUMES ); |
my %STATES = check_status( \%VOLUMES ); |
|
|
my $have_results = 0; |
my $have_results = 0; |
$state = 'OK'; |
my $state = 'OK'; |
foreach my $error ( sort { $ERRORS{$b} <=> $ERRORS{$a} } keys %ERRORS ) { |
foreach my $error ( sort { $ERRORS{$b} <=> $ERRORS{$a} } keys %ERRORS ) { |
if ( exists $STATES{$error} ) { |
if ( exists $STATES{$error} ) { |
$have_results++; |
$have_results++; |
|
|
|
|
{ |
{ |
my $vid; |
my $vid; |
|
my $controller; |
|
|
sub parse_bioctl_line { |
sub parse_bioctl_line { |
my ($line) = @_; |
($_) = @_; |
chomp $line; |
chomp; |
|
|
# Do these by columns cuZ that is the easiest for now |
my @o = map { s/^\s+|\s+$//g; $_ } split; |
my @o = unpack( "A6 A1 A11 A15 A7 A9 A*", $line ); |
|
return if $o[0] eq 'Volume'; |
return if $o[0] eq 'Volume'; |
|
|
foreach (@o) { |
$vid ||= ''; |
s/^\s+//xms; |
|
s/\s+$//xms; |
|
} |
|
|
|
my ( $controller, $id, $status, $size, $dev, $details, $name ) = @o; |
my $index = "$vid.$o[0]"; |
my $index = $id; |
if ( $o[0] !~ /^\d+$/ ) { |
if ($controller) { |
$controller = shift @o; |
$vid = $id; |
$vid = $o[0]; |
|
$index = $vid; |
} |
} |
else { |
|
$index = "$vid.$id"; |
|
} |
|
|
|
my %item = ( |
return $index, |
type => 'volume', |
{ |
controller => $controller, |
controller => $controller, |
id => $id, |
volume_id => $vid, |
status => $status, |
id => shift @o, |
size => $size, |
status => shift @o, |
device => $dev, |
size => shift @o, |
details => $details, |
device => shift @o, |
name => $name, |
name => shift @o, |
volume_id => $vid, |
description => join ' ', |
); |
@o, |
|
}; |
return $index, \%item; |
|
} |
} |
} |
} |
|
|
|
|
my ($volumes) = @_; |
my ($volumes) = @_; |
|
|
my %states; |
my %states; |
foreach my $device ( sort keys %{$volumes} ) { |
foreach my $d ( sort keys %{$volumes} ) { |
foreach my $index ( sort keys %{ $volumes->{$device} } ) { |
foreach my $i ( sort { $a <=> $b } keys %{ $volumes->{$d} } ) { |
my $cur_volume = $volumes->{$device}->{$index}; |
my $volume = $volumes->{$d}->{$i}; |
my $cur_state = $Status_Map{ $cur_volume->{'status'} } |
my $state = $Status_Map{ $volume->{'status'} } || 'UNKNOWN'; |
|| 'UNKNOWN'; |
|
|
|
if ( $cur_volume->{'device'} =~ /^\d+:\d/xms ) { |
push @{ $states{$state} }, |
push @{ $states{$cur_state} }, |
sprintf( |
sprintf( |
"%5s %-7s %-11s %s", |
"%5s %-7s %-11s %s", |
$volume->{'controller'}, $volume->{'device'}, |
$cur_volume->{'volume'}{'controller'}, |
$volume->{'status'}, $volume->{'name'} |
$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'} ); |
|
} |
|
} |
} |
} |
} |
return %states; |
return %states; |