bin/checkfs.pjotr
changeset 4 a29ba54493af
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/checkfs.pjotr	Fri Jan 20 14:17:34 2012 +0100
@@ -0,0 +1,87 @@
+#! /usr/bin/perl
+#use 5.10.0;
+use strict;
+use warnings;
+use Pod::Usage;
+use Getopt::Long;
+use Nagios;
+use Switch 'Perl6';
+
+my $fs;
+my $stdin = 0;
+
+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")
+        );
+    },
+    "s|stdin" => \$stdin,
+) and $fs = shift;
+
+pod2usage if (!$fs && !$stdin);
+
+my @data;
+
+if ($stdin) {
+   while (<STDIN>) {
+      push @data, $_;
+   }
+} else {
+   @data = `df -P -B 1K $fs`;
+}
+
+analyze(\@data);
+
+sub analyze {
+   my $data = shift;
+   my ($fs, $blocks, $used, $avail, undef, $mp) = split /\s+/ => $data->[1];
+   my $msg = "$fs on $mp: left ${avail}kB of ${blocks}kB";
+
+   my $free = $avail / $blocks;
+
+   if ($free < 0.1)    { print "FS CRIT - $msg\n"; exit Nagios::CRITICAL }
+   elsif ($free < 0.3) { print "FS WARN - $msg\n"; exit Nagios::WARNING }
+   else                { print "FS OK - $msg\n";   exit Nagios::OK }
+
+
+#   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
+
+
+