bin/checkfs.maik
changeset 5 e0e9dff5c791
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/checkfs.maik	Fri Jan 20 14:50:20 2012 +0100
@@ -0,0 +1,96 @@
+#! /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 $input;
+
+GetOptions(
+    "i|input=s" => \$input,
+    "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;
+
+my @output = $input ? input() : `df -P -B 1K $fs`;
+
+($fs, my ($blocks, $used, $avail, undef, $mp)) =
+  split " " => $output[1];
+my $msg = "$fs on $mp: left ${avail}kB of ${blocks}kB";
+
+if (not defined $blocks or $blocks == 0) {
+    print "FS UNKNOWN - do not know anything about $fs\n";
+    exit Nagios::UNKNOWN;
+}
+
+my $ratio = $avail / $blocks;
+
+if($ratio > 0.2) {
+   print "FS OK - ($ratio) $msg\n";   exit Nagios::OK;
+} elsif($ratio > 0.1) {
+   print "FS WARN - ($ratio) $msg\n"; exit Nagios::WARNING;
+} else {
+   print "FS CRIT - ($ratio) $msg\n"; exit Nagios::CRITICAL;
+}
+
+#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 }
+#}
+
+sub input
+{
+   our @ARGV = ($input);
+   return <>;
+#   my @data;
+#   if($input eq "-") {
+#      @data = <STDIN>;
+#   } else {
+#      open("IN", $input) or die "Can't open $input";
+#      @data = <IN>;
+#      close IN;
+#   }
+#
+#   return @data;
+}
+
+__END__
+
+=head1 NAME
+
+    checkfs - check the current file system
+
+=head1 SYNOPSIS
+
+    checkfs [-h|--help]
+    checkfs [-m|--man]
+    checkfs <filesystem>
+    checkfs -i <df output> <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
+