===================================================================
RCS file: /cvs/nagios/check_hw_sensors/check_hw_sensors,v
retrieving revision 1.4
retrieving revision 1.9
diff -u -r1.4 -r1.9
--- nagios/check_hw_sensors/check_hw_sensors 2006/05/02 16:54:42 1.4
+++ nagios/check_hw_sensors/check_hw_sensors 2006/05/03 03:26:47 1.9
@@ -1,5 +1,5 @@
#!/usr/bin/perl
-# $RedRiver: check_hw_sensors,v 1.3 2006/05/02 01:39:23 andrew Exp $
+# $RedRiver: check_hw_sensors,v 1.8 2006/05/02 21:23:29 andrew Exp $
########################################################################
# check_hw_sensors *** A nagios check for OpenBSD hw.sensors
#
@@ -65,7 +65,7 @@
}
if ($opt_V) {
- print_revision($PROGNAME,'$Revision: 1.4 $ ');
+ print_revision($PROGNAME,'$Revision: 1.9 $ ');
exit $ERRORS{'OK'};
}
@@ -148,17 +148,21 @@
#print Dumper \%states;
$state = 'OK';
-if (NAGIOS_OUTPUT) {
- print '
';
+my $have_results = 0;
+foreach my $error (sort { $ERRORS{$a} <=> $ERRORS{$b} } keys %ERRORS) {
+ if (exists $states{$error}) {
+ $have_results++;
+ $state = $error;
+ }
}
foreach my $error (sort { $ERRORS{$b} <=> $ERRORS{$a} } keys %ERRORS) {
if (exists $states{$error}) {
if (NAGIOS_OUTPUT) {
- print "- $error (" . scalar(@{ $states{ $error } }) . "):
";
- foreach (@{ $states{ $error } }) {
- print "- $_
";
+ print "$error (" . scalar(@{ $states{ $error } }) . ")";
+ unless ($error eq 'OK') {
+ print '
';
+ print map { " - $_
" } @{ $states{ $error } };
}
- print "
"
} else {
print "$error (" . scalar(@{ $states{ $error } }) . "):\n";
foreach (@{ $states{ $error } }) {
@@ -167,14 +171,9 @@
}
}
}
-if (NAGIOS_OUTPUT) {
- print '
' . "\n";
+if ($have_results == 0) {
+ print "No results found\n";
}
-foreach my $error (sort { $ERRORS{$a} <=> $ERRORS{$b} } keys %ERRORS) {
- if (exists $states{$error}) {
- $state = $error;
- }
-}
exit $ERRORS{$state};
@@ -294,12 +293,12 @@
$result = $errors{$code}
if ($c <= $data);
}
- } elsif (defined $check->{$code}) {
+ } elsif (@{ $check->{$code} }) {
my $matched = 0;
foreach my $c (@{ $check->{$code} }) {
$c =~ s/[^\d\.]//g;
unless (length $c) {
- warn "INVALID CHECK (" . $check->{$code} .
+ warn "INVALID CHECK (" . $c .
") for '$sensor->{'id'}:$code'";
next;
}
@@ -362,7 +361,7 @@
$result = $errors{$code}
if ($c <= $data);
}
- } elsif (defined $check->{$code}) {
+ } elsif (@{ $check->{$code} }) {
my $matched = 0;
foreach my $c (@{ $check->{$code} }) {
@@ -377,7 +376,7 @@
$c =~ s/[^\d\.]//g;
unless (length $c) {
- warn "INVALID CHECK (" . $check->{$code} .
+ warn "INVALID CHECK (" . $c .
") for '$sensor->{'id'}':$code";
next;
}
@@ -394,7 +393,7 @@
$sensor->{'type'} eq 'drive' ||
$sensor->{'type'} eq 'indicator'
) {
- if (defined $check->{$code}) {
+ if (@{ $check->{$code} }) {
my $matched = 0;
foreach (@{ $check->{$code} }) {
if ($_ eq $sensor->{'data'}) {
@@ -445,6 +444,6 @@
EOL
- print_revision($PROGNAME, '$Revision: 1.4 $');
+ print_revision($PROGNAME, '$Revision: 1.9 $');
}