[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.34 and 1.41

version 1.34, 2009/11/10 23:12:49 version 1.41, 2009/11/12 18:53:52
Line 1 
Line 1 
 #!/usr/bin/perl -T  #!/usr/bin/perl -T
 # $RedRiver: check_hw_sensors,v 1.33 2009/11/10 23:11:18 andrew Exp $  # $RedRiver: check_hw_sensors,v 1.40 2009/11/11 18:14:40 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 27 
Line 27 
 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 EOL  EOL
   
   my $PROGNAME       = 'check_hw_sensors';
   my $SYSCTL         = '/sbin/sysctl';
   my $GETCAP         = '/usr/bin/getcap';
   my $BASE           = 'hw.sensors';
   my $DEFAULT_CONFIG = '/etc/sensorsd.conf';
   
 use POSIX;  use POSIX;
 use Config;  use Config;
 use lib '/usr/local/libexec/nagios';  my $PREFIX;
   
   BEGIN {
       ## no critic 'warnings'
       no warnings 'uninitialized';
       $PREFIX = "${PREFIX}" || '/usr/local';    # Magic for OpenBSD ports tree
   }
   use lib $PREFIX . '/libexec/nagios';
 use utils qw($TIMEOUT %ERRORS &support);  use utils qw($TIMEOUT %ERRORS &support);
   
   $SIG{'ALRM'} = sub {
       print("ERROR: $PROGNAME timeout\n");
       exit $ERRORS{'UNKNOWN'};
   };
   alarm($TIMEOUT);
   
 use Getopt::Long;  use Getopt::Long;
 Getopt::Long::Configure('bundling');  Getopt::Long::Configure('bundling');
   
 my $PROGNAME = 'check_hw_sensors';  my $OSVer = $Config{'osvers'} || 0;
   
 my $SYSCTL         = '/sbin/sysctl';  
 my $GETCAP         = '/usr/bin/getcap';  
 my $BASE           = 'hw.sensors';  
 my $DEFAULT_CONFIG = '/etc/sensorsd.conf';  
 my $OSVer          = $Config{'osvers'} || 0;  
   
 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 $opt_V;  my $opt_V;
 my $opt_h;  my $opt_h;
Line 130 
Line 143 
     }      }
     $CHECK_SENSOR = $SENSOR;      $CHECK_SENSOR = $SENSOR;
   
     $CHECKS{$SENSOR}{'warn'} = $WARNING;      $CHECKS{$SENSOR}{'warn'} = $WARNING  if $WARNING;
     $CHECKS{$SENSOR}{'crit'} = $CRITICAL;      $CHECKS{$SENSOR}{'crit'} = $CRITICAL if $CRITICAL;
   
 }  }
 elsif ( defined $FILENAME ) {  elsif ( defined $FILENAME ) {
     %CHECKS = read_file($FILENAME);      %CHECKS = read_file($FILENAME);
Line 144 
Line 156 
   
 my $have_results = 0;  my $have_results = 0;
 $state = 'OK';  $state = 'OK';
 foreach my $error ( sort { $ERRORS{$b} <=> $ERRORS{$a} } keys %ERRORS ) {  foreach
       my $error ( reverse sort { $ERRORS{$a} <=> $ERRORS{$b} } 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} } ) . ')';
             if ( $error ne 'OK' ) {              if ( $error ne 'OK' ) {
                 s/\s+/ /gxms;  
                 print '<br>';                  print '<br>';
                 print map {" - $_<br>"} @{ $STATES{$error} };                  print map {" - $_<br>"} @{ $STATES{$error} };
             }              }
         }          }
         else {          else {
             print "$error (" . scalar( @{ $STATES{$error} } ) . "):\n";              print $error . ' (' . scalar( @{ $STATES{$error} } ) . "):\n";
             foreach ( @{ $STATES{$error} } ) {              foreach ( @{ $STATES{$error} } ) {
                 print "   $_\n";                  print "   $_\n";
             }              }
Line 324 
Line 337 
             $r = check_sensor( $sensor, $C->{ $sensor->{id} } );              $r = check_sensor( $sensor, $C->{ $sensor->{id} } );
             $data = $sensor->{id} . '=' . $sensor->{output};              $data = $sensor->{id} . '=' . $sensor->{output};
         }          }
         elsif ( !$O->{ignore_status} && $sensor->{status} ) {          elsif ( $sensor->{status} && !$O->{IGNORE_STATUS} ) {
             $r = check_sensor( $sensor, { STATUS => 1 } );              $r = check_sensor( $sensor, { STATUS => 1 } );
             $data = $sensor->{id} . '=' . $sensor->{output};              $data = $sensor->{id} . '=' . $sensor->{output};
         }          }
Line 398 
Line 411 
     }      }
   
     foreach my $code ( 'warn', 'crit' ) {      foreach my $code ( 'warn', 'crit' ) {
         if (   defined $check->{ $code . ".low" }          if (   defined $check->{ $code . '.low' }
             || defined $check->{ $code . ".high" } )              || defined $check->{ $code . '.high' } )
         {          {
             if ((   defined $check->{ $code . ".low" }              if ((   defined $check->{ $code . '.low' }
                     && $check->{ $code . ".low" } >= $data                      && $check->{ $code . '.low' } >= $data
                 )                  )
                 || ( defined $check->{ $code . ".high" }                  || ( defined $check->{ $code . '.high' }
                     && $check->{ $code . ".high" } <= $data )                      && $check->{ $code . '.high' } <= $data )
                 )                  )
             {              {
                 $result = $errors{$code};                  $result = $errors{$code};
Line 418 
Line 431 
                 my $c = $_;                  my $c = $_;
                 $c =~ s/[^\d\.]//gxms;                  $c =~ s/[^\d\.]//gxms;
                 if ( !length $c ) {                  if ( !length $c ) {
                     warn "INVALID CHECK (" . $_ . ") for '$code'\n";                      warn "INVALID CHECK ($_) for '$code'\n";
                     next;                      next;
                 }                  }
   
Line 489 
Line 502 
   
 FILE is in the same format as sensorsd.conf(5) plus some additional  FILE is in the same format as sensorsd.conf(5) plus some additional
 entries.  These additional entries in the file are ignored by  entries.  These additional entries in the file are ignored by
 sensorsd(8) this means you can use the same config file for $PROGNAME  sensorsd(8).  This means you can use the same config file for $PROGNAME
 as well as sensorsd(8).  as well as sensorsd(8).
   
 $PROGNAME understands the following entries:  $PROGNAME understands the following entries:

Legend:
Removed from v.1.34  
changed lines
  Added in v.1.41

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