=================================================================== RCS file: /cvs/nagios/check_hw_sensors/check_hw_sensors,v retrieving revision 1.16 retrieving revision 1.19 diff -u -r1.16 -r1.19 --- nagios/check_hw_sensors/check_hw_sensors 2006/10/25 19:36:46 1.16 +++ nagios/check_hw_sensors/check_hw_sensors 2006/12/04 23:33:53 1.19 @@ -1,5 +1,5 @@ #!/usr/bin/perl -T -# $RedRiver: check_hw_sensors,v 1.15 2006/10/25 18:35:59 andrew Exp $ +# $RedRiver: check_hw_sensors,v 1.18 2006/12/02 02:15:17 andrew Exp $ ######################################################################## # check_hw_sensors *** A nagios check for OpenBSD hw.sensors # @@ -17,6 +17,7 @@ use POSIX; use lib "/usr/local/libexec/nagios"; +use lib '.'; use utils qw($TIMEOUT %ERRORS &print_revision &support); use Getopt::Long; @@ -52,17 +53,70 @@ "warning|w=s" => \$warning, "critical|c=s" => \$critical, ); - + # set the default this way so it only happens if someone typed -f or --filename $filename = $DEFAULT_CONFIG if (defined $filename && $filename eq ''); +# Stuff is output in this file by print_sensor() +# http://www.openbsd.org/cgi-bin/cvsweb/src/sbin/sysctl/sysctl.c +my @Type_Map = ( + { + type => 'temp', + regex => qr/\sdegC$/, + }, + { + type => 'fanrpm', + regex => qr/\sRPM$/, + }, + { + type => 'volts_dc', + regex => qr/\sV\sDC$/, + }, + { + type => 'amps', + regex => qr/\sA$/, + }, + { + type => 'watthour', + regex => qr/\sWh$/, + }, + { + type => 'amphour', + regex => qr/\sAh$/, + }, + { + type => 'indicator', + regex => qr/^(On|Off)$/, + }, + { + type => 'integer', + regex => qr/\sraw$/, + }, + { + type => 'percent', + regex => qr/\s\%$/, + }, + { + type => 'lux', + regex => qr/\slx$/, + }, + { + type => 'drive', + regex => qr/^drive\s/, + }, + { + type => 'timedelta', + regex => qr/\ssecs$/, + }, +); + if ($status == 0) { print_help() ; exit $ERRORS{'OK'}; } if ($opt_V) { - print_revision($PROGNAME,'$Revision: 1.16 $ '); + print_revision($PROGNAME,'$Revision: 1.19 $ '); exit $ERRORS{'OK'}; } @@ -100,12 +154,26 @@ my ($id, $output) = split /=/; my @o = split /,\s*/, $output; - my $source = $o[0]; - my $descr = $o[1]; - my $status = $o[2] if @o == 5; - my $type = $o[-2]; - my $data = $o[-1]; + my ($type, $source, $descr, $data, $status); + $source = $o[0]; + $descr = $o[1]; + $type = $o[-2] if @o >= 4; + $data = $o[-1]; + + $status = $o[2] if ($type && @o == 5) || @o == 4; + + unless ($type) { + foreach my $t (@Type_Map) { + if ($data =~ /$t->{'regex'}/) { + $type = $t->{'type'}; + last; + } + } + } + + $type ||= 'unknown'; + $SENSORS{$id} = { id => $id, output => $output, @@ -318,6 +386,7 @@ } elsif ($sensor->{'type'} eq 'temp') { my ($degC, $degF) = split /\//, $sensor->{'data'}; $degC =~ s/[^\d\.]//g; + $degF ||= $degC * 9 / 5 + 32; $degF =~ s/[^\d\.]//g; if ( defined $check->{$code . ".low"} || @@ -397,6 +466,7 @@ $sensor->{'type'} eq 'drive' || $sensor->{'type'} eq 'indicator' ) { + $sensor->{'type'} =~ s/^drive\s+//; if (@{ $check->{$code} }) { my $matched = 0; foreach (@{ $check->{$code} }) { @@ -424,8 +494,7 @@ Usage: -i, --ignore-status - Whether to check the "status" of the sensors that report it. - Normally enabled, pass this + Don't check the status of sensors that report it. -f, --filename=FILE FILE to load checks from (defaults to /etc/sensorsd.conf) -s, --sensor=ID @@ -435,8 +504,6 @@ -c, --critical=RANGE or single ENTRY Exit with CRITICAL status if outside of RANGE or if != ENTRY - -h (--help) usage help - FILE is in the same format as sensorsd.conf(5) plus some additional entries. These additional entries in the file are ignored by sensorsd(8). @@ -480,6 +547,6 @@ EOL - print_revision($PROGNAME, '$Revision: 1.16 $'); + print_revision($PROGNAME, '$Revision: 1.19 $'); }