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

Annotation of nagios/check_bioctl/check_bioctl, Revision 1.7

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

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