[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.3 and 1.4

version 1.3, 2006/05/02 02:39:23 version 1.4, 2006/05/02 16:54:42
Line 1 
Line 1 
 #!/usr/bin/perl  #!/usr/bin/perl
 # $RedRiver: check_hw_sensors,v 1.2 2006/05/02 01:29:33 andrew Exp $  # $RedRiver: check_hw_sensors,v 1.3 2006/05/02 01:39:23 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(
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';
   if (NAGIOS_OUTPUT) {
           print '<ul>';
   }
   foreach my $error (sort { $ERRORS{$b} <=> $ERRORS{$a} } keys %ERRORS) {
           if (exists $states{$error}) {
                   if (NAGIOS_OUTPUT) {
                           print "<li>$error (" . scalar(@{ $states{ $error } }) . "):<ul>";
                           foreach (@{ $states{ $error } }) {
                                   print "<li>$_</li>";
                           }
                           print "</ul></li>"
                   } else {
                           print "$error (" . scalar(@{ $states{ $error } }) . "):\n";
                           foreach (@{ $states{ $error } }) {
                                   print "   $_\n";
                           }
                   }
           }
   }
   if (NAGIOS_OUTPUT) {
           print '</ul>' . "\n";
   }
 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}) {
                 $state = $error;                  $state = $error;
                 print "$error (" . scalar(@{ $states{ $error } }) . "):\n";  
                 foreach (@{ $states{ $error } }) {  
                         print "   $_\n";  
                 }  
         }          }
 }  }
 exit $ERRORS{$state};  exit $ERRORS{$state};
Line 174 
Line 200 
 sub parse_check {  sub parse_check {
         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'}) {

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

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