=================================================================== RCS file: /cvs/nagios/check_hw_sensors/check_hw_sensors,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- nagios/check_hw_sensors/check_hw_sensors 2009/11/09 21:25:07 1.26 +++ nagios/check_hw_sensors/check_hw_sensors 2009/11/09 22:51:44 1.27 @@ -1,5 +1,5 @@ #!/usr/bin/perl -T -# $RedRiver: check_hw_sensors,v 1.25 2008/03/10 16:21:53 andrew Exp $ +# $RedRiver: check_hw_sensors,v 1.26 2009/11/09 21:25:07 andrew Exp $ ######################################################################## # check_hw_sensors *** A nagios check for OpenBSD sysctl hw.sensors # @@ -60,6 +60,7 @@ #Option checking my $status = GetOptions( "version|V" => \$opt_V, + "help|h" => \$opt_h, "filename|f:s" => \$filename, "ignore-status|i" => \$ignore_status, "sensor|s=s" => \$sensor, @@ -117,13 +118,13 @@ } if ($opt_V) { - print_revision( $PROGNAME, '$Revision: 1.26 $ ' ); + print_revision( $PROGNAME, '$Revision: 1.27 $ ' ); exit $ERRORS{'OK'}; } -if ( - $opt_h +if ($opt_h || ( ( !defined $filename ) && ( !defined $sensor ) ) + #|| ( defined $sensor && !( $warning || $critical ) ) ) { @@ -325,20 +326,18 @@ return $result unless ref $sensor eq 'HASH'; $check = parse_check($check) if $check; - if (! $check) { + if ( !$check ) { + # It looks like doing this should be safe, from # src/sbin/sysctl/sysctl.c return $sensor->{'status'} if $sensor->{'status'}; return; } - elsif ($check eq 'IGNORE') { + elsif ( $check eq 'IGNORE' ) { return; } - use YAML; - print Dump $check; - $result = 'OK'; foreach my $code ( 'warn', 'crit' ) { if ( $sensor->{'type'} eq 'fan' @@ -356,8 +355,9 @@ { my $data = $sensor->{'data'}; $data =~ s/[^\d\.]//g; - if (! length $data ) { - warn "INVALID DATA ($sensor->{'data'}) for '$sensor->{'id'}'"; + if ( !length $data ) { + warn + "INVALID DATA ($sensor->{'data'}) for '$sensor->{'id'}'\n"; next; } @@ -368,10 +368,10 @@ my $c = $check->{ $code . ".low" }; $c =~ s/[^\d\.]//g; - if (! length $c ) { + if ( !length $c ) { warn "INVALID CHECK (" . $check->{ $code . ".low" } - . ") for '$sensor->{'id'}:$code.low'"; + . ") for '$sensor->{'id'}:$code.low'\n"; next; } @@ -381,10 +381,10 @@ if ( defined $check->{ $code . ".high" } ) { my $c = $check->{ $code . ".high" }; $c =~ s/[^\d\.]//g; - if (! length $c ) { + if ( !length $c ) { warn "INVALID CHECK (" . $check->{ $code . ".high" } - . ") for '$sensor->{'id'}:$code.high'"; + . ") for '$sensor->{'id'}:$code.high'\n"; next; } @@ -394,11 +394,12 @@ } elsif ( @{ $check->{$code} } ) { my $matched = 0; - foreach my $c ( @{ $check->{$code} } ) { + foreach ( @{ $check->{$code} } ) { + my $c = $_; $c =~ s/[^\d\.]//g; - if (! length $c ) { - warn "INVALID CHECK (" . $c - . ") for '$sensor->{'id'}:$code'"; + if ( !length $c ) { + warn "INVALID CHECK (" . $_ + . ") for '$sensor->{'id'}:$code'\n"; next; } @@ -424,18 +425,18 @@ my $data = $degC; $data = $degF if ( $c =~ /F/i ); - if (! length $data ) { + if ( !length $data ) { warn "INVALID DATA (" . $sensor->{'data'} - . ") for '$sensor->{'id'}'"; + . ") for '$sensor->{'id'}'\n"; next; } $c =~ s/[^\d\.]//g; - if (! length $c ) { + if ( !length $c ) { warn "INVALID CHECK (" . $check->{ $code . ".low" } - . ") for '$sensor->{'id'}':$code.low"; + . ") for '$sensor->{'id'}':$code.low\n"; next; } @@ -447,18 +448,18 @@ my $data = $degC; $data = $degF if ( $c =~ /F/i ); - if (! length $data ) { + if ( !length $data ) { warn "INVALID DATA (" . $sensor->{'data'} - . ") for '$sensor->{'id'}'"; + . ") for '$sensor->{'id'}'\n"; next; } $c =~ s/[^\d\.]//g; - if (! length $c ) { + if ( !length $c ) { warn "INVALID CHECK (" . $check->{ $code . ".high" } - . ") for '$sensor->{'id'}:$code.high'"; + . ") for '$sensor->{'id'}:$code.high'\n"; next; } @@ -469,21 +470,22 @@ elsif ( @{ $check->{$code} } ) { my $matched = 0; - foreach my $c ( @{ $check->{$code} } ) { + foreach ( @{ $check->{$code} } ) { + my $c = $_; my $data = $degC; $data = $degF if ( $c =~ /F/i ); - if (! length $data ) { + if ( !length $data ) { warn "INVALID DATA (" . $sensor->{'data'} - . ") for '$sensor->{'id'}'"; + . ") for '$sensor->{'id'}'\n"; next; } $c =~ s/[^\d\.]//g; - if (! length $c ) { - warn "INVALID CHECK (" . $c - . ") for '$sensor->{'id'}':$code"; + if ( !length $c ) { + warn "INVALID CHECK (" . $_ + . ") for '$sensor->{'id'}':$code\n"; next; } @@ -494,7 +496,6 @@ } $result = $errors{$code} unless $matched; } - } elsif ($sensor->{'type'} eq 'drive' || $sensor->{'type'} eq 'indicator' ) @@ -513,7 +514,7 @@ } else { - print STDERR 'Unknown Sensor Type: ', + warn 'Unknown Sensor Type: ', $sensor->{'id'}, '=', $sensor->{'type'}, @@ -538,6 +539,7 @@ FILE to load checks from (defaults to /etc/sensorsd.conf) -s, --sensor=ID ID of a single sensor. "-s kate0.temp0" means hw.sensors.kate0.temp0 + Overrides --filename. -w, --warning=RANGE or single ENTRY Exit with WARNING status if outside of RANGE or if != ENTRY -c, --critical=RANGE or single ENTRY @@ -588,18 +590,15 @@ EOL - print_revision( $PROGNAME, '$Revision: 1.26 $' ); + print_revision( $PROGNAME, '$Revision: 1.27 $' ); print $License; } - sub print_revision { - my ($prog, $rev) = @_; + my ( $prog, $rev ) = @_; $rev =~ s/^\D+([\d\.]+)\D+$/v$1/xms; print "$prog $rev\n"; } - -