[BACK]Return to check_bioctl CVS log [TXT][DIR] Up to [local] / nagios / check_bioctl

Annotation of nagios/check_bioctl/check_bioctl, Revision 1.8

1.1       andrew      1: #!/usr/bin/perl -T
1.8     ! andrew      2: # $RedRiver: check_bioctl,v 1.7 2009/11/09 18:00:09 andrew Exp $
1.1       andrew      3: ########################################################################
                      4: # check_bioctl *** A nagios check for OpenBSD bioctl
1.7       andrew      5: #
1.1       andrew      6: # 2006.07.26 #*#*# andrew fresh <andrew@mad-techies.org>
                      7: ########################################################################
                      8: use strict;
                      9: use warnings;
                     10:
                     11: %ENV = ();
                     12:
                     13: use constant NAGIOS_OUTPUT => 1;
                     14:
                     15: use POSIX;
                     16: use lib "/usr/local/libexec/nagios";
                     17: use utils qw($TIMEOUT %ERRORS &print_revision &support);
                     18:
                     19: use Getopt::Long;
                     20: Getopt::Long::Configure('bundling');
                     21:
                     22: my $PROGNAME = "check_bioctl";
1.7       andrew     23: my $BIOCTL   = '/sbin/bioctl';
1.1       andrew     24:
1.3       andrew     25: # This maps the status we get from bioctl to something nagios can use
1.1       andrew     26: my %Status_Map = (
1.7       andrew     27:     Online      => 'OK',
                     28:     Offline     => 'CRITICAL',
                     29:     Degraded    => 'CRITICAL',
                     30:     Failed      => 'CRITICAL',
                     31:     Building    => 'WARNING',
                     32:     Rebuild     => 'WARNING',
                     33:     'Hot spare' => 'OK',
                     34:     Unused      => 'OK',
                     35:     Scrubbing   => 'WARNING',
                     36:     Invalid     => 'CRITICAL',
1.1       andrew     37: );
                     38:
1.7       andrew     39: my $state = 'UNKNOWN';    # tells whether the it is warning, critical, or OK
                     40: my %states;               # This stores the count of states;
1.2       andrew     41: my @devices;
1.1       andrew     42: my $opt_h;
                     43: my $opt_V;
                     44:
                     45: #Option checking
                     46: my $status = GetOptions(
1.7       andrew     47:     "version|V"  => \$opt_V,
                     48:     "help|h"     => \$opt_h,
                     49:     "device|d=s" => \@devices,
1.1       andrew     50: );
                     51:
1.7       andrew     52: if ( $status == 0 ) {
                     53:     print_help();
                     54:     exit $ERRORS{'OK'};
1.1       andrew     55: }
                     56:
                     57: if ($opt_V) {
1.8     ! andrew     58:     print_revision( $PROGNAME, '$Revision: 1.7 $ ' );
1.7       andrew     59:     exit $ERRORS{'OK'};
1.1       andrew     60: }
                     61:
1.7       andrew     62: if ( $opt_h || not @devices ) {
                     63:     print_help();
                     64:     exit $ERRORS{'OK'};
1.1       andrew     65: }
                     66:
                     67: my %VOLUMES;
