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

Diff for /nagios/check_bioctl/check_bioctl between version 1.6 and 1.7

version 1.6, 2009/11/09 17:58:29 version 1.7, 2009/11/09 18:00:09
Line 1 
Line 1 
 #!/usr/bin/perl -T  #!/usr/bin/perl -T
 # $RedRiver: check_bioctl,v 1.5 2009/11/09 17:57:32 andrew Exp $  # $RedRiver: check_bioctl,v 1.6 2009/11/09 17:58:29 andrew Exp $
 ########################################################################  ########################################################################
 # check_bioctl *** A nagios check for OpenBSD bioctl  # check_bioctl *** A nagios check for OpenBSD bioctl
 #  #
 # 2006.07.26 #*#*# andrew fresh <andrew@mad-techies.org>  # 2006.07.26 #*#*# andrew fresh <andrew@mad-techies.org>
 ########################################################################  ########################################################################
 # TODO:  # TODO:
 #   Really need real documentation.  #   Really need real documentation.
 ########################################################################  ########################################################################
 use strict;  use strict;
Line 23 
Line 23 
 Getopt::Long::Configure('bundling');  Getopt::Long::Configure('bundling');
   
 my $PROGNAME = "check_bioctl";  my $PROGNAME = "check_bioctl";
 my $BIOCTL = '/sbin/bioctl';  my $BIOCTL   = '/sbin/bioctl';
   
 # This maps the status we get from bioctl to something nagios can use  # This maps the status we get from bioctl to something nagios can use
 my %Status_Map = (  my %Status_Map = (
         Online      => 'OK',      Online      => 'OK',
         Offline     => 'CRITICAL',      Offline     => 'CRITICAL',
         Degraded    => 'CRITICAL',      Degraded    => 'CRITICAL',
         Failed      => 'CRITICAL',      Failed      => 'CRITICAL',
         Building    => 'WARNING',      Building    => 'WARNING',
         Rebuild     => 'WARNING',      Rebuild     => 'WARNING',
         'Hot spare' => 'OK',      'Hot spare' => 'OK',
         Unused      => 'OK',      Unused      => 'OK',
         Scrubbing   => 'WARNING',      Scrubbing   => 'WARNING',
         Invalid     => 'CRITICAL',      Invalid     => 'CRITICAL',
 );  );
   
   my $state = 'UNKNOWN';    # tells whether the it is warning, critical, or OK
 my $state = 'UNKNOWN'; # tells whether the it is warning, critical, or OK  my %states;               # This stores the count of states;
 my %states; # This stores the count of states;  
 my @devices;  my @devices;
 my $opt_h;  my $opt_h;
 my $opt_V;  my $opt_V;
   
 #Option checking  #Option checking
 my $status = GetOptions(  my $status = GetOptions(
         "version|V"    => \$opt_V,      "version|V"  => \$opt_V,
         "help|h"       => \$opt_h,      "help|h"     => \$opt_h,
         "device|d=s"   => \@devices,      "device|d=s" => \@devices,
 );  );
   
 if ($status == 0) {  if ( $status == 0 ) {
         print_help() ;      print_help();
         exit $ERRORS{'OK'};      exit $ERRORS{'OK'};
 }  }
   
 if ($opt_V) {  if ($opt_V) {
         print_revision($PROGNAME,'$Revision$ ');      print_revision( $PROGNAME, '$Revision$ ' );
         exit $ERRORS{'OK'};      exit $ERRORS{'OK'};
 }  }
   
 if ($opt_h || not @devices) {  if ( $opt_h || not @devices ) {
         print_help();      print_help();
         exit $ERRORS{'OK'};      exit $ERRORS{'OK'};
 }  }
   
 my %VOLUMES;  my %VOLUMES;
 foreach my $device (@devices) {  foreach my $device (@devices) {
         open my $bioctl, "-|", $BIOCTL, $device or die "Couldn't open bioctl: $!";      open my $bioctl, "-|", $BIOCTL, $device or die "Couldn't open bioctl: $!";
         my $volume_id;      my $volume_id;
   
         while (<$bioctl>) {      while (<$bioctl>) {
                 chomp;          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';  
   
                 foreach (@o) {          # Do these by columns cuZ that is the easiest for now
                         s/^\s+//;          my @o = unpack( "A6 A1 A11 A15 A7 A9 A*", $_ );
                         s/\s+$//;          next if $o[0] eq 'Volume';
                 }  
   
                 my ($controller, $id, $status, $size, $dev, $details, $name) = @o;          foreach (@o) {
                 my $index = $id;              s/^\s+//;
                 if ($controller) {              s/\s+$//;
                         $volume_id  = $id;          }
                 } else {  
                         $index = "$volume_id.$id";  
                 }  
   
                 $VOLUMES{$device}{$index} = {          my ( $controller, $id, $status, $size, $dev, $details, $name ) = @o;
                         type       => 'volume',          my $index = $id;
                         controller => $controller,          if ($controller) {
                         id         => $id,              $volume_id = $id;
                         status     => $status,          }
                         size       => $size,          else {
                         device     => $dev,              $index = "$volume_id.$id";
                         details    => $details,          }
                         name       => $name,  
                 };  
   
                 if ($dev =~ /^\d+:\d+/) {          $VOLUMES{$device}{$index} = {
                         $VOLUMES{$device}{$index}{'volume'} =              type       => 'volume',
                                 $VOLUMES{$device}{$volume_id};              controller => $controller,
                 }              id         => $id,
               status     => $status,
               size       => $size,
               device     => $dev,
               details    => $details,
               name       => $name,
           };
   
         }          if ( $dev =~ /^\d+:\d+/ ) {
         close $bioctl;              $VOLUMES{$device}{$index}{'volume'}
                   = $VOLUMES{$device}{$volume_id};
           }
   
       }
       close $bioctl;
 }  }
   
 foreach my $device (sort keys %VOLUMES) {  foreach my $device ( sort keys %VOLUMES ) {
         foreach my $index (sort keys %{ $VOLUMES{$device} }) {      foreach my $index ( sort keys %{ $VOLUMES{$device} } ) {
                 my $cur_state = $Status_Map{ $VOLUMES{$device}{$index}{'status'} } ?          my $cur_state
                         $Status_Map{ $VOLUMES{$device}{$index}{'status'} } :              = $Status_Map{ $VOLUMES{$device}{$index}{'status'} }
                         'UNKNOWN';              ? $Status_Map{ $VOLUMES{$device}{$index}{'status'} }
               : 'UNKNOWN';
   
                 if ($VOLUMES{$device}{$index}{'device'} =~ /^\d+:\d/) {          if ( $VOLUMES{$device}{$index}{'device'} =~ /^\d+:\d/ ) {
                         push @{ $states{$cur_state} }, sprintf("%5s %-7s %-11s %s",              push @{ $states{$cur_state} },
                                 $VOLUMES{$device}{$index}{'volume'}{'controller'},                  sprintf(
                                 $VOLUMES{$device}{$index}{'device'},                  "%5s %-7s %-11s %s",
                                 $VOLUMES{$device}{$index}{'status'},                  $VOLUMES{$device}{$index}{'volume'}{'controller'},
                                 $VOLUMES{$device}{$index}{'name'}                  $VOLUMES{$device}{$index}{'device'},
                         );                  $VOLUMES{$device}{$index}{'status'},
                 } else {                  $VOLUMES{$device}{$index}{'name'}
                         push @{ $states{$cur_state} }, sprintf("%5s %-7s %s",                  );
                                 $VOLUMES{$device}{$index}{'controller'},          }
                                 $VOLUMES{$device}{$index}{'device'},          else {
                                 $VOLUMES{$device}{$index}{'status'}              push @{ $states{$cur_state} },
                         );                  sprintf( "%5s %-7s %s",
                 }                  $VOLUMES{$device}{$index}{'controller'},
         }                  $VOLUMES{$device}{$index}{'device'},
                   $VOLUMES{$device}{$index}{'status'} );
           }
       }
 }  }
   
 my $have_results = 0;  my $have_results = 0;
 foreach my $error (sort { $ERRORS{$b} <=> $ERRORS{$a} } keys %ERRORS) {  foreach my $error ( sort { $ERRORS{$b} <=> $ERRORS{$a} } keys %ERRORS ) {
         if (exists $states{$error}) {      if ( exists $states{$error} ) {
                 $have_results++;          $have_results++;
         $state = $error if $ERRORS{$state} < $ERRORS{$error};          $state = $error if $ERRORS{$state} < $ERRORS{$error};
   
                 if (NAGIOS_OUTPUT) {          if (NAGIOS_OUTPUT) {
                         print "$error (" . scalar(@{ $states{ $error } }) . ")";              print "$error (" . scalar( @{ $states{$error} } ) . ")";
                         unless ($error eq 'OK') {              unless ( $error eq 'OK' ) {
                                 print '<br>';                  print '<br>';
                                 print map { " - $_<br>" } @{ $states{ $error } };                  print map {" - $_<br>"} @{ $states{$error} };
                         }              }
                 } else {          }
                         print "$error (" . scalar(@{ $states{ $error } }) . "):\n";          else {
                         print map { "    $_\n" } @{ $states{ $error } };              print "$error (" . scalar( @{ $states{$error} } ) . "):\n";
                 }              print map {"    $_\n"} @{ $states{$error} };
         }          }
       }
 }  }
 if ($have_results == 0) {  if ( $have_results == 0 ) {
         print "No results found\n";      print "No results found\n";
 }  }
 exit $ERRORS{$state};  exit $ERRORS{$state};
   
 sub print_help {  sub print_help {
         print <<EOL;      print <<EOL;
 $PROGNAME plugin for Nagios monitors bioctl on OpenBSD  $PROGNAME plugin for Nagios monitors bioctl on OpenBSD
     $PROGNAME -d <device> [ -d <device2> [ -d ... ] ]      $PROGNAME -d <device> [ -d <device2> [ -d ... ] ]
   
Line 170 
Line 176 
         -V (--version)    version information          -V (--version)    version information
   
 EOL  EOL
   
         print_revision($PROGNAME, '$Revision$');      print_revision( $PROGNAME, '$Revision$' );
 }  }
   

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

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