version 1.2, 2006/07/27 02:08:13 |
version 1.3, 2006/07/27 21:34:02 |
|
|
#!/usr/bin/perl -T |
#!/usr/bin/perl -T |
# $RedRiver: check_bioctl,v 1.1 2006/07/27 00:02:43 andrew Exp $ |
# $RedRiver: check_bioctl,v 1.2 2006/07/27 01:08:13 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 Data::Dumper; |
|
|
|
%ENV = (); |
%ENV = (); |
|
|
use constant NAGIOS_OUTPUT => 1; |
use constant NAGIOS_OUTPUT => 1; |
|
|
my $PROGNAME = "check_bioctl"; |
my $PROGNAME = "check_bioctl"; |
my $BIOCTL = '/sbin/bioctl'; |
my $BIOCTL = '/sbin/bioctl'; |
|
|
|
# This maps the status we get from bioctl to something nagios can use |
my %Status_Map = ( |
my %Status_Map = ( |
Online => 'OK', |
Online => 'OK', |
Offline => 'WARNING', |
Offline => 'WARNING', |
|
|
my %VOLUMES; |
my %VOLUMES; |
foreach my $device (@devices) { |
foreach my $device (@devices) { |
open my $bioctl, "-|", $BIOCTL, $device or die "Couldn't open bioctl: $!"; |
open my $bioctl, "-|", $BIOCTL, $device or die "Couldn't open bioctl: $!"; |
my ($controller, $volume_id); |
my $volume_id; |
|
|
while (<$bioctl>) { |
while (<$bioctl>) { |
chomp; |
chomp; |
# Do these by columns cuZ that is the easiest for now |
# 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*", $_); |
my @o = unpack("A6 A1 A11 A15 A7 A9 A*", $_); |
next if $o[0] eq 'Volume'; |
next if $o[0] eq 'Volume'; |
|
|
|
|
s/\s+$//; |
s/\s+$//; |
} |
} |
|
|
#print Dumper \@o; |
my ($controller, $id, $status, $size, $dev, $details, $name) = @o; |
|
|
my ($c, $id, $status, $size, $dev, $details, $name) = @o; |
|
|
|
my $index = $id; |
my $index = $id; |
if ($c) { |
if ($controller) { |
$controller = $c; |
|
$volume_id = $id; |
$volume_id = $id; |
} else { |
} else { |
$index = "$volume_id.$id"; |
$index = "$volume_id.$id"; |
} |
} |
|
|
$VOLUMES{$controller}{$index} = { |
$VOLUMES{$device}{$index} = { |
type => 'volume', |
type => 'volume', |
controller => $controller, |
controller => $controller, |
id => $id, |
id => $id, |
|
|
}; |
}; |
|
|
if ($dev =~ /^\d+:\d+/) { |
if ($dev =~ /^\d+:\d+/) { |
$VOLUMES{$controller}{$index}{'volume'} = |
$VOLUMES{$device}{$index}{'volume'} = |
$VOLUMES{$controller}{$volume_id}; |
$VOLUMES{$device}{$volume_id}; |
} |
} |
|
|
} |
} |
close $bioctl; |
close $bioctl; |
} |
} |
|
|
#print Dumper \%VOLUMES; |
foreach my $device (sort keys %VOLUMES) { |
|
foreach my $index (sort keys %{ $VOLUMES{$device} }) { |
foreach my $controller (sort keys %VOLUMES) { |
my $cur_state = $Status_Map{ $VOLUMES{$device}{$index}{'status'} } ? |
foreach my $index (sort keys %{ $VOLUMES{$controller} }) { |
$Status_Map{ $VOLUMES{$device}{$index}{'status'} } : |
my $cur_state = $Status_Map{ $VOLUMES{$controller}{$index}{'status'} } ? |
|
$Status_Map{ $VOLUMES{$controller}{$index}{'status'} } : |
|
'UNKNOWN'; |
'UNKNOWN'; |
|
|
if ($VOLUMES{$controller}{$index}{'device'} =~ /^\d+:\d/) { |
if ($VOLUMES{$device}{$index}{'device'} =~ /^\d+:\d/) { |
push @{ $states{$cur_state} }, sprintf("%5s %-7s %-11s %s", |
push @{ $states{$cur_state} }, sprintf("%5s %-7s %-11s %s", |
$VOLUMES{$controller}{$index}{'volume'}{'controller'}, |
$VOLUMES{$device}{$index}{'volume'}{'controller'}, |
$VOLUMES{$controller}{$index}{'device'}, |
$VOLUMES{$device}{$index}{'device'}, |
$VOLUMES{$controller}{$index}{'status'}, |
$VOLUMES{$device}{$index}{'status'}, |
$VOLUMES{$controller}{$index}{'name'} |
$VOLUMES{$device}{$index}{'name'} |
); |
); |
} else { |
} else { |
push @{ $states{$cur_state} }, sprintf("%5s %-7s %s", |
push @{ $states{$cur_state} }, sprintf("%5s %-7s %s", |
$VOLUMES{$controller}{$index}{'controller'}, |
$VOLUMES{$device}{$index}{'controller'}, |
$VOLUMES{$controller}{$index}{'device'}, |
$VOLUMES{$device}{$index}{'device'}, |
$VOLUMES{$controller}{$index}{'status'} |
$VOLUMES{$device}{$index}{'status'} |
); |
); |
} |
} |
} |
} |
} |
} |
|
|
|
|
#print Dumper \%states; |
|
|
|
$state = 'OK'; |
|
my $have_results = 0; |
my $have_results = 0; |
foreach my $error (sort { $ERRORS{$a} <=> $ERRORS{$b} } keys %ERRORS) { |
foreach my $error (sort { $ERRORS{$a} <=> $ERRORS{$b} } keys %ERRORS) { |
if (exists $states{$error}) { |
if (exists $states{$error}) { |
|
|
|
|
Usage: |
Usage: |
-d, --device=DEVICE |
-d, --device=DEVICE |
DEVICE to check. Can either be a disk, as in sd0 |
DEVICE to check. Can be any device that bioctl(8) accepts |
or a raid card like ami0 |
|
-h (--help) usage help |
-h (--help) usage help |
-V (--version) version information |
-V (--version) version information |
|
|