bin/checkfs
changeset 5 e0e9dff5c791
parent 4 a29ba54493af
child 6 168e478d1757
--- a/bin/checkfs	Fri Jan 20 14:17:34 2012 +0100
+++ b/bin/checkfs	Fri Jan 20 14:50:20 2012 +0100
@@ -0,0 +1,70 @@
+#! /usr/bin/perl 
+
+#use 5.10.0;
+use strict;
+use warnings;
+use Pod::Usage;
+use Getopt::Long;
+use Nagios;
+
+my $fs;
+
+delete @ENV{grep /^(LC_|LANG)/, keys %ENV};
+
+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 defined($fs = shift)
+  or pod2usage;
+
+my @df = $ENV{HARNESS_ACTIVE} ? <STDIN> : `df -P -B 1K '$fs'`;
+
+($fs, my ($blocks, $used, $avail, undef, $mp)) = split " " => $df[1];
+
+if (not defined $avail or not defined $blocks or $blocks == 0) {
+    print "FS UNKNOWN - can't determine values for $fs\n";
+    exit Nagios::UNKNOWN;
+}
+
+my $ratio = int(100 * ($avail / $blocks));
+my $msg = "$fs on $mp: left ${avail}kB of ${blocks}kB ($ratio%)";
+if ($ratio > 30) { print "FS OK - $msg\n";   exit Nagios::OK }
+if ($ratio > 10) { print "FS WARN - $msg\n"; exit Nagios::WARNING }
+
+print "FS CRIT - $msg ($ratio%)\n";
+exit Nagios::CRITICAL;
+
+__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