#! /usr/bin/perl
use 5.10.0;
use strict;
use warnings;
use Pod::Usage;
use Getopt::Long;
use Nagios;

my $fs;

GetOptions(
    "h|help" => sub { pod2usage(-exit => 0, -verbose => 1) },
    "m|man"  => sub {
        pod2usage(
            -exit      => 0,
            -verbose   => 2,
            -noperldoc => system("perldoc -V 2>/dev/null 1>&2")
        );
    },
) and $fs = shift // pod2usage;

($fs, my ($blocks, $used, $avail, undef, $mp)) =
  split " " => (`df -P -B 1K $fs`)[1];
my $msg = "$fs on $mp: left ${avail}kB of ${blocks}kB";

given ($avail / $blocks) {
    when ($_ < 0.1) { print "FS CRIT - $msg\n"; exit Nagios::CRITICAL }
    when ($_ < 0.3) { print "FS WARN - $msg\n"; exit Nagios::WARNING }
    default         { print "FS OK - $msg\n";   exit Nagios::OK }
}

__END__

=head1 NAME

    checkfs - check the current file system

=head1 SYNOPSIS

    checkfs [-h|--help]
    checkfs [-m|--man]
    checkfs <filesystem>

=head1 DESCRIPTION

B<checkfs> checks the filesystem.

=head1 OPTIONS

=over 4

=item B<-h>|B<--help>

=item B<-m>|B<--man>

The usual help messages;

=back

