check_hddtemp.pl
changeset 2 21b771e60058
parent 1 5f67fdc48747
equal deleted inserted replaced
1:5f67fdc48747 2:21b771e60058
     1 #! /usr/bin/perl -w
     1 #! /usr/bin/perl -w
     2 
     2 
     3 #    Copyright (C) 2012  Christian Arnold
     3 #    Copyright (C) 2012  Christian Arnold
       
     4 #    Copyright (C) 2015  Matthias Förste
     4 #
     5 #
     5 #    This program is free software: you can redistribute it and/or modify
     6 #    This program is free software: you can redistribute it and/or modify
     6 #    it under the terms of the GNU General Public License as published by
     7 #    it under the terms of the GNU General Public License as published by
     7 #    the Free Software Foundation, either version 3 of the License, or
     8 #    the Free Software Foundation, either version 3 of the License, or
     8 #    (at your option) any later version.
     9 #    (at your option) any later version.
    25 delete @ENV{ grep /^LC_/ => keys %ENV };
    26 delete @ENV{ grep /^LC_/ => keys %ENV };
    26 $ENV{LANG}   = "C";
    27 $ENV{LANG}   = "C";
    27 $ENV{LC_ALL} = "C";
    28 $ENV{LC_ALL} = "C";
    28 
    29 
    29 sub version($$);
    30 sub version($$);
    30 sub hddtemp($$$$);
    31 sub hddtemp($$$$$);
    31 
    32 
    32 my %ERRORS = (
    33 my %ERRORS = (
    33     OK        => 0,
    34     OK        => 0,
    34     WARNING   => 1,
    35     WARNING   => 1,
    35     CRITICAL  => 2,
    36     CRITICAL  => 2,
    37     DEPENDENT => 4
    38     DEPENDENT => 4
    38 );
    39 );
    39 
    40 
    40 my $ME      = basename $0;
    41 my $ME      = basename $0;
    41 my $NAME    = "HDDTEMP";
    42 my $NAME    = "HDDTEMP";
    42 my $VERSION = "1.6";
    43 my $VERSION = "1.7";
    43 
    44 
    44 my ( @devices, @output );
    45 my ( @devices, @output );
    45 
    46 
    46 my %opt = (
    47 my %opt = (
    47     "warning"  => 55,
    48     "warning"  => 55,
    48     "critical" => 65,
    49     "critical" => 65,
    49     "devices"  => "/dev/sda,/dev/sdb",
    50     "devices"  => 'all',
       
    51     "exclude"  => '/dev/sg',
    50     "binary"   => "/usr/sbin/hddtemp"
    52     "binary"   => "/usr/sbin/hddtemp"
    51 );
    53 );
    52 
    54 
    53 MAIN: {
    55 MAIN: {
    54     Getopt::Long::Configure('bundling');
    56     Getopt::Long::Configure('bundling');
    55     GetOptions(
    57     GetOptions(
    56         "b|binary=s"   => \$opt{binary},
    58         "b|binary=s"   => \$opt{binary},
    57         "d|devices=s"  => \$opt{devices},
    59         "d|devices=s"  => \$opt{devices},
       
    60         "x|exclude=s"  => \$opt{exclude},
    58         "w|warning=i"  => \$opt{warning},
    61         "w|warning=i"  => \$opt{warning},
    59         "c|critical=i" => \$opt{critical},
    62         "c|critical=i" => \$opt{critical},
    60         "h|help" => sub { pod2usage( -verbose => 1, -exitval => $ERRORS{OK} ) },
    63         "h|help" => sub { pod2usage( -verbose => 1, -exitval => $ERRORS{OK} ) },
    61         "m|man" => sub { pod2usage( -verbose => 2, -exitval => $ERRORS{OK} ) },
    64         "m|man" => sub { pod2usage( -verbose => 2, -exitval => $ERRORS{OK} ) },
    62         "V|version" => sub { version( $ME, $VERSION ); exit $ERRORS{OK}; }
    65         "V|version" => sub { version( $ME, $VERSION ); exit $ERRORS{OK}; }
    63     ) or pod2usage( -verbose => 1, -exitval => $ERRORS{CRITICAL} );
    66     ) or pod2usage( -verbose => 1, -exitval => $ERRORS{CRITICAL} );
    64 
    67 
    65     hddtemp( $opt{binary}, $opt{devices}, $opt{warning}, $opt{critical} );
    68     hddtemp( $opt{binary}, $opt{devices}, $opt{warning}, $opt{critical}, $opt{exclude} );
    66 }
    69 }
    67 
    70 
    68 sub hddtemp($$$$) {
    71 sub hddtemp($$$$$) {
    69     my ( $binary, $devices, $warning, $critical ) = @_;
    72     my ( $binary, $devices, $warning, $critical, $exclude ) = @_;
    70     my $rc;
    73     my $rc;
    71     my %temp;
    74     my %temp;
    72 
    75 
    73     if ( !-x $binary ) {
    76     if ( !-x $binary ) {
    74         print "$NAME CRITICAL: $binary - not found or not executable\n";
    77         print "$NAME CRITICAL: $binary - not found or not executable\n";
    75         exit $ERRORS{CRITICAL};
    78         exit $ERRORS{CRITICAL};
    76     }
    79     }
    77 
    80 
    78     my @devices = split( /,/, $devices );
    81     my @devices;
       
    82     if ($devices eq 'all') {
       
    83         @devices =  grep { not /$exclude/; } glob "/dev/[hs]d? /dev/cciss/c[0-9]d[0-9] /dev/tw[ael][0-9] /dev/sg*";
       
    84     } elsif (defined $devices) {
       
    85         @devices = split( /,/, $devices );
       
    86     }
    79 
    87 
    80     foreach my $dev (@devices) {
    88     foreach my $dev (@devices) {
    81         if ( !-r $dev ) {
    89         if ( !-r $dev ) {
    82             print
    90             print
    83 "$NAME CRITICAL: $dev - not exists or not read permission is granted\n";
    91 "$NAME CRITICAL: $dev - not exists or not read permission is granted\n";
   184 
   192 
   185 Temperature of your hard drive to generate critical alert (default: 65)
   193 Temperature of your hard drive to generate critical alert (default: 65)
   186 
   194 
   187 =item B<-d>|B<--devices>
   195 =item B<-d>|B<--devices>
   188 
   196 
   189 Device drive path (default: /dev/sda,/dev/sdb)
   197 Device drive path (default: all we can find)
       
   198 
       
   199 =item B<-x>|B<--exclude>
       
   200 
       
   201 A regular expression matching all devices we do not want to check (default:
       
   202 '/dev/sg')
   190 
   203 
   191 =item B<-h>|B<--help>
   204 =item B<-h>|B<--help>
   192 
   205 
   193 Print detailed help screen.
   206 Print detailed help screen.
   194 
   207 
   206 
   219 
   207 This plugin checks the hard drive temperature.
   220 This plugin checks the hard drive temperature.
   208 
   221 
   209 =head1 VERSION
   222 =head1 VERSION
   210 
   223 
   211 This man page is current for version 1.6 of B<check_hddtemp>.
   224 This man page is current for version 1.7 of B<check_hddtemp>.
   212 
   225 
   213 =head1 AUTHOR
   226 =head1 AUTHOR
   214 
   227 
   215 Written by Christian Arnold L<arnold@schlittermann.de>
   228 Written by Christian Arnold L<arnold@schlittermann.de>, Matthias Förste L<förste@schlittermann.de>
   216 
   229 
   217 =head1 COPYRIGHT
   230 =head1 COPYRIGHT
   218 
   231 
   219 Copyright (C) 2012 by Christian Arnold and Schlittermann internet & unix support.
   232 Copyright (C) 2012 by Christian Arnold and Schlittermann internet & unix
       
   233 support, (C) 2015 by Matthias Förste and Schlittermann internet & unix support.
   220 This is free software, and you are welcome to redistribute it under certain conditions.
   234 This is free software, and you are welcome to redistribute it under certain conditions.
   221 See the GNU General Public Licence for details.
   235 See the GNU General Public Licence for details.
   222 
   236 
   223 =cut
   237 =cut