bin/checkfs.sylvia
changeset 4 a29ba54493af
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/checkfs.sylvia	Fri Jan 20 14:17:34 2012 +0100
@@ -0,0 +1,87 @@
+#! /usr/bin/perl
+use 5.8.8;
+use strict;
+use warnings;
+use Pod::Usage;
+use Getopt::Long;
+use Nagios;
+use Switch;
+
+my $file;
+my $fs;
+my $ismp;
+my $isblocks;
+my $isavail;
+my $ispct;
+
+my $opt_input = undef;
+
+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")
+        );
+    },
+    "i|input=s" => \$opt_input,
+) and $fs = shift || pod2usage;
+
+if (defined $opt_input) {
+   my @line = split(/ /, $opt_input);
+   $fs = $line[0];
+   $isblocks = $line[1];
+   $isavail = $line[3];
+   $ispct = $line[4];
+   $ismp = $line[5];
+}
+else 
+{
+   ($fs, my ($blocks, $used, $avail, $pct, $mp)) =
+     split " " => (`df -P -B 1K $fs`)[1];
+   $isblocks = $blocks;
+   $isavail = $avail;
+   $ismp = $mp;
+   $ispct = $pct;
+}
+my $msg = "$fs on $ismp: left ${isavail}kB of ${isblocks}kB ($ispct)";
+
+my $aval = $isavail / $isblocks;
+if ($aval < 0.1)  { print "FS CRIT - $msg\n"; exit Nagios::CRITICAL }
+if ($aval < 0.3)  { print "FS WARN - $msg\n"; exit Nagios::WARNING }
+if ($aval >= 0.3) { 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 [-i|--input]
+    checkfs <filesystem>
+
+=head1 DESCRIPTION
+
+B<checkfs> checks the filesystem.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-h>|B<--help>
+
+=item B<-m>|B<--man>
+
+=item B<-i>|B<--input>
+
+The usual help messages;
+
+=back
+
+
+