[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.2 and 1.8

version 1.2, 2006/05/02 02:29:33 version 1.8, 2006/05/02 22:23:29
Line 1 
Line 1 
 #!/usr/bin/perl  #!/usr/bin/perl
 # $RedRiver: check_sensors,v 1.1 2006/05/01 18:11:23 andrew Exp $  # $RedRiver: check_hw_sensors,v 1.7 2006/05/02 20:03:53 andrew Exp $
 ########################################################################  ########################################################################
 # check_hw_sensors *** A nagios check for OpenBSD hw.sensors  # check_hw_sensors *** A nagios check for OpenBSD hw.sensors
 #  #
 # 2006.05.01 #*#*# andrew fresh <andrew@mad-techies.org>  # 2006.05.01 #*#*# andrew fresh <andrew@mad-techies.org>
 ########################################################################  ########################################################################
   # TODO:
   #   Really need to fix the documentation issue.
   #
   #   I want the ability to just check the "status" entry that is in some output.  For example the OK here:
   #     hw.sensors.1=esm0, CPU 1, OK, temp, 31.00 degC / 87.80 degF
   ########################################################################
 use strict;  use strict;
 use warnings;  use warnings;
   
 #use Data::Dumper;  #use Data::Dumper;
   
   use constant NAGIOS_OUTPUT => 1;
   
 use POSIX;  use POSIX;
 #use lib "/usr/local/libexec/nagios";  use lib "/usr/local/libexec/nagios";
 use lib $ENV{'HOME'};  #use lib $ENV{'HOME'};
 use utils qw($TIMEOUT %ERRORS &print_revision &support);  use utils qw($TIMEOUT %ERRORS &print_revision &support);
   
 use Getopt::Long;  use Getopt::Long;
Line 20 
Line 28 
   
 my $PROGNAME = "check_hw_sensors";  my $PROGNAME = "check_hw_sensors";
   
 my $SYSCTL = 'sysctl';  my $SYSCTL = '/sbin/sysctl';
 my $GETCAP = 'getcap';  my $GETCAP = '/usr/bin/getcap';
 my $BASE   = 'hw.sensors';  my $BASE   = 'hw.sensors';
   my $DEFAULT_CONFIG = '/etc/sensorsd.conf';
   
 my $CHECK_SENSOR = $BASE;  
 my %CHECKS;  
 my %SENSORS;  
   
 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 $filename;
Line 37 
Line 42 
 my $opt_h ;  my $opt_h ;
 my $opt_V ;  my $opt_V ;
   
   my $CHECK_SENSOR = $BASE;
   my %CHECKS;
   my %SENSORS;
   
 #Option checking  #Option checking
 my $status = GetOptions(  my $status = GetOptions(
         "V"   => \$opt_V,    "version"    => \$opt_V,          "version|V"    => \$opt_V,
         "h"   => \$opt_h,    "help"       => \$opt_h,          "help|h"       => \$opt_h,
         "filename|f:s" => \$filename,          "filename|f:s" => \$filename,
         "sensor|s=s"   => \$sensor,          "sensor|s=s"   => \$sensor,
         "warning|w=s"  => \$warning,          "warning|w=s"  => \$warning,
Line 49 
Line 57 
 );  );
   
 # set the default this way so it only happens if someone typed -f or --filename  # set the default this way so it only happens if someone typed -f or --filename
 $filename = '/etc/sensorsd.conf' if (defined $filename && $filename eq '');  $filename = $DEFAULT_CONFIG if (defined $filename && $filename eq '');
   
 if ($status == 0) {  if ($status == 0) {
         print_help() ;          print_help() ;
Line 84 
Line 92 
         $CHECK_SENSOR = $sensor;          $CHECK_SENSOR = $sensor;
   
         $CHECKS{$sensor} = {          $CHECKS{$sensor} = {
                 'warning'  => $warning,                  'warn' => $warning,
                 'critical' => $critical,                  'crit' => $critical,
         };          };
 } elsif (defined $filename) {  } elsif (defined $filename) {
         %CHECKS = parse_file($filename);          %CHECKS = parse_file($filename);
Line 140 
Line 148 
 #print Dumper \%states;  #print Dumper \%states;
   
 $state = 'OK';  $state = 'OK';
   my $have_results = 0;
 foreach my $error (sort { $ERRORS{$a} <=> $ERRORS{$b} } keys %ERRORS) {  foreach my $error (sort { $ERRORS{$a} <=> $ERRORS{$b} } keys %ERRORS) {
         if (exists $states{$error}) {          if (exists $states{$error}) {
                   $have_results++;
                 $state = $error;                  $state = $error;
                 print "$error (" . scalar(@{ $states{ $error } }) . "):\n";          }
                 foreach (@{ $states{ $error } }) {  }
                         print "   $_\n";  foreach my $error (sort { $ERRORS{$b} <=> $ERRORS{$a} } keys %ERRORS) {
           if (exists $states{$error}) {
                   if (NAGIOS_OUTPUT) {
                           print "$error (" . scalar(@{ $states{ $error } }) . ")";
                           unless ($error eq 'OK') {
                                   print '<br />';
                                   print map { " - $_<br />" } @{ $states{ $error } };
                           }
                   } else {
                           print "$error (" . scalar(@{ $states{ $error } }) . "):\n";
                           foreach (@{ $states{ $error } }) {
                                   print "   $_\n";
                           }
                 }                  }
         }          }
 }  }
   if ($have_results == 0) {
           print "No results found\n";
   }
 exit $ERRORS{$state};  exit $ERRORS{$state};
   
   
Line 175 
Line 200 
         my $type  = shift;          my $type  = shift;
         my $check = shift;          my $check = shift;
   
         $check->{'warn'} = $check->{'warning'}  if (!defined $check->{'warn'});  
         $check->{'crit'} = $check->{'critical'} if (!defined $check->{'crit'});  
   
         if (defined $check->{'warn'} && $check->{'warn'} =~ /:/) {          if (defined $check->{'warn'} && $check->{'warn'} =~ /:/) {
                 if (my ($low, $high) = split /:/, $check->{'warn'}) {                  if (my ($low, $high) = split /:/, $check->{'warn'}) {
                         $check->{'warn.low'}  = $low;                          $check->{'warn.low'}  = $low;
Line 276 
Line 298 
                                 foreach my $c (@{ $check->{$code} }) {                                  foreach my $c (@{ $check->{$code} }) {
                                         $c =~ s/[^\d\.]//g;                                          $c =~ s/[^\d\.]//g;
                                         unless (length $c) {                                          unless (length $c) {
                                                 warn "INVALID CHECK (" . $check->{$code} .                                                  warn "INVALID CHECK (" . $c .
                                                       ") for '$sensor->{'id'}:$code'";                                                        ") for '$sensor->{'id'}:$code'";
                                                 next;                                                  next;
                                         }                                          }
Line 354 
Line 376 
   
                                         $c =~ s/[^\d\.]//g;                                          $c =~ s/[^\d\.]//g;
                                         unless (length $c) {                                          unless (length $c) {
                                                 warn "INVALID CHECK (" . $check->{$code} .                                                  warn "INVALID CHECK (" . $c .
                                                          ") for '$sensor->{'id'}':$code";                                                           ") for '$sensor->{'id'}':$code";
                                                 next;                                                  next;
                                         }                                          }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.8

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