=================================================================== RCS file: /cvs/nagios/check_hw_sensors/check_hw_sensors,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- nagios/check_hw_sensors/check_hw_sensors 2006/05/02 02:39:23 1.3 +++ nagios/check_hw_sensors/check_hw_sensors 2006/05/02 16:54:42 1.4 @@ -1,18 +1,26 @@ #!/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 # # 2006.05.01 #*#*# andrew fresh ######################################################################## +# 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 warnings; #use Data::Dumper; +use constant NAGIOS_OUTPUT => 1; + use POSIX; -#use lib "/usr/local/libexec/nagios"; -use lib $ENV{'HOME'}; +use lib "/usr/local/libexec/nagios"; +#use lib $ENV{'HOME'}; use utils qw($TIMEOUT %ERRORS &print_revision &support); use Getopt::Long; @@ -20,14 +28,11 @@ my $PROGNAME = "check_hw_sensors"; -my $SYSCTL = 'sysctl'; -my $GETCAP = 'getcap'; +my $SYSCTL = '/sbin/sysctl'; +my $GETCAP = '/usr/bin/getcap'; 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 %states; # This stores the count of states; my $filename; @@ -37,6 +42,9 @@ my $opt_h ; my $opt_V ; +my $CHECK_SENSOR = $BASE; +my %CHECKS; +my %SENSORS; #Option checking my $status = GetOptions( @@ -49,7 +57,7 @@ ); # 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) { print_help() ; @@ -57,7 +65,7 @@ } if ($opt_V) { - print_revision($PROGNAME,'$Revision: 1.3 $ '); + print_revision($PROGNAME,'$Revision: 1.4 $ '); exit $ERRORS{'OK'}; } @@ -84,8 +92,8 @@ $CHECK_SENSOR = $sensor; $CHECKS{$sensor} = { - 'warning' => $warning, - 'critical' => $critical, + 'warn' => $warning, + 'crit' => $critical, }; } elsif (defined $filename) { %CHECKS = parse_file($filename); @@ -140,13 +148,31 @@ #print Dumper \%states; $state = 'OK'; +if (NAGIOS_OUTPUT) { + print '' . "\n"; +} foreach my $error (sort { $ERRORS{$a} <=> $ERRORS{$b} } keys %ERRORS) { if (exists $states{$error}) { $state = $error; - print "$error (" . scalar(@{ $states{ $error } }) . "):\n"; - foreach (@{ $states{ $error } }) { - print " $_\n"; - } } } exit $ERRORS{$state}; @@ -175,9 +201,6 @@ my $type = 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 (my ($low, $high) = split /:/, $check->{'warn'}) { $check->{'warn.low'} = $low; @@ -422,6 +445,6 @@ EOL - print_revision($PROGNAME, '$Revision: 1.3 $'); + print_revision($PROGNAME, '$Revision: 1.4 $'); }