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

Diff for /nagios/check_hw_sensors/check_hw_sensors between version 1.26 and 1.27

version 1.26, 2009/11/09 21:25:07 version 1.27, 2009/11/09 22:51:44
Line 1 
Line 1 
 #!/usr/bin/perl -T  #!/usr/bin/perl -T
 # $RedRiver: check_hw_sensors,v 1.25 2008/03/10 16:21:53 andrew Exp $  # $RedRiver: check_hw_sensors,v 1.26 2009/11/09 21:25:07 andrew Exp $
 ########################################################################  ########################################################################
 # check_hw_sensors *** A nagios check for OpenBSD sysctl hw.sensors  # check_hw_sensors *** A nagios check for OpenBSD sysctl hw.sensors
 #  #
Line 60 
Line 60 
 #Option checking  #Option checking
 my $status = GetOptions(  my $status = GetOptions(
     "version|V"       => \$opt_V,      "version|V"       => \$opt_V,
       "help|h"          => \$opt_h,
     "filename|f:s"    => \$filename,      "filename|f:s"    => \$filename,
     "ignore-status|i" => \$ignore_status,      "ignore-status|i" => \$ignore_status,
     "sensor|s=s"      => \$sensor,      "sensor|s=s"      => \$sensor,
Line 121 
Line 122 
     exit $ERRORS{'OK'};      exit $ERRORS{'OK'};
 }  }
   
 if (  if ($opt_h
     $opt_h  
     || ( ( !defined $filename ) && ( !defined $sensor ) )      || ( ( !defined $filename ) && ( !defined $sensor ) )
   
     #|| ( defined $sensor && !( $warning || $critical ) )      #|| ( defined $sensor && !( $warning || $critical ) )
     )      )
 {  {
Line 325 
Line 326 
     return $result unless ref $sensor eq 'HASH';      return $result unless ref $sensor eq 'HASH';
     $check = parse_check($check) if $check;      $check = parse_check($check) if $check;
   
     if (! $check) {      if ( !$check ) {
   
         # It looks like doing this should be safe, from          # It looks like doing this should be safe, from
         # src/sbin/sysctl/sysctl.c          # src/sbin/sysctl/sysctl.c
         return $sensor->{'status'} if $sensor->{'status'};          return $sensor->{'status'} if $sensor->{'status'};
   
         return;          return;
     }      }
     elsif ($check eq 'IGNORE') {      elsif ( $check eq 'IGNORE' ) {
         return;          return;
     }      }
   
     use YAML;  
     print Dump $check;  
   
     $result = 'OK';      $result = 'OK';
     foreach my $code ( 'warn', 'crit' ) {      foreach my $code ( 'warn', 'crit' ) {
         if (   $sensor->{'type'} eq 'fan'          if (   $sensor->{'type'} eq 'fan'
Line 356 
Line 355 
         {          {
             my $data = $sensor->{'data'};              my $data = $sensor->{'data'};
             $data =~ s/[^\d\.]//g;              $data =~ s/[^\d\.]//g;
             if (! length $data ) {              if ( !length $data ) {
                 warn "INVALID DATA ($sensor->{'data'}) for '$sensor->{'id'}'";                  warn
                       "INVALID DATA ($sensor->{'data'}) for '$sensor->{'id'}'\n";
                 next;                  next;
             }              }
   
Line 368 
Line 368 
                     my $c = $check->{ $code . ".low" };                      my $c = $check->{ $code . ".low" };
                     $c =~ s/[^\d\.]//g;                      $c =~ s/[^\d\.]//g;
   
                     if (! length $c ) {                      if ( !length $c ) {
                         warn "INVALID CHECK ("                          warn "INVALID CHECK ("
                             . $check->{ $code . ".low" }                              . $check->{ $code . ".low" }
                             . ") for '$sensor->{'id'}:$code.low'";                              . ") for '$sensor->{'id'}:$code.low'\n";
                         next;                          next;
                     }                      }
   
Line 381 
Line 381 
                 if ( defined $check->{ $code . ".high" } ) {                  if ( defined $check->{ $code . ".high" } ) {
                     my $c = $check->{ $code . ".high" };                      my $c = $check->{ $code . ".high" };
                     $c =~ s/[^\d\.]//g;                      $c =~ s/[^\d\.]//g;
                     if (! length $c ) {                      if ( !length $c ) {
                         warn "INVALID CHECK ("                          warn "INVALID CHECK ("
                             . $check->{ $code . ".high" }                              . $check->{ $code . ".high" }
                             . ") for '$sensor->{'id'}:$code.high'";                              . ") for '$sensor->{'id'}:$code.high'\n";
                         next;                          next;
                     }                      }
   
Line 394 
Line 394 
             }              }
             elsif ( @{ $check->{$code} } ) {              elsif ( @{ $check->{$code} } ) {
                 my $matched = 0;                  my $matched = 0;
                 foreach my $c ( @{ $check->{$code} } ) {                  foreach ( @{ $check->{$code} } ) {
                       my $c = $_;
                     $c =~ s/[^\d\.]//g;                      $c =~ s/[^\d\.]//g;
                     if (! length $c ) {                      if ( !length $c ) {
                         warn "INVALID CHECK (" . $c                          warn "INVALID CHECK (" . $_
                             . ") for '$sensor->{'id'}:$code'";                              . ") for '$sensor->{'id'}:$code'\n";
                         next;                          next;
                     }                      }
   
Line 424 
Line 425 
                     my $data = $degC;                      my $data = $degC;
   
                     $data = $degF if ( $c =~ /F/i );                      $data = $degF if ( $c =~ /F/i );
                     if (! length $data ) {                      if ( !length $data ) {
                         warn "INVALID DATA ("                          warn "INVALID DATA ("
                             . $sensor->{'data'}                              . $sensor->{'data'}
                             . ") for '$sensor->{'id'}'";                              . ") for '$sensor->{'id'}'\n";
                         next;                          next;
                     }                      }
   
                     $c =~ s/[^\d\.]//g;                      $c =~ s/[^\d\.]//g;
                     if (! length $c ) {                      if ( !length $c ) {
                         warn "INVALID CHECK ("                          warn "INVALID CHECK ("
                             . $check->{ $code . ".low" }                              . $check->{ $code . ".low" }
                             . ") for '$sensor->{'id'}':$code.low";                              . ") for '$sensor->{'id'}':$code.low\n";
                         next;                          next;
                     }                      }
   
Line 447 
Line 448 
   
                     my $data = $degC;                      my $data = $degC;
                     $data = $degF if ( $c =~ /F/i );                      $data = $degF if ( $c =~ /F/i );
                     if (! length $data ) {                      if ( !length $data ) {
                         warn "INVALID DATA ("                          warn "INVALID DATA ("
                             . $sensor->{'data'}                              . $sensor->{'data'}
                             . ") for '$sensor->{'id'}'";                              . ") for '$sensor->{'id'}'\n";
                         next;                          next;
                     }                      }
   
                     $c =~ s/[^\d\.]//g;                      $c =~ s/[^\d\.]//g;
                     if (! length $c ) {                      if ( !length $c ) {
                         warn "INVALID CHECK ("                          warn "INVALID CHECK ("
                             . $check->{ $code . ".high" }                              . $check->{ $code . ".high" }
                             . ") for '$sensor->{'id'}:$code.high'";                              . ") for '$sensor->{'id'}:$code.high'\n";
                         next;                          next;
                     }                      }
   
Line 469 
Line 470 
             elsif ( @{ $check->{$code} } ) {              elsif ( @{ $check->{$code} } ) {
   
                 my $matched = 0;                  my $matched = 0;
                 foreach my $c ( @{ $check->{$code} } ) {                  foreach ( @{ $check->{$code} } ) {
                       my $c    = $_;
                     my $data = $degC;                      my $data = $degC;
   
                     $data = $degF if ( $c =~ /F/i );                      $data = $degF if ( $c =~ /F/i );
                     if (! length $data ) {                      if ( !length $data ) {
                         warn "INVALID DATA ("                          warn "INVALID DATA ("
                             . $sensor->{'data'}                              . $sensor->{'data'}
                             . ") for '$sensor->{'id'}'";                              . ") for '$sensor->{'id'}'\n";
                         next;                          next;
                     }                      }
   
                     $c =~ s/[^\d\.]//g;                      $c =~ s/[^\d\.]//g;
                     if (! length $c ) {                      if ( !length $c ) {
                         warn "INVALID CHECK (" . $c                          warn "INVALID CHECK (" . $_
                             . ") for '$sensor->{'id'}':$code";                              . ") for '$sensor->{'id'}':$code\n";
                         next;                          next;
                     }                      }
   
Line 494 
Line 496 
                 }                  }
                 $result = $errors{$code} unless $matched;                  $result = $errors{$code} unless $matched;
             }              }
   
         }          }
         elsif ($sensor->{'type'} eq 'drive'          elsif ($sensor->{'type'} eq 'drive'
             || $sensor->{'type'} eq 'indicator' )              || $sensor->{'type'} eq 'indicator' )
Line 513 
Line 514 
   
         }          }
         else {          else {
             print STDERR 'Unknown Sensor Type: ',              warn 'Unknown Sensor Type: ',
                 $sensor->{'id'},                  $sensor->{'id'},
                 '=',                  '=',
                 $sensor->{'type'},                  $sensor->{'type'},
Line 538 
Line 539 
         FILE to load checks from (defaults to /etc/sensorsd.conf)          FILE to load checks from (defaults to /etc/sensorsd.conf)
     -s, --sensor=ID      -s, --sensor=ID
         ID of a single sensor.  "-s kate0.temp0" means hw.sensors.kate0.temp0          ID of a single sensor.  "-s kate0.temp0" means hw.sensors.kate0.temp0
           Overrides --filename.
     -w, --warning=RANGE or single ENTRY      -w, --warning=RANGE or single ENTRY
         Exit with WARNING status if outside of RANGE or if != ENTRY          Exit with WARNING status if outside of RANGE or if != ENTRY
     -c, --critical=RANGE or single ENTRY      -c, --critical=RANGE or single ENTRY
Line 593 
Line 595 
     print $License;      print $License;
 }  }
   
   
 sub print_revision {  sub print_revision {
     my ($prog, $rev) = @_;      my ( $prog, $rev ) = @_;
     $rev =~ s/^\D+([\d\.]+)\D+$/v$1/xms;      $rev =~ s/^\D+([\d\.]+)\D+$/v$1/xms;
   
     print "$prog $rev\n";      print "$prog $rev\n";
 }  }
   
   
   

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.27

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