===================================================================
RCS file: /cvs/nagios/check_hw_sensors/check_hw_sensors,v
retrieving revision 1.35
retrieving revision 1.41
diff -u -r1.35 -r1.41
--- nagios/check_hw_sensors/check_hw_sensors 2009/11/10 23:15:15 1.35
+++ nagios/check_hw_sensors/check_hw_sensors 2009/11/12 18:53:52 1.41
@@ -1,5 +1,5 @@
#!/usr/bin/perl -T
-# $RedRiver: check_hw_sensors,v 1.34 2009/11/10 23:12:49 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
#
@@ -27,22 +27,35 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
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 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);
+$SIG{'ALRM'} = sub {
+ print("ERROR: $PROGNAME timeout\n");
+ exit $ERRORS{'UNKNOWN'};
+};
+alarm($TIMEOUT);
+
use Getopt::Long;
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 $opt_V;
my $opt_h;
@@ -69,7 +82,7 @@
}
if ($opt_V) {
- print_revision( $PROGNAME, '$Revision: 1.35 $ ' );
+ print_revision( $PROGNAME, '$Revision: 1.41 $ ' );
exit $ERRORS{'OK'};
}
@@ -130,9 +143,8 @@
}
$CHECK_SENSOR = $SENSOR;
- $CHECKS{$SENSOR}{'warn'} = $WARNING;
- $CHECKS{$SENSOR}{'crit'} = $CRITICAL;
-
+ $CHECKS{$SENSOR}{'warn'} = $WARNING if $WARNING;
+ $CHECKS{$SENSOR}{'crit'} = $CRITICAL if $CRITICAL;
}
elsif ( defined $FILENAME ) {
%CHECKS = read_file($FILENAME);
@@ -144,21 +156,22 @@
my $have_results = 0;
$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} ) {
$have_results++;
$state = $error if $ERRORS{$state} < $ERRORS{$error};
if ($NAGIOS_OUTPUT) {
- print "$error (" . scalar( @{ $STATES{$error} } ) . ")";
+ print $error . ' (' . scalar( @{ $STATES{$error} } ) . ')';
if ( $error ne 'OK' ) {
- s/\s+/ /gxms;
print '
';
print map {" - $_
"} @{ $STATES{$error} };
}
}
else {
- print "$error (" . scalar( @{ $STATES{$error} } ) . "):\n";
+ print $error . ' (' . scalar( @{ $STATES{$error} } ) . "):\n";
foreach ( @{ $STATES{$error} } ) {
print " $_\n";
}
@@ -324,7 +337,7 @@
$r = check_sensor( $sensor, $C->{ $sensor->{id} } );
$data = $sensor->{id} . '=' . $sensor->{output};
}
- elsif ( !$O->{ignore_status} && $sensor->{status} ) {
+ elsif ( $sensor->{status} && !$O->{IGNORE_STATUS} ) {
$r = check_sensor( $sensor, { STATUS => 1 } );
$data = $sensor->{id} . '=' . $sensor->{output};
}
@@ -398,14 +411,14 @@
}
foreach my $code ( 'warn', 'crit' ) {
- if ( defined $check->{ $code . ".low" }
- || defined $check->{ $code . ".high" } )
+ if ( defined $check->{ $code . '.low' }
+ || defined $check->{ $code . '.high' } )
{
- if (( defined $check->{ $code . ".low" }
- && $check->{ $code . ".low" } >= $data
+ if (( defined $check->{ $code . '.low' }
+ && $check->{ $code . '.low' } >= $data
)
- || ( defined $check->{ $code . ".high" }
- && $check->{ $code . ".high" } <= $data )
+ || ( defined $check->{ $code . '.high' }
+ && $check->{ $code . '.high' } <= $data )
)
{
$result = $errors{$code};
@@ -418,7 +431,7 @@
my $c = $_;
$c =~ s/[^\d\.]//gxms;
if ( !length $c ) {
- warn "INVALID CHECK (" . $_ . ") for '$code'\n";
+ warn "INVALID CHECK ($_) for '$code'\n";
next;
}
@@ -529,7 +542,7 @@
EOL
- print_revision( $PROGNAME, '$Revision: 1.35 $' );
+ print_revision( $PROGNAME, '$Revision: 1.41 $' );
print $LICENSE;