=================================================================== RCS file: /cvs/nagios/check_hw_sensors/check_hw_sensors,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- nagios/check_hw_sensors/check_hw_sensors 2006/10/26 00:30:23 1.17 +++ nagios/check_hw_sensors/check_hw_sensors 2006/12/02 02:15:17 1.18 @@ -1,5 +1,5 @@ #!/usr/bin/perl -T -# $RedRiver: check_hw_sensors,v 1.16 2006/10/25 18:36:46 andrew Exp $ +# $RedRiver: check_hw_sensors,v 1.17 2006/10/25 23:30:23 andrew Exp $ ######################################################################## # check_hw_sensors *** A nagios check for OpenBSD hw.sensors # @@ -52,17 +52,66 @@ "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 => '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.17 $ '); + print_revision($PROGNAME,'$Revision: 1.18 $ '); exit $ERRORS{'OK'}; } @@ -100,12 +149,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 +381,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 +461,7 @@ $sensor->{'type'} eq 'drive' || $sensor->{'type'} eq 'indicator' ) { + $sensor->{'type'} =~ s/^drive\s+//; if (@{ $check->{$code} }) { my $matched = 0; foreach (@{ $check->{$code} }) { @@ -477,6 +542,6 @@ EOL - print_revision($PROGNAME, '$Revision: 1.17 $'); + print_revision($PROGNAME, '$Revision: 1.18 $'); }