=================================================================== RCS file: /cvs/nagios/check_bioctl/check_bioctl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- nagios/check_bioctl/check_bioctl 2006/07/27 01:02:43 1.1 +++ nagios/check_bioctl/check_bioctl 2006/07/27 02:08:13 1.2 @@ -1,5 +1,5 @@ #!/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 # @@ -43,7 +43,7 @@ my $state = 'UNKNOWN'; # tells whether the it is warning, critical, or OK my %states; # This stores the count of states; -my $device; +my @devices; my $opt_h; my $opt_V; @@ -51,7 +51,7 @@ my $status = GetOptions( "version|V" => \$opt_V, "help|h" => \$opt_h, - "device|d=s" => \$device, + "device|d=s" => \@devices, ); if ($status == 0) { @@ -60,92 +60,90 @@ } if ($opt_V) { - print_revision($PROGNAME,'$Revision: 1.1 $ '); + print_revision($PROGNAME,'$Revision: 1.2 $ '); exit $ERRORS{'OK'}; } -if ($opt_h || not $device) { +if ($opt_h || not @devices) { print_help(); exit $ERRORS{'OK'}; } -my %DISKS; my %VOLUMES; -open my $bioctl, "-|", $BIOCTL, $device or die "Couldn't open bioctl: $!"; -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'; +foreach my $device (@devices) { + open my $bioctl, "-|", $BIOCTL, $device or die "Couldn't open bioctl: $!"; + my ($controller, $volume_id); - foreach (@o) { - s/^\s+//; - s/\s+$//; - } + 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'; - #print Dumper \@o; + foreach (@o) { + s/^\s+//; + s/\s+$//; + } - my ($controller, $id, $status, $size, $dev, $details, $name) = @o; + #print Dumper \@o; - if ($controller) { - $volume_id = $id; + my ($c, $id, $status, $size, $dev, $details, $name) = @o; - $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, - id => $volume_id, + id => $id, status => $status, size => $size, device => $dev, details => $details, 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) { - next if $VOLUMES{$volume}{'device'} =~ /^\d+:\d+/; - my $cur_state = $Status_Map{ $VOLUMES{$volume}{'status'} } ? - $Status_Map{ $VOLUMES{$volume}{'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'} } : +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'} } : 'UNKNOWN'; - push @{ $states{$cur_state} }, sprintf("%5s %-7s %-11s %s", - $DISKS{$volume}{$disk}{'volume'}{'controller'}, - $DISKS{$volume}{$disk}{'device'}, - $DISKS{$volume}{$disk}{'status'}, - $DISKS{$volume}{$disk}{'name'} - ); + + if ($VOLUMES{$controller}{$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'} + ); + } else { + push @{ $states{$cur_state} }, sprintf("%5s %-7s %s", + $VOLUMES{$controller}{$index}{'controller'}, + $VOLUMES{$controller}{$index}{'device'}, + $VOLUMES{$controller}{$index}{'status'} + ); + } } } + #print Dumper \%states; $state = 'OK'; @@ -178,7 +176,7 @@ sub print_help { print < + $PROGNAME -d [ -d [ -d ... ] ] Usage: -d, --device=DEVICE @@ -189,6 +187,6 @@ EOL - print_revision($PROGNAME, '$Revision: 1.1 $'); + print_revision($PROGNAME, '$Revision: 1.2 $'); }