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

Annotation of nagios/check_bioctl/check_bioctl, Revision 1.2

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

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