version 1.1, 2006/07/27 01:02:43 |
version 1.2, 2006/07/27 02:08:13 |
|
|
#!/usr/bin/perl -T |
#!/usr/bin/perl -T |
# $RedRiver$ |
# $RedRiver: check_bioctl,v 1.1 2006/07/27 00:02:43 andrew Exp $ |
######################################################################## |
######################################################################## |
# check_bioctl *** A nagios check for OpenBSD bioctl |
# check_bioctl *** A nagios check for OpenBSD bioctl |
# |
# |
|
|
|
|
my $state = 'UNKNOWN'; # tells whether the it is warning, critical, or OK |
my $state = 'UNKNOWN'; # tells whether the it is warning, critical, or OK |
my %states; # This stores the count of states; |
my %states; # This stores the count of states; |
my $device; |
my @devices; |
my $opt_h; |
my $opt_h; |
my $opt_V; |
my $opt_V; |
|
|
|
|
my $status = GetOptions( |
my $status = GetOptions( |
"version|V" => \$opt_V, |
"version|V" => \$opt_V, |
"help|h" => \$opt_h, |
"help|h" => \$opt_h, |
"device|d=s" => \$device, |
"device|d=s" => \@devices, |
); |
); |
|
|
if ($status == 0) { |
if ($status == 0) { |
|
|
exit $ERRORS{'OK'}; |
exit $ERRORS{'OK'}; |
} |
} |
|
|
if ($opt_h || not $device) { |
if ($opt_h || not @devices) { |
print_help(); |
print_help(); |
exit $ERRORS{'OK'}; |
exit $ERRORS{'OK'}; |
} |
} |
|
|
my %DISKS; |
|
my %VOLUMES; |
my %VOLUMES; |
open my $bioctl, "-|", $BIOCTL, $device or die "Couldn't open bioctl: $!"; |
foreach my $device (@devices) { |
my $volume_id; |
open my $bioctl, "-|", $BIOCTL, $device or die "Couldn't open bioctl: $!"; |
while (<$bioctl>) { |
my ($controller, $volume_id); |
chomp; |
|
# Do these by columns cuZ that is the easiest for now |
|
# Volume Status Size Device |
|
my @o = unpack("A6 A1 A11 A15 A7 A9 A*", $_); |
|
next if $o[0] eq 'Volume'; |
|
|
|
foreach (@o) { |
while (<$bioctl>) { |
s/^\s+//; |
chomp; |
s/\s+$//; |
# Do these by columns cuZ that is the easiest for now |
} |
# Volume Status Size Device |
|
my @o = unpack("A6 A1 A11 A15 A7 A9 A*", $_); |
|
next if $o[0] eq 'Volume'; |
|
|
#print Dumper \@o; |
foreach (@o) { |
|
s/^\s+//; |
|
s/\s+$//; |
|
} |
|
|
my ($controller, $id, $status, $size, $dev, $details, $name) = @o; |
#print Dumper \@o; |
|
|
if ($controller) { |
my ($c, $id, $status, $size, $dev, $details, $name) = @o; |
$volume_id = $id; |
|
|
|
$VOLUMES{$volume_id} = { |
my $index = $id; |
|
if ($c) { |
|
$controller = $c; |
|
$volume_id = $id; |
|
} else { |
|
$index = "$volume_id.$id"; |
|
} |
|
|
|
$VOLUMES{$controller}{$index} = { |
|
type => 'volume', |
controller => $controller, |
controller => $controller, |
id => $volume_id, |
id => $id, |
status => $status, |
status => $status, |
size => $size, |
size => $size, |
device => $dev, |
device => $dev, |
details => $details, |
details => $details, |
name => $name, |
name => $name, |
|
}; |
|
|
|
if ($dev =~ /^\d+:\d+/) { |
|
$VOLUMES{$controller}{$index}{'volume'} = |
|
$VOLUMES{$controller}{$volume_id}; |
} |
} |
} |
|
|
|
if ($dev =~ /^\d+:\d+/) { |
|
$DISKS{$volume_id}{$id} = { |
|
volume => $VOLUMES{$volume_id}, |
|
id => $id, |
|
status => $status, |
|
size => $size, |
|
device => $dev, |
|
details => $details, |
|
name => $name, |
|
}; |
|
} |
} |
|
close $bioctl; |
} |
} |
close $bioctl; |
|
|
|
#print Dumper \%VOLUMES, \%DISKS; |
#print Dumper \%VOLUMES; |
|
|
foreach my $volume (sort keys %VOLUMES) { |
foreach my $controller (sort keys %VOLUMES) { |
next if $VOLUMES{$volume}{'device'} =~ /^\d+:\d+/; |
foreach my $index (sort keys %{ $VOLUMES{$controller} }) { |
my $cur_state = $Status_Map{ $VOLUMES{$volume}{'status'} } ? |
my $cur_state = $Status_Map{ $VOLUMES{$controller}{$index}{'status'} } ? |
$Status_Map{ $VOLUMES{$volume}{'status'} } : |
$Status_Map{ $VOLUMES{$controller}{$index}{'status'} } : |
'UNKNOWN'; |
|
push @{ $states{$cur_state} }, sprintf("%5s %-7s %s", |
|
$VOLUMES{$volume}{'controller'}, |
|
$VOLUMES{$volume}{'device'}, |
|
$VOLUMES{$volume}{'status'} |
|
); |
|
} |
|
|
|
foreach my $volume (sort keys %DISKS) { |
|
foreach my $disk (sort keys %{ $DISKS{$volume} }) { |
|
my $cur_state = $Status_Map{ $DISKS{$volume}{$disk}{'status'} } ? |
|
$Status_Map{ $DISKS{$volume}{$disk}{'status'} } : |
|
'UNKNOWN'; |
'UNKNOWN'; |
push @{ $states{$cur_state} }, sprintf("%5s %-7s %-11s %s", |
|
$DISKS{$volume}{$disk}{'volume'}{'controller'}, |
if ($VOLUMES{$controller}{$index}{'device'} =~ /^\d+:\d/) { |
$DISKS{$volume}{$disk}{'device'}, |
push @{ $states{$cur_state} }, sprintf("%5s %-7s %-11s %s", |
$DISKS{$volume}{$disk}{'status'}, |
$VOLUMES{$controller}{$index}{'volume'}{'controller'}, |
$DISKS{$volume}{$disk}{'name'} |
$VOLUMES{$controller}{$index}{'device'}, |
); |
$VOLUMES{$controller}{$index}{'status'}, |
|
$VOLUMES{$controller}{$index}{'name'} |
|
); |
|
} else { |
|
push @{ $states{$cur_state} }, sprintf("%5s %-7s %s", |
|
$VOLUMES{$controller}{$index}{'controller'}, |
|
$VOLUMES{$controller}{$index}{'device'}, |
|
$VOLUMES{$controller}{$index}{'status'} |
|
); |
|
} |
} |
} |
} |
} |
|
|
|
|
#print Dumper \%states; |
#print Dumper \%states; |
|
|
$state = 'OK'; |
$state = 'OK'; |
|
|
sub print_help { |
sub print_help { |
print <<EOL; |
print <<EOL; |
$PROGNAME plugin for Nagios monitors bioctl on OpenBSD |
$PROGNAME plugin for Nagios monitors bioctl on OpenBSD |
$PROGNAME -d <device> |
$PROGNAME -d <device> [ -d <device2> [ -d ... ] ] |
|
|
Usage: |
Usage: |
-d, --device=DEVICE |
-d, --device=DEVICE |