[BACK]Return to check_hw_sensors CVS log [TXT][DIR] Up to [local] / nagios / check_hw_sensors

Diff for /nagios/check_hw_sensors/check_hw_sensors between version 1.41 and 1.42

version 1.41, 2009/11/12 18:53:52 version 1.42, 2009/11/24 17:54:54
Line 1 
Line 1 
 #!/usr/bin/perl -T  #!/usr/bin/perl -T
 # $RedRiver: check_hw_sensors,v 1.40 2009/11/11 18:14:40 andrew Exp $  # $RedRiver: check_hw_sensors,v 1.41 2009/11/12 18:53:52 andrew Exp $
 ########################################################################  ########################################################################
 # check_hw_sensors *** A nagios check for OpenBSD sysctl hw.sensors  # check_hw_sensors *** A nagios check for OpenBSD sysctl hw.sensors
 #  #
Line 10 
Line 10 
   
 local %ENV = ();  local %ENV = ();
   
   use POSIX;
   use Config;
   use Getopt::Long;
   use List::Util qw/ first /;
   
 my $NAGIOS_OUTPUT = 1;  my $NAGIOS_OUTPUT = 1;
   
   our $VERSION = q{$Revision$}; $VERSION =~ s/^\D+([\d\.]+)\D+$/v$1/xms;
   
 my $LICENSE = <<'EOL';  my $LICENSE = <<'EOL';
 Copyright (c) 2009 Andrew Fresh <andrew@afresh1.com>  Copyright (c) 2009 Andrew Fresh <andrew@afresh1.com>
 Permission to use, copy, modify, and distribute this software for any  Permission to use, copy, modify, and distribute this software for any
Line 33 
Line 40 
 my $BASE           = 'hw.sensors';  my $BASE           = 'hw.sensors';
 my $DEFAULT_CONFIG = '/etc/sensorsd.conf';  my $DEFAULT_CONFIG = '/etc/sensorsd.conf';
   
 use POSIX;  
 use Config;  
 my $PREFIX;  my $PREFIX;
   
 BEGIN {  BEGIN {
Line 46 
Line 51 
 use utils qw($TIMEOUT %ERRORS &support);  use utils qw($TIMEOUT %ERRORS &support);
   
 $SIG{'ALRM'} = sub {  $SIG{'ALRM'} = sub {
     print("ERROR: $PROGNAME timeout\n");      print "ERROR: $PROGNAME timeout\n";
     exit $ERRORS{'UNKNOWN'};      exit $ERRORS{'UNKNOWN'};
 };  };
 alarm($TIMEOUT);  alarm $TIMEOUT;
   
 use Getopt::Long;  
 Getopt::Long::Configure('bundling');  Getopt::Long::Configure('bundling');
   
 my $OSVer = $Config{'osvers'} || 0;  my $OSVer = $Config{'osvers'} || 0;
Line 82 
Line 86 
 }  }
   
 if ($opt_V) {  if ($opt_V) {
     print_revision( $PROGNAME, '$Revision$ ' );      print_revision( $PROGNAME, $VERSION );
     exit $ERRORS{'OK'};      exit $ERRORS{'OK'};
 }  }
   
Line 92 
Line 96 
 }  }
   
 # set the default this way so it only happens if someone typed -f or --filename  # set the default this way so it only happens if someone typed -f or --filename
 $FILENAME = $DEFAULT_CONFIG if ( defined $FILENAME && $FILENAME eq q{} );  if ( defined $FILENAME && $FILENAME eq q{} ) {
       $FILENAME = $DEFAULT_CONFIG;
   }
   
 # Stuff is output in this file by print_sensor()  # Stuff is output in this file by print_sensor()
 # http://www.openbsd.org/cgi-bin/cvsweb/src/sbin/sysctl/sysctl.c  # http://www.openbsd.org/cgi-bin/cvsweb/src/sbin/sysctl/sysctl.c
