bin/checkfs.dominik
changeset 4 a29ba54493af
equal deleted inserted replaced
3:bdbd5e99f85a 4:a29ba54493af
       
     1 #!/usr/bin/perl 
       
     2 
       
     3 #use 5.10.0;
       
     4 use strict;
       
     5 use warnings;
       
     6 use Pod::Usage;
       
     7 use Getopt::Long;
       
     8 use Nagios;
       
     9 
       
    10 #use Switch 'Perl6';
       
    11 
       
    12 my $fs;
       
    13 my $input = undef;
       
    14 my $mp;
       
    15 my $avail;
       
    16 my $blocks;
       
    17 my $used;
       
    18 my $msg;
       
    19 
       
    20 GetOptions(
       
    21     "i|input=s" => \$input,
       
    22     "h|help"    => sub { pod2usage(-exit => 0, -verbose => 1) },
       
    23     "m|man"     => sub {
       
    24         pod2usage(
       
    25             -exit      => 0,
       
    26             -verbose   => 2,
       
    27             -noperldoc => system("perldoc -V 2>/dev/null 1>&2")
       
    28         );
       
    29     },
       
    30 );
       
    31 
       
    32 if (not defined $input) {
       
    33     ($fs, $blocks, $used, $avail, undef, $mp) =
       
    34       split " " => (`df -P -B 1K $fs`)[1];
       
    35     $msg = "$fs on $mp: left ${avail}kB of ${blocks}kB";
       
    36 }
       
    37 else {
       
    38     ($fs, $blocks, $used, $avail, undef, $mp) =
       
    39       split " " => $input;
       
    40     $msg = "$fs on $mp: left ${avail}kB of ${blocks}kB";
       
    41 }
       
    42 
       
    43 if ($avail * 100 / $blocks > 90) {
       
    44     print "Warning - $msg\n";
       
    45     exit Nagios::WARNING;
       
    46 }
       
    47 else {
       
    48     print "OK - $msg\n";
       
    49     exit Nagios::OK;
       
    50 }
       
    51 
       
    52 #given ($avail / $blocks) {
       
    53 #    when ($_ < 0.1) { print "FS CRIT - $msg\n"; exit Nagios::CRITICAL }
       
    54 #    when ($_ < 0.3) { print "FS WARN - $msg\n"; exit Nagios::WARNING }
       
    55 #    default         { print "FS OK - $msg\n";   exit Nagios::OK }
       
    56 #}
       
    57 
       
    58 __END__
       
    59 
       
    60 =head1 NAME
       
    61 
       
    62     checkfs - check the current file system
       
    63 
       
    64 =head1 SYNOPSIS
       
    65 
       
    66     checkfs [-i|--input]
       
    67     checkfs [-h|--help]
       
    68     checkfs [-m|--man]
       
    69     checkfs <filesystem>
       
    70 
       
    71 =head1 DESCRIPTION
       
    72 
       
    73 B<checkfs> checks the filesystem.
       
    74 
       
    75 =head1 OPTIONS
       
    76 
       
    77 =over 5 
       
    78 
       
    79 =item B<-i>|B<--input>
       
    80 
       
    81 =item B<-h>|B<--help>
       
    82 
       
    83 =item B<-m>|B<--man>
       
    84 
       
    85 The usual help messages;
       
    86 
       
    87 =back
       
    88 
       
    89