bin/checkfs
changeset 3 bdbd5e99f85a
parent 2 bc2f76c0908a
child 4 a29ba54493af
equal deleted inserted replaced
2:bc2f76c0908a 3:bdbd5e99f85a
     1 #! /usr/bin/perl
     1 #! /usr/bin/perl 
     2 use 5.10.0;
     2 
       
     3 #use 5.10.0;
       
     4 use Switch 'Perl6';
     3 use strict;
     5 use strict;
     4 use warnings;
     6 use warnings;
     5 use Pod::Usage;
     7 use Pod::Usage;
     6 use Getopt::Long;
     8 use Getopt::Long;
     7 use Nagios;
     9 use Nagios;
    15             -exit      => 0,
    17             -exit      => 0,
    16             -verbose   => 2,
    18             -verbose   => 2,
    17             -noperldoc => system("perldoc -V 2>/dev/null 1>&2")
    19             -noperldoc => system("perldoc -V 2>/dev/null 1>&2")
    18         );
    20         );
    19     },
    21     },
    20 ) and $fs = shift // pod2usage;
    22   )
       
    23   and defined($fs = shift)
       
    24   or pod2usage;
    21 
    25 
    22 ($fs, my ($blocks, $used, $avail, undef, $mp)) =
    26 my @df = $ENV{HARNESS_ACTIVE} ? <STDIN> : `df -P -B 1K '$fs'`;
    23   split " " => (`df -P -B 1K $fs`)[1];
       
    24 my $msg = "$fs on $mp: left ${avail}kB of ${blocks}kB";
       
    25 
    27 
    26 given ($avail / $blocks) {
    28 ($fs, my ($blocks, $used, $avail, undef, $mp)) = split " " => $df[1];
    27     when ($_ < 0.1) { print "FS CRIT - $msg\n"; exit Nagios::CRITICAL }
    29 
    28     when ($_ < 0.3) { print "FS WARN - $msg\n"; exit Nagios::WARNING }
    30 if (not defined $avail or not defined $blocks or $blocks == 0) {
    29     default         { print "FS OK - $msg\n";   exit Nagios::OK }
    31     print "FS UNKNOWN - can't determine values for $fs\n";
       
    32     exit Nagios::UNKNOWN;
    30 }
    33 }
       
    34 
       
    35 my $ratio = int(100 * ($avail / $blocks));
       
    36 my $msg = "$fs on $mp: left ${avail}kB of ${blocks}kB ($ratio%)";
       
    37 if ($ratio > 30) { print "FS OK - $msg\n";   exit Nagios::OK }
       
    38 if ($ratio > 10) { print "FS WARN - $msg\n"; exit Nagios::WARNING }
       
    39 
       
    40 print "FS CRIT - $msg ($ratio%)\n";
       
    41 exit Nagios::CRITICAL;
    31 
    42 
    32 __END__
    43 __END__
    33 
    44 
    34 =head1 NAME
    45 =head1 NAME
    35 
    46