1.2       andrew     68: foreach my $device (@devices) {
1.8     ! andrew     69:     open my $bioctl, '-|', $BIOCTL, $device or die "Couldn't open bioctl: $!";
1.7       andrew     70:     my $volume_id;
                     71:
                     72:     while (<$bioctl>) {
                     73:         chomp;
1.2       andrew     74:
1.7       andrew     75:         # Do these by columns cuZ that is the easiest for now
                     76:         my @o = unpack( "A6 A1 A11 A15 A7 A9 A*", $_ );
                     77:         next if $o[0] eq 'Volume';
                     78:
                     79:         foreach (@o) {
                     80:             s/^\s+//;
                     81:             s/\s+$//;
                     82:         }
                     83:
                     84:         my ( $controller, $id, $status, $size, $dev, $details, $name ) = @o;
                     85:         my $index = $id;
                     86:         if ($controller) {
                     87:             $volume_id = $id;
                     88:         }
                     89:         else {
                     90:             $index = "$volume_id.$id";
                     91:         }
                     92:
                     93:         $VOLUMES{$device}{$index} = {
                     94:             type       => 'volume',
                     95:             controller => $controller,
                     96:             id         => $id,
                     97:             status     => $status,
                     98:             size       => $size,
                     99:             device     => $dev,
                    100:             details    => $details,
                    101:             name       => $name,
                    102:         };
                    103:
                    104:         if ( $dev =~ /^\d+:\d+/ ) {
                    105:             $VOLUMES{$device}{$index}{'volume'}
                    106:                 = $VOLUMES{$device}{$volume_id};
                    107:         }
                    108:
                    109:     }
                    110:     close $bioctl;
                    111: }
                    112:
                    113: foreach my $device ( sort keys %VOLUMES ) {
                    114:     foreach my $index ( sort keys %{ $VOLUMES{$device} } ) {
                    115:         my $cur_state
                    116:             = $Status_Map{ $VOLUMES{$device}{$index}{'status'} }
                    117:             ? $Status_Map{ $VOLUMES{$device}{$index}{'status'} }
                    118:             : 'UNKNOWN';
                    119:
                    120:         if ( $VOLUMES{$device}{$index}{'device'} =~ /^\d+:\d/ ) {
                    121:             push @{ $states{$cur_state} },
                    122:                 sprintf(
                    123:                 "%5s %-7s %-11s %s",
                    124:                 $VOLUMES{$device}{$index}{'volume'}{'controller'},
                    125:                 $VOLUMES{$device}{$index}{'device'},
                    126:                 $VOLUMES{$device}{$index}{'status'},
                    127:                 $VOLUMES{$device}{$index}{'name'}
                    128:                 );
                    129:         }
                    130:         else {
                    131:             push @{ $states{$cur_state} },
                    132:                 sprintf( "%5s %-7s %s",
                    133:                 $VOLUMES{$device}{$index}{'controller'},
                    134:                 $VOLUMES{$device}{$index}{'device'},
                    135:                 $VOLUMES{$device}{$index}{'status'} );
                    136:         }
                    137:     }
1.1       andrew    138: }
                    139:
                    140: my $have_results = 0;
1.8     ! andrew    141: $state = 'OK';
1.7       andrew    142: foreach my $error ( sort { $ERRORS{$b} <=> $ERRORS{$a} } keys %ERRORS ) {
                    143:     if ( exists $states{$error} ) {
                    144:         $have_results++;
1.6       andrew    145:         $state = $error if $ERRORS{$state} < $ERRORS{$error};
1.5       andrew    146:
1.7       andrew    147:         if (NAGIOS_OUTPUT) {
                    148:             print "$error (" . scalar( @{ $states{$error} } ) . ")";
1.8     ! andrew    149:             if ( $error ne 'OK' ) {
1.7       andrew    150:                 print '<br>';
                    151:                 print map {" - $_<br>"} @{ $states{$error} };
                    152:             }
                    153:         }
                    154:         else {
                    155:             print "$error (" . scalar( @{ $states{$error} } ) . "):\n";
                    156:             print map {"    $_\n"} @{ $states{$error} };
                    157:         }
                    158:     }
1.1       andrew    159: }
1.7       andrew    160: if ( $have_results == 0 ) {
                    161:     print "No results found\n";
1.1       andrew    162: }
                    163: exit $ERRORS{$state};
                    164:
                    165: sub print_help {
1.7       andrew    166:     print <<EOL;
1.1       andrew    167: $PROGNAME plugin for Nagios monitors bioctl on OpenBSD
1.2       andrew    168:     $PROGNAME -d <device> [ -d <device2> [ -d ... ] ]
1.1       andrew    169:
                    170: Usage:
                    171:     -d, --device=DEVICE
1.3       andrew    172:         DEVICE to check.  Can be any device that bioctl(8) accepts
1.1       andrew    173:     -h (--help)       usage help
                    174:        -V (--version)    version information
                    175:
                    176: EOL
1.7       andrew    177:
1.8     ! andrew    178:     print_revision( $PROGNAME, '$Revision: 1.7 $' );
1.1       andrew    179: }
                    180:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>