Line 143 
Line 149 
     }      }
     $CHECK_SENSOR = $SENSOR;      $CHECK_SENSOR = $SENSOR;
   
     $CHECKS{$SENSOR}{'warn'} = $WARNING  if $WARNING;      if ($WARNING)  { $CHECKS{$SENSOR}{'warn'} = $WARNING; }
     $CHECKS{$SENSOR}{'crit'} = $CRITICAL if $CRITICAL;      if ($CRITICAL) { $CHECKS{$SENSOR}{'crit'} = $CRITICAL; }
 }  }
 elsif ( defined $FILENAME ) {  elsif ( defined $FILENAME ) {
     %CHECKS = read_file($FILENAME);      %CHECKS = read_file($FILENAME);
Line 186 
Line 192 
 sub read_sensors {  sub read_sensors {
     my ($sensor) = @_;      my ($sensor) = @_;
     my @S;      my @S;
     open my $sysctl, '-|', $SYSCTL, $sensor      open my $sysctl, q{-|}, $SYSCTL, $sensor
         or die "Couldn't open sysctl: $!\n";          or die "Couldn't open sysctl: $!\n";
     while (<$sysctl>) {      while (<$sysctl>) {
         chomp;          chomp;
Line 204 
Line 210 
 sub parse_sensor {  sub parse_sensor {
     my ($sensor) = @_;      my ($sensor) = @_;
   
       ## no critic 'literal'
     my ( $id, $output ) = split /=/xms, $sensor;      my ( $id, $output ) = split /=/xms, $sensor;
     my @s = split /\./xms,   $id;      my @s = split /\./xms,   $id;
     my @o = split /,\s*/xms, $output;      my @o = split /,\s*/xms, $output;
Line 254 
Line 261 
     my $filename = shift;      my $filename = shift;
     my %contents;      my %contents;
   
     die "file '$filename' does not exist.\n" unless -e $filename;      die "file '$filename' does not exist.\n" if !-e $filename;
   
     open my $fh, '-|', $GETCAP, '-a', '-f', $filename      open my $fh, q{-|}, $GETCAP, q{-a}, q{-f}, $filename
         or die "Couldn't open '$GETCAP -a -f $filename': $!\n";          or die "Couldn't open '$GETCAP -a -f $filename': $!\n";
     while (<$fh>) {      while (<$fh>) {
         chomp;          chomp;
Line 287 
Line 294 
 sub parse_check {  sub parse_check {
     my $check = shift;      my $check = shift;
   
     return unless $check;      return          if !$check;
     return 'STATUS' if $check->{'STATUS'};      return 'STATUS' if $check->{'STATUS'};
     return 'IGNORE' if $check->{'IGNORE'};      return 'IGNORE' if $check->{'IGNORE'};
   
Line 301 
Line 308 
         }          }
   
         foreach my $direction ( 'low', 'high' ) {          foreach my $direction ( 'low', 'high' ) {
             my $c = $code . '.' . $direction;              my $c = $code . q{.} . $direction;
             if ( defined $check->{$direction} ) {              if ( defined $check->{$direction} ) {
                 $check->{$c} ||= $check->{$direction};                  $check->{$c} ||= $check->{$direction};
             }              }
Line 335 
Line 342 
         my ( $r, $data );          my ( $r, $data );
         if ( exists $C->{ $sensor->{id} } ) {          if ( exists $C->{ $sensor->{id} } ) {
             $r = check_sensor( $sensor, $C->{ $sensor->{id} } );              $r = check_sensor( $sensor, $C->{ $sensor->{id} } );
             $data = $sensor->{id} . '=' . $sensor->{output};              $data = $sensor->{id} . q{=} . $sensor->{output};
         }          }
         elsif ( $sensor->{status} && !$O->{IGNORE_STATUS} ) {          elsif ( $sensor->{status} && !$O->{IGNORE_STATUS} ) {
             $r = check_sensor( $sensor, { STATUS => 1 } );              $r = check_sensor( $sensor, { STATUS => 1 } );
             $data = $sensor->{id} . '=' . $sensor->{output};              $data = $sensor->{id} . q{=} . $sensor->{output};
         }          }
         else {          else {
   
Line 358 
Line 365 
     my ( $sensor, $check ) = @_;      my ( $sensor, $check ) = @_;
     my $result = 'UNKNOWN';      my $result = 'UNKNOWN';
   
     return $result unless ref $sensor eq 'HASH';      return $result if ref $sensor ne 'HASH';
     $check = parse_check($check) if $check;      $check = parse_check($check) if $check;
   
     if ( !$check ) { return $result; }      if ( !$check ) { return $result; }
Line 371 
Line 378 
     elsif ( $check eq 'IGNORE' ) { return; }      elsif ( $check eq 'IGNORE' ) { return; }
   
     my $type = $sensor->{'type'};      my $type = $sensor->{'type'};
     if (grep { $type eq $_ }      if (first { $type eq $_ }
         qw(          qw(
         fan fanrpm          fan fanrpm
         volt volts_dc          volt volts_dc
Line 383 
Line 390 
     {      {
         $result = check_sensor_numeric( $sensor->{'data'}, $check );          $result = check_sensor_numeric( $sensor->{'data'}, $check );
     }      }
     elsif ( grep { $type eq $_ } qw( drive indicator ) ) {      elsif ( first { $type eq $_ } qw( drive indicator ) ) {
         my $data = $sensor->{'data'};          my $data = $sensor->{'data'};
         $data =~ s/^drive\s+//xms;          $data =~ s/^drive\s+//xms;
         $result = check_sensor_list( $data, $check );          $result = check_sensor_list( $data, $check );
     }      }
     else {      else {
         warn 'Unknown Sensor Type: ', $sensor->{'id'}, '=', $type, "\n";          warn "Unknown Sensor Type: $sensor->{id} = $type\n";
     }      }
   
     return $result;      return $result;
Line 542 
Line 549 
   
 EOL  EOL
   
     print_revision( $PROGNAME, '$Revision$' );      print_revision( $PROGNAME, $VERSION );
   
     print $LICENSE;      print $LICENSE;
   
Line 551 
Line 558 
   
 sub print_revision {  sub print_revision {
     my ( $prog, $rev ) = @_;      my ( $prog, $rev ) = @_;
     $rev =~ s/^\D+([\d\.]+)\D+$/v$1/xms;  
   
     print "$prog $rev\n";      print "$prog $rev\n";
   

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.42

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>