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