version 1.11, 2009/11/23 21:45:58 |
version 1.15, 2009/11/23 22:24:45 |
|
|
#!/usr/bin/perl -T |
#!/usr/bin/perl -T |
# $RedRiver: check_bioctl,v 1.10 2009/11/12 18:54:38 andrew Exp $ |
# $RedRiver: check_bioctl,v 1.14 2009/11/23 21:58:04 andrew Exp $ |
######################################################################## |
######################################################################## |
# 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 => 1; |
my $NAGIOS_OUTPUT = 0; |
|
|
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 { |
say "ERROR: $PROGNAME timeout"; |
print "ERROR: $PROGNAME timeout\n"; |
exit $ERRORS{'UNKNOWN'}; |
exit $ERRORS{'UNKNOWN'}; |
}; |
}; |
alarm($TIMEOUT); |
alarm($TIMEOUT); |
|
|
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++; |
|
|
foreach my $d ( @{$devices} ) { |
foreach my $d ( @{$devices} ) { |
open my $bioctl, q{-|}, $BIOCTL, $d |
open my $bioctl, q{-|}, $BIOCTL, $d |
or die "Couldn't open bioctl: $!\n"; |
or die "Couldn't open bioctl: $!\n"; |
while ( my $line = <$bioctl> ) { |
LINE: while ( my $line = <$bioctl> ) { |
my ( $i, $item ) = parse_bioctl_line($line); |
my ( $i, $item ) = parse_bioctl_line($line); |
|
next LINE if !defined $i; |
$volumes{$d}{$i} = $item; |
$volumes{$d}{$i} = $item; |
} |
} |
## no critic 'die' |
## no critic 'die' |
|
|
foreach my $i ( keys %{ $volumes{$d} } ) { |
foreach my $i ( keys %{ $volumes{$d} } ) { |
my $item = $volumes{$d}{$i}; |
my $item = $volumes{$d}{$i}; |
if ( $item->{device} =~ /^\d+:\d+/xms ) { |
if ( $item->{device} =~ /^\d+:\d+/xms ) { |
$item->{'volume'} = $volumes{$d}{ $i->{volume_id} }; |
$item->{'volume'} = $volumes{$d}{ $item->{volume_id} }; |
} |
} |
} |
} |
} |
} |
|
|
return %volumes; |
return %volumes; |
} |
} |
|
|
sub parse_bioctl_line { |
{ |
my ($line) = @_; |
my $vid; |
state $vid; |
my $controller; |
chomp $line; |
|
|
|
# Do these by columns cuZ that is the easiest for now |
sub parse_bioctl_line { |
my @o = unpack( "A6 A1 A11 A15 A7 A9 A*", $line ); |
my ($line) = @_; |
next if $o[0] eq 'Volume'; |
chomp $line; |
|
|
foreach (@o) { |
# Do these by columns cuZ that is the easiest for now |
s/^\s+//xms; |
my @o = unpack( "A6 A1 A11 A15 A7 A9 A*", $line ); |
s/\s+$//xms; |
return if $o[0] eq 'Volume'; |
} |
|
|
|
my ( $controller, $id, $status, $size, $dev, $details, $name ) = @o; |
foreach (@o) { |
my $index = $id; |
s/^\s+//xms; |
if ($controller) { |
s/\s+$//xms; |
$vid = $id; |
} |
} |
|
else { |
|
$index = "$vid.$id"; |
|
} |
|
|
|
my %item = ( |
my ( $c, $id, $status, $size, $dev, $details, $name ) = @o; |
type => 'volume', |
my $index = $id; |
controller => $controller, |
if ($c) { |
id => $id, |
$vid = $id; |
status => $status, |
$controller = $c; |
size => $size, |
} |
device => $dev, |
else { |
details => $details, |
$index = "$vid.$id"; |
name => $name, |
} |
volume_id => $vid, |
|
); |
|
|
|
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 { |
sub check_status { |
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; |
|
|
my ( $prog, $rev ) = @_; |
my ( $prog, $rev ) = @_; |
$rev =~ s/^\D+([\d\.]+)\D+$/v$1/xms; |
$rev =~ s/^\D+([\d\.]+)\D+$/v$1/xms; |
|
|
say "$prog $rev"; |
print "$prog $rev\n"; |
|
|
return 1; |
return 1; |
} |
} |