check_hddtemp.pl
changeset 1 5f67fdc48747
parent 0 2fde8823787b
child 2 21b771e60058
equal deleted inserted replaced
0:2fde8823787b 1:5f67fdc48747
    15 #    You should have received a copy of the GNU General Public License
    15 #    You should have received a copy of the GNU General Public License
    16 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17 #
    17 #
    18 #    Christian Arnold <arnold@schlittermann.de>
    18 #    Christian Arnold <arnold@schlittermann.de>
    19 
    19 
    20 use 5.010;
       
    21 use strict;
    20 use strict;
    22 use File::Basename;
    21 use File::Basename;
    23 use Getopt::Long;
    22 use Getopt::Long;
    24 use Pod::Usage;
    23 use Pod::Usage;
    25 
    24 
    38     DEPENDENT => 4
    37     DEPENDENT => 4
    39 );
    38 );
    40 
    39 
    41 my $ME      = basename $0;
    40 my $ME      = basename $0;
    42 my $NAME    = "HDDTEMP";
    41 my $NAME    = "HDDTEMP";
    43 my $VERSION = "1.5";
    42 my $VERSION = "1.6";
    44 
    43 
    45 my ( @devices, @output );
    44 my ( @devices, @output );
    46 
    45 
    47 my %opt = (
    46 my %opt = (
    48     "warning"  => 55,
    47     "warning"  => 55,
    70     my ( $binary, $devices, $warning, $critical ) = @_;
    69     my ( $binary, $devices, $warning, $critical ) = @_;
    71     my $rc;
    70     my $rc;
    72     my %temp;
    71     my %temp;
    73 
    72 
    74     if ( !-x $binary ) {
    73     if ( !-x $binary ) {
    75         say "$NAME CRITICAL: $binary - not found or not executable";
    74         print "$NAME CRITICAL: $binary - not found or not executable\n";
    76         exit $ERRORS{CRITICAL};
    75         exit $ERRORS{CRITICAL};
    77     }
    76     }
    78 
    77 
    79     my @devices = split( /,/, $devices );
    78     my @devices = split( /,/, $devices );
    80 
    79 
    81     foreach my $dev (@devices) {
    80     foreach my $dev (@devices) {
    82         if ( !-r $dev ) {
    81         if ( !-r $dev ) {
    83             say
    82             print
    84 "$NAME CRITICAL: $dev - not exists or not read permission is granted";
    83 "$NAME CRITICAL: $dev - not exists or not read permission is granted\n";
    85             exit $ERRORS{CRITICAL};
    84             exit $ERRORS{CRITICAL};
    86         }
    85         }
    87         my @line = grep { /^$dev/ } `$binary $dev`;
    86         my @line = grep { /^$dev/ } `$binary $dev`;
    88 
    87 
    89         if ( $line[0] ) {
    88         if ( $line[0] ) {
   122             push @perf,   "$dev=$temp{$dev}{'rc'}{'2'};$warning;$critical";
   121             push @perf,   "$dev=$temp{$dev}{'rc'}{'2'};$warning;$critical";
   123         }
   122         }
   124     }
   123     }
   125 
   124 
   126     if ($crit) {
   125     if ($crit) {
   127         say "$NAME CRITICAL: "
   126         print "$NAME CRITICAL: "
   128           . join( ' ', @output ) . " | "
   127           . join( ' ', @output ) . " | "
   129           . join( ' ', @perf );
   128           . join( ' ', @perf ) . "\n";
   130         exit $ERRORS{CRITICAL};
   129         exit $ERRORS{CRITICAL};
   131     }
   130     }
   132     elsif ($warn) {
   131     elsif ($warn) {
   133         say "$NAME WARNING: "
   132         print "$NAME WARNING: "
   134           . join( ' ', @output ) . " | "
   133           . join( ' ', @output ) . " | "
   135           . join( ' ', @perf );
   134           . join( ' ', @perf ) . "\n";
   136         exit $ERRORS{WARNING};
   135         exit $ERRORS{WARNING};
   137     }
   136     }
   138 
   137 
   139     say "$NAME OK: " . join( ' ', @output ) . " | " . join( ' ', @perf );
   138     print "$NAME OK: " . join( ' ', @output ) . " | " . join( ' ', @perf ) . "\n";
   140     exit $ERRORS{OK};
   139     exit $ERRORS{OK};
   141 }
   140 }
   142 
   141 
   143 sub version($$) {
   142 sub version($$) {
   144     my ( $progname, $version ) = @_;
   143     my ( $progname, $version ) = @_;
   145 
   144 
   146     say <<_VERSION;
   145     print <<_VERSION;
   147 $progname version $version
   146 $progname version $version
   148 Copyright (C) 2012 by Christian Arnold and Schlittermann internet & unix support.
   147 Copyright (C) 2012 by Christian Arnold and Schlittermann internet & unix support.
   149 
   148 
   150 $ME comes with ABSOLUTELY NO WARRANTY. This is free software,
   149 $ME comes with ABSOLUTELY NO WARRANTY. This is free software,
   151 and you are welcome to redistribute it under certain conditions.
   150 and you are welcome to redistribute it under certain conditions.
   207 
   206 
   208 This plugin checks the hard drive temperature.
   207 This plugin checks the hard drive temperature.
   209 
   208 
   210 =head1 VERSION
   209 =head1 VERSION
   211 
   210 
   212 This man page is current for version 1.5 of B<check_hddtemp>.
   211 This man page is current for version 1.6 of B<check_hddtemp>.
   213 
   212 
   214 =head1 AUTHOR
   213 =head1 AUTHOR
   215 
   214 
   216 Written by Christian Arnold L<arnold@schlittermann.de>
   215 Written by Christian Arnold L<arnold@schlittermann.de>
   217 
   216