[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.31

version 1.26, 2009/11/09 21:25:07 version 1.31, 2009/11/10 18:24:56
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.30 2009/11/09 23:13:04 andrew Exp $
 ########################################################################  ########################################################################
 # check_hw_sensors *** A nagios check for OpenBSD sysctl hw.sensors  # check_hw_sensors *** A nagios check for OpenBSD sysctl hw.sensors
 #  #
 # 2006.05.01 #*#*# andrew fresh <andrew@mad-techies.org>  # 2006.05.01 #*#*# andrew fresh <andrew@afresh1.com>
 ########################################################################  ########################################################################
 use strict;  use strict;
 use warnings;  use warnings;
Line 45 
Line 45 
   
 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 $filename;  my $opt_V;
   my $opt_h;
 my $ignore_status;  my $ignore_status;
   my $filename;
 my $sensor;  my $sensor;
 my $warning;  my $warning;
 my $critical;  my $critical;
 my $opt_h;  
 my $opt_V;  
   
 my $CHECK_SENSOR = $BASE;  my $CHECK_SENSOR = $BASE;
 my %CHECKS;  my %CHECKS;
Line 60 
Line 60 
 #Option checking  #Option checking
 my $status = GetOptions(  my $status = GetOptions(
     "version|V"       => \$opt_V,      "version|V"       => \$opt_V,
     "filename|f:s"    => \$filename,      "help|h"          => \$opt_h,
     "ignore-status|i" => \$ignore_status,      "ignore-status|i" => \$ignore_status,
       "filename|f:s"    => \$filename,
     "sensor|s=s"      => \$sensor,      "sensor|s=s"      => \$sensor,
     "warning|w=s"     => \$warning,      "warning|w=s"     => \$warning,
     "critical|c=s"    => \$critical,      "critical|c=s"    => \$critical,
Line 121 
Line 122 
     exit $ERRORS{'OK'};      exit $ERRORS{'OK'};
 }  }
   
 if (  if ($opt_h) {
     $opt_h  
     || ( ( !defined $filename ) && ( !defined $sensor ) )  
     #|| ( defined $sensor && !( $warning || $critical ) )  
     )  
 {  
     print_help();      print_help();
     exit $ERRORS{'OK'};      exit $ERRORS{'OK'};
 }  }
Line 213 
Line 209 
         $r = check_sensor( $SENSORS{$s}, $CHECKS{$s} );          $r = check_sensor( $SENSORS{$s}, $CHECKS{$s} );
         $data = $s . '=' . $SENSORS{$s}{'output'};          $data = $s . '=' . $SENSORS{$s}{'output'};
     }      }
     elsif ( not $ignore_status ) {      elsif ( !$ignore_status ) {
         $r    = check_sensor( $SENSORS{$s} );          $r    = check_sensor( $SENSORS{$s} );
         $data = $s . '=' . $SENSORS{$s}{'output'};          $data = $s . '=' . $SENSORS{$s}{'output'};
     }      }
Line 325 
Line 321 
     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 350 
         {          {
             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 363 
                     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 376 
                 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 389 
             }              }
             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 420 
                     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 443 
   
                     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 465 
             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 491 
                 }                  }
                 $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 509 
   
         }          }
         else {          else {
             print STDERR 'Unknown Sensor Type: ',              warn 'Unknown Sensor Type: ',
                 $sensor->{'id'},                  $sensor->{'id'},
                 '=',                  '=',
                 $sensor->{'type'},                  $sensor->{'type'},
Line 529 
Line 525 
 sub print_help {  sub print_help {
     print <<"EOL";      print <<"EOL";
 $PROGNAME - monitors sysctl hw.sensors on OpenBSD  $PROGNAME - monitors sysctl hw.sensors on OpenBSD
     $PROGNAME [-i] (-f [<FILENAME>]|(-s <hw.sensors id> [-w limit] [-c limit]))      $PROGNAME [-i] [-f [<FILENAME>]|(-s <hw.sensors id> [-w limit] [-c limit])]
   
 Usage:  Usage:
     -i, --ignore-status      -i, --ignore-status
Line 538 
Line 534 
         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 590 
     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.31

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