[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.12 and 1.20

version 1.12, 2009/11/23 21:52:53 version 1.20, 2014/06/27 19:59:56
Line 1 
Line 1 
 #!/usr/bin/perl -T  #!/usr/bin/perl -T
 # $RedRiver: check_bioctl,v 1.11 2009/11/23 21:45:58 andrew Exp $  # $AFresh1: check_bioctl,v 1.19 2011/12/27 02:23:57 andrew Exp $
 ########################################################################  ########################################################################
 # check_bioctl *** A nagios check for OpenBSD bioctl  # check_bioctl *** A nagios check for OpenBSD bioctl
 #  #
Line 7 
Line 7 
 ########################################################################  ########################################################################
 use strict;  use strict;
 use warnings;  use warnings;
   use 5.010;
   
 local %ENV = ();  local %ENV = ();
   
Line 29 
Line 30 
   
 my $PROGNAME = 'check_bioctl';  my $PROGNAME = 'check_bioctl';
 my $BIOCTL   = '/sbin/bioctl';  my $BIOCTL   = '/sbin/bioctl';
   my $SUDO     = '/usr/bin/sudo';
   
 use POSIX;  use POSIX;
 my $PREFIX;  my $PREFIX;
Line 42 
Line 44 
 use utils qw($TIMEOUT %ERRORS &support);  use utils qw($TIMEOUT %ERRORS &support);
   
 $SIG{'ALRM'} = sub {  $SIG{'ALRM'} = sub {
     print "ERROR: $PROGNAME timeout\n";      say "ERROR: $PROGNAME timeout";
     exit $ERRORS{'UNKNOWN'};      exit $ERRORS{'UNKNOWN'};
 };  };
 alarm($TIMEOUT);  alarm($TIMEOUT);
Line 64 
Line 66 
     Invalid     => 'CRITICAL',      Invalid     => 'CRITICAL',
 );  );
   
 my $state = 'UNKNOWN';    # tells whether the it is warning, critical, or OK  
 my @devices;  my @devices;
 my $opt_h;  my $opt_h;
 my $opt_V;  my $opt_V;
Line 82 
Line 83 
 }  }
   
 if ($opt_V) {  if ($opt_V) {
     print_revision( $PROGNAME, '$Revision$ ' );      print_revision();
     exit $ERRORS{'OK'};      exit $ERRORS{'OK'};
 }  }
   
Line 95 
Line 96 
 my %STATES  = check_status( \%VOLUMES );  my %STATES  = check_status( \%VOLUMES );
   
 my $have_results = 0;  my $have_results = 0;
 $state = 'OK';  my $state        = 'OK';
 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++;
Line 115 
Line 116 
     }      }
 }  }
 if ( $have_results == 0 ) {  if ( $have_results == 0 ) {
     print "No results found\n";      say 'No results found';
 }  }
 exit $ERRORS{$state};  exit $ERRORS{$state};
   
Line 124 
Line 125 
     my %volumes;      my %volumes;
   
     foreach my $d ( @{$devices} ) {      foreach my $d ( @{$devices} ) {
         open my $bioctl, q{-|}, $BIOCTL, $d          open my $bioctl, q{-|}, $SUDO, $BIOCTL, $d
             or die "Couldn't open bioctl: $!\n";              or die "Couldn't open bioctl: $!\n";
         while ( my $line = <$bioctl> ) {      LINE: while ( my $line = <$bioctl> ) {
             my ( $i, $item ) = parse_bioctl_line($line);              my ( $i, $item ) = parse_bioctl_line($line);
             next unless defined $i;              next LINE if !defined $i;
             $volumes{$d}{$i} = $item;              $volumes{$d}{$i} = $item;
         }          }
         ## no critic 'die'          ## no critic 'die'
Line 150 
Line 151 
     return %volumes;      return %volumes;
 }  }
   
 {  
     my $vid;  
 sub parse_bioctl_line {  sub parse_bioctl_line {
     my ($line) = @_;      ($_) = @_;
     chomp $line;      chomp;
   
     # Do these by columns cuZ that is the easiest for now      my @o = map { s/^\s+|\s+$//g; $_ } split;
     my @o = unpack( "A6 A1 A11 A15 A7 A9 A*", $line );  
     return if $o[0] eq 'Volume';      return if $o[0] eq 'Volume';
   
     foreach (@o) {      state $vid = '';
         s/^\s+//xms;      state $controller;
         s/\s+$//xms;  
     }  
   
     my ( $controller, $id, $status, $size, $dev, $details, $name ) = @o;      my $index = "$vid.$o[0]";
     my $index = $id;      if ( $o[0] !~ /^\d+$/ ) {
     if ($controller) {          $controller = shift @o;
         $vid = $id;          $vid        = $o[0];
           $index      = $vid;
     }      }
     else {  
         $index = "$vid.$id";  
     }  
   
     my %item = (      return $index, {
         type       => 'volume',          controller  => $controller,
         controller => $controller,          volume_id   => $vid,
         id         => $id,          id          => shift @o,
         status     => $status,          status      => shift @o,
         size       => $size,          size        => shift @o,
         device     => $dev,          device      => shift @o,
         details    => $details,          name        => shift @o,
         name       => $name,          description => join ' ', @o,
         volume_id  => $vid,      };
     );  
   
     return $index, \%item;  
 }  }
 }  
   
 sub check_status {  sub check_status {
     my ($volumes) = @_;      my ($volumes) = @_;
   
     my %states;      my %states;
     foreach my $device ( sort keys %{$volumes} ) {      foreach my $d ( sort keys %{$volumes} ) {
         foreach my $index ( sort keys %{ $volumes->{$device} } ) {          foreach my $i ( sort { $a <=> $b } keys %{ $volumes->{$d} } ) {
             my $cur_volume = $volumes->{$device}->{$index};              my $volume = $volumes->{$d}->{$i};
             my $cur_state  = $Status_Map{ $cur_volume->{'status'} }              my $state = $Status_Map{ $volume->{'status'} } || 'UNKNOWN';
                 || 'UNKNOWN';  
   
             if ( $cur_volume->{'device'} =~ /^\d+:\d/xms ) {              push @{ $states{$state} },
                 push @{ $states{$cur_state} },                  sprintf(
                     sprintf(                  "%5s %-7s %-11s %s",
                     "%5s %-7s %-11s %s",                  $volume->{'controller'}, $volume->{'device'},
                     $cur_volume->{'volume'}{'controller'},                  $volume->{'status'},     $volume->{'name'}
                     $cur_volume->{'device'},                  );
                     $cur_volume->{'status'},  
                     $cur_volume->{'name'}  
                     );  
             }  
             else {  
                 push @{ $states{$cur_state} },  
                     sprintf( "%5s %-7s %s",  
                     $cur_volume->{'controller'},  
                     $cur_volume->{'device'},  
                     $cur_volume->{'status'} );  
             }  
         }          }
     }      }
     return %states;      return %states;
Line 235 
Line 213 
   
 EOL  EOL
   
     print_revision( $PROGNAME, '$Revision$' );      print_revision();
   
     print $License;      print $License;
   
Line 243 
Line 221 
 }  }
   
 sub print_revision {  sub print_revision {
     my ( $prog, $rev ) = @_;      my $rev = '$Revision$';
     $rev =~ s/^\D+([\d\.]+)\D+$/v$1/xms;      $rev =~ s/^\D+([\d\.]+)\D+$/v$1/xms;
   
     print "$prog $rev\n";      say "$PROGNAME $rev";
   
     return 1;      return 1;
 }  }

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.20

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