=================================================================== RCS file: /cvs/nagios/check_hw_sensors/check_hw_sensors,v retrieving revision 1.26 retrieving revision 1.29 diff -u -r1.26 -r1.29 --- 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 23:06:26 1.29 @@ -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.28 2009/11/09 22:58:41 andrew Exp $ ######################################################################## # check_hw_sensors *** A nagios check for OpenBSD sysctl hw.sensors # @@ -45,13 +45,13 @@ my $state = 'UNKNOWN'; # tells whether the it is warning, critical, or OK my %states; # This stores the count of states; -my $filename; +my $opt_V; +my $opt_h; my $ignore_status; +my $filename; my $sensor; my $warning; my $critical; -my $opt_h; -my $opt_V; my $CHECK_SENSOR = $BASE; my %CHECKS; @@ -60,8 +60,9 @@ #Option checking my $status = GetOptions( "version|V" => \$opt_V, - "filename|f:s" => \$filename, + "help|h" => \$opt_h, "ignore-status|i" => \$ignore_status, + "filename|f:s" => \$filename, "sensor|s=s" => \$sensor, "warning|w=s" => \$warning, "critical|c=s" => \$critical, @@ -117,16 +118,11 @@ } if ($opt_V) { - print_revision( $PROGNAME, '$Revision: 1.26 $ ' ); + print_revision( $PROGNAME, '$Revision: 1.29 $ ' ); exit $ERRORS{'OK'}; } -if ( - $opt_h - || ( ( !defined $filename ) && ( !defined $sensor ) ) - #|| ( defined $sensor && !( $warning || $critical ) ) - ) -{ +if ($opt_h) { print_help(); exit $ERRORS{'OK'}; } @@ -213,7 +209,7 @@ $r = check_sensor( $SENSORS{$s}, $CHECKS{$s} ); $data = $s . '=' . $SENSORS{$s}{'output'}; } - elsif ( not $ignore_status ) { + elsif ( !$ignore_status ) { $r = check_sensor( $SENSORS{$s} ); $data = $s . '=' . $SENSORS{$s}{'output'}; } @@ -325,20 +321,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 +350,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 +363,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 +376,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 +389,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 +420,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 +443,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 +465,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 +491,6 @@ } $result = $errors{$code} unless $matched; } - } elsif ($sensor->{'type'} eq 'drive' || $sensor->{'type'} eq 'indicator' ) @@ -513,7 +509,7 @@ } else { - print STDERR 'Unknown Sensor Type: ', + warn 'Unknown Sensor Type: ', $sensor->{'id'}, '=', $sensor->{'type'}, @@ -538,6 +534,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 +585,15 @@ EOL - print_revision( $PROGNAME, '$Revision: 1.26 $' ); + print_revision( $PROGNAME, '$Revision: 1.29 $' ); print $License; } - sub print_revision { - my ($prog, $rev) = @_; + my ( $prog, $rev ) = @_; $rev =~ s/^\D+([\d\.]+)\D+$/v$1/xms; print "$prog $rev\n"; } - -