Annotation of nagios/check_bioctl/check_bioctl, Revision 1.1
1.1 ! andrew 1: #!/usr/bin/perl -T
! 2: # $RedRiver$
! 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;
! 46: my $device;
! 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,
! 54: "device|d=s" => \$device,
! 55: );
! 56:
! 57: if ($status == 0) {
! 58: print_help() ;
! 59: exit $ERRORS{'OK'};
! 60: }
! 61:
! 62: if ($opt_V) {
! 63: print_revision($PROGNAME,'$Revision: 1.14 $ ');
! 64: exit $ERRORS{'OK'};
! 65: }
! 66:
! 67: if ($opt_h || not $device) {
! 68: print_help();
! 69: exit $ERRORS{'OK'};
! 70: }
! 71:
! 72: my %DISKS;
! 73: my %VOLUMES;
! 74: open my $bioctl, "-|", $BIOCTL, $device or die "Couldn't open bioctl: $!";
! 75: my $volume_id;
! 76: while (<$bioctl>) {
! 77: chomp;
! 78: # Do these by columns cuZ that is the easiest for now
! 79: # Volume Status Size Device
! 80: my @o = unpack("A6 A1 A11 A15 A7 A9 A*", $_);
! 81: next if $o[0] eq 'Volume';
! 82:
! 83: foreach (@o) {
! 84: s/^\s+//;
! 85: s/\s+$//;
! 86: }
! 87:
! 88: #print Dumper \@o;
! 89:
! 90: my ($controller, $id, $status, $size, $dev, $details, $name) = @o;
! 91:
! 92: if ($controller) {
! 93: $volume_id = $id;
! 94:
! 95: $VOLUMES{$volume_id} = {
! 96: controller => $controller,
! 97: id => $volume_id,
! 98: status => $status,
! 99: size => $size,
! 100: device => $dev,
! 101: details => $details,
! 102: name => $name,
! 103: }
! 104: }
! 105:
! 106: if ($dev =~ /^\d+:\d+/) {
! 107: $DISKS{$volume_id}{$id} = {
! 108: volume => $VOLUMES{$volume_id},
! 109: id => $id,
! 110: status => $status,
! 111: size => $size,
! 112: device => $dev,
! 113: details => $details,
! 114: name => $name,
! 115: };
! 116: }
! 117:
! 118: }
! 119: close $bioctl;
! 120:
! 121: #print Dumper \%VOLUMES, \%DISKS;
! 122:
! 123: foreach my $volume (sort keys %VOLUMES) {
! 124: next if $VOLUMES{$volume}{'device'} =~ /^\d+:\d+/;
! 125: my $cur_state = $Status_Map{ $VOLUMES{$volume}{'status'} } ?
! 126: $Status_Map{ $VOLUMES{$volume}{'status'} } :
! 127: 'UNKNOWN';
! 128: push @{ $states{$cur_state} }, sprintf("%5s %-7s %s",
! 129: $VOLUMES{$volume}{'controller'},
! 130: $VOLUMES{$volume}{'device'},
! 131: $VOLUMES{$volume}{'status'}
! 132: );
! 133: }
! 134:
! 135: foreach my $volume (sort keys %DISKS) {
! 136: foreach my $disk (sort keys %{ $DISKS{$volume} }) {
! 137: my $cur_state = $Status_Map{ $DISKS{$volume}{$disk}{'status'} } ?
! 138: $Status_Map{ $DISKS{$volume}{$disk}{'status'} } :
! 139: 'UNKNOWN';
! 140: push @{ $states{$cur_state} }, sprintf("%5s %-7s %-11s %s",
! 141: $DISKS{$volume}{$disk}{'volume'}{'controller'},
! 142: $DISKS{$volume}{$disk}{'device'},
! 143: $DISKS{$volume}{$disk}{'status'},
! 144: $DISKS{$volume}{$disk}{'name'}
! 145: );
! 146: }
! 147: }
! 148:
! 149: #print Dumper \%states;
! 150:
! 151: $state = 'OK';
! 152: my $have_results = 0;
! 153: foreach my $error (sort { $ERRORS{$a} <=> $ERRORS{$b} } keys %ERRORS) {
! 154: if (exists $states{$error}) {
! 155: $have_results++;
! 156: $state = $error;
! 157: }
! 158: }
! 159: foreach my $error (sort { $ERRORS{$b} <=> $ERRORS{$a} } keys %ERRORS) {
! 160: if (exists $states{$error}) {
! 161: if (NAGIOS_OUTPUT) {
! 162: print "$error (" . scalar(@{ $states{ $error } }) . ")";
! 163: unless ($error eq 'OK') {
! 164: print '<br>';
! 165: print map { " - $_<br>" } @{ $states{ $error } };
! 166: }
! 167: } else {
! 168: print "$error (" . scalar(@{ $states{ $error } }) . "):\n";
! 169: print map { " $_\n" } @{ $states{ $error } };
! 170: }
! 171: }
! 172: }
! 173: if ($have_results == 0) {
! 174: print "No results found\n";
! 175: }
! 176: exit $ERRORS{$state};
! 177:
! 178: sub print_help {
! 179: print <<EOL;
! 180: $PROGNAME plugin for Nagios monitors bioctl on OpenBSD
! 181: $PROGNAME -d <device>
! 182:
! 183: Usage:
! 184: -d, --device=DEVICE
! 185: DEVICE to check. Can either be a disk, as in sd0
! 186: or a raid card like ami0
! 187: -h (--help) usage help
! 188: -V (--version) version information
! 189:
! 190: EOL
! 191:
! 192: print_revision($PROGNAME, '$Revision: 1.14 $');
! 193: }
! 194:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>