=================================================================== RCS file: /cvs/nagios/check_bioctl/check_bioctl,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- nagios/check_bioctl/check_bioctl 2006/07/27 02:08:13 1.2 +++ nagios/check_bioctl/check_bioctl 2006/07/27 21:34:02 1.3 @@ -1,5 +1,5 @@ #!/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 # @@ -11,8 +11,6 @@ use strict; use warnings; -#use Data::Dumper; - %ENV = (); use constant NAGIOS_OUTPUT => 1; @@ -27,6 +25,7 @@ my $PROGNAME = "check_bioctl"; my $BIOCTL = '/sbin/bioctl'; +# This maps the status we get from bioctl to something nagios can use my %Status_Map = ( Online => 'OK', Offline => 'WARNING', @@ -60,7 +59,7 @@ } if ($opt_V) { - print_revision($PROGNAME,'$Revision: 1.2 $ '); + print_revision($PROGNAME,'$Revision: 1.3 $ '); exit $ERRORS{'OK'}; } @@ -72,12 +71,11 @@ my %VOLUMES; foreach my $device (@devices) { open my $bioctl, "-|", $BIOCTL, $device or die "Couldn't open bioctl: $!"; - my ($controller, $volume_id); + my $volume_id; while (<$bioctl>) { 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'; @@ -86,19 +84,15 @@ s/\s+$//; } - #print Dumper \@o; - - my ($c, $id, $status, $size, $dev, $details, $name) = @o; - + my ($controller, $id, $status, $size, $dev, $details, $name) = @o; my $index = $id; - if ($c) { - $controller = $c; + if ($controller) { $volume_id = $id; } else { $index = "$volume_id.$id"; } - $VOLUMES{$controller}{$index} = { + $VOLUMES{$device}{$index} = { type => 'volume', controller => $controller, id => $id, @@ -110,43 +104,37 @@ }; if ($dev =~ /^\d+:\d+/) { - $VOLUMES{$controller}{$index}{'volume'} = - $VOLUMES{$controller}{$volume_id}; + $VOLUMES{$device}{$index}{'volume'} = + $VOLUMES{$device}{$volume_id}; } } close $bioctl; } -#print Dumper \%VOLUMES; - -foreach my $controller (sort keys %VOLUMES) { - foreach my $index (sort keys %{ $VOLUMES{$controller} }) { - my $cur_state = $Status_Map{ $VOLUMES{$controller}{$index}{'status'} } ? - $Status_Map{ $VOLUMES{$controller}{$index}{'status'} } : +foreach my $device (sort keys %VOLUMES) { + foreach my $index (sort keys %{ $VOLUMES{$device} }) { + my $cur_state = $Status_Map{ $VOLUMES{$device}{$index}{'status'} } ? + $Status_Map{ $VOLUMES{$device}{$index}{'status'} } : 'UNKNOWN'; - if ($VOLUMES{$controller}{$index}{'device'} =~ /^\d+:\d/) { + if ($VOLUMES{$device}{$index}{'device'} =~ /^\d+:\d/) { push @{ $states{$cur_state} }, sprintf("%5s %-7s %-11s %s", - $VOLUMES{$controller}{$index}{'volume'}{'controller'}, - $VOLUMES{$controller}{$index}{'device'}, - $VOLUMES{$controller}{$index}{'status'}, - $VOLUMES{$controller}{$index}{'name'} + $VOLUMES{$device}{$index}{'volume'}{'controller'}, + $VOLUMES{$device}{$index}{'device'}, + $VOLUMES{$device}{$index}{'status'}, + $VOLUMES{$device}{$index}{'name'} ); } else { push @{ $states{$cur_state} }, sprintf("%5s %-7s %s", - $VOLUMES{$controller}{$index}{'controller'}, - $VOLUMES{$controller}{$index}{'device'}, - $VOLUMES{$controller}{$index}{'status'} + $VOLUMES{$device}{$index}{'controller'}, + $VOLUMES{$device}{$index}{'device'}, + $VOLUMES{$device}{$index}{'status'} ); } } } - -#print Dumper \%states; - -$state = 'OK'; my $have_results = 0; foreach my $error (sort { $ERRORS{$a} <=> $ERRORS{$b} } keys %ERRORS) { if (exists $states{$error}) { @@ -180,13 +168,12 @@ Usage: -d, --device=DEVICE - DEVICE to check. Can either be a disk, as in sd0 - or a raid card like ami0 + DEVICE to check. Can be any device that bioctl(8) accepts -h (--help) usage help -V (--version) version information EOL - print_revision($PROGNAME, '$Revision: 1.2 $'); + print_revision($PROGNAME, '$Revision: 1.3 $'); }