=================================================================== RCS file: /cvs/nagios/check_bioctl/check_bioctl,v retrieving revision 1.1 retrieving revision 1.6 diff -u -r1.1 -r1.6 --- nagios/check_bioctl/check_bioctl 2006/07/27 01:02:43 1.1 +++ nagios/check_bioctl/check_bioctl 2009/11/09 17:58:29 1.6 @@ -1,5 +1,5 @@ #!/usr/bin/perl -T -# $RedRiver$ +# $RedRiver: check_bioctl,v 1.5 2009/11/09 17:57:32 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,9 +25,10 @@ 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', + Offline => 'CRITICAL', Degraded => 'CRITICAL', Failed => 'CRITICAL', Building => 'WARNING', @@ -43,7 +42,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 +50,7 @@ my $status = GetOptions( "version|V" => \$opt_V, "help|h" => \$opt_h, - "device|d=s" => \$device, + "device|d=s" => \@devices, ); if ($status == 0) { @@ -60,104 +59,88 @@ } if ($opt_V) { - print_revision($PROGNAME,'$Revision: 1.1 $ '); + print_revision($PROGNAME,'$Revision: 1.6 $ '); 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 $volume_id; - foreach (@o) { - s/^\s+//; - s/\s+$//; - } + while (<$bioctl>) { + chomp; + # Do these by columns cuZ that is the easiest for now + 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; + my ($controller, $id, $status, $size, $dev, $details, $name) = @o; + my $index = $id; + if ($controller) { + $volume_id = $id; + } else { + $index = "$volume_id.$id"; + } - if ($controller) { - $volume_id = $id; - - $VOLUMES{$volume_id} = { + $VOLUMES{$device}{$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{$device}{$index}{'volume'} = + $VOLUMES{$device}{$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; - -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 $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'; - 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{$device}{$index}{'device'} =~ /^\d+:\d/) { + push @{ $states{$cur_state} }, sprintf("%5s %-7s %-11s %s", + $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{$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}) { - $have_results++; - $state = $error; - } -} foreach my $error (sort { $ERRORS{$b} <=> $ERRORS{$a} } keys %ERRORS) { if (exists $states{$error}) { + $have_results++; + $state = $error if $ERRORS{$state} < $ERRORS{$error}; + if (NAGIOS_OUTPUT) { print "$error (" . scalar(@{ $states{ $error } }) . ")"; unless ($error eq 'OK') { @@ -178,17 +161,16 @@ sub print_help { print < + $PROGNAME -d [ -d [ -d ... ] ] 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.1 $'); + print_revision($PROGNAME, '$Revision: 1.6 $'); }