version 1.4, 2006/05/02 16:54:42 |
version 1.7, 2006/05/02 21:03:53 |
|
|
#!/usr/bin/perl |
#!/usr/bin/perl |
# $RedRiver: check_hw_sensors,v 1.3 2006/05/02 01:39:23 andrew Exp $ |
# $RedRiver: check_hw_sensors,v 1.6 2006/05/02 19:59:47 andrew Exp $ |
######################################################################## |
######################################################################## |
# check_hw_sensors *** A nagios check for OpenBSD hw.sensors |
# check_hw_sensors *** A nagios check for OpenBSD hw.sensors |
# |
# |
|
|
#print Dumper \%states; |
#print Dumper \%states; |
|
|
$state = 'OK'; |
$state = 'OK'; |
if (NAGIOS_OUTPUT) { |
my $have_results = 0; |
|
foreach my $error (sort { $ERRORS{$a} <=> $ERRORS{$b} } keys %ERRORS) { |
|
if (exists $states{$error}) { |
|
$have_results++; |
|
$state = $error; |
|
} |
|
} |
|
if (NAGIOS_OUTPUT && $have_results) { |
print '<ul>'; |
print '<ul>'; |
} |
} |
foreach my $error (sort { $ERRORS{$b} <=> $ERRORS{$a} } keys %ERRORS) { |
foreach my $error (sort { $ERRORS{$b} <=> $ERRORS{$a} } keys %ERRORS) { |
if (exists $states{$error}) { |
if (exists $states{$error}) { |
if (NAGIOS_OUTPUT) { |
if (NAGIOS_OUTPUT) { |
print "<li>$error (" . scalar(@{ $states{ $error } }) . "):<ul>"; |
print "<li>$error (" . scalar(@{ $states{ $error } }) . ")"; |
foreach (@{ $states{ $error } }) { |
unless ($error eq 'OK') { |
print "<li>$_</li>"; |
print '<ul>'; |
|
foreach (@{ $states{ $error } }) { |
|
print "<li>$_</li>"; |
|
} |
|
print '</ul>'; |
} |
} |
print "</ul></li>" |
print "</li>" |
} else { |
} else { |
print "$error (" . scalar(@{ $states{ $error } }) . "):\n"; |
print "$error (" . scalar(@{ $states{ $error } }) . "):\n"; |
foreach (@{ $states{ $error } }) { |
foreach (@{ $states{ $error } }) { |
|
|
} |
} |
} |
} |
} |
} |
if (NAGIOS_OUTPUT) { |
if ($have_results == 0) { |
|
print "No results found\n"; |
|
} |
|
if (NAGIOS_OUTPUT && $have_results) { |
print '</ul>' . "\n"; |
print '</ul>' . "\n"; |
} |
} |
foreach my $error (sort { $ERRORS{$a} <=> $ERRORS{$b} } keys %ERRORS) { |
|
if (exists $states{$error}) { |
|
$state = $error; |
|
} |
|
} |
|
exit $ERRORS{$state}; |
exit $ERRORS{$state}; |
|
|
|
|
|
|
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; |
} |
} |
|
|
|
|
$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; |
} |
} |