bin/checkfs
changeset 3 bdbd5e99f85a
parent 2 bc2f76c0908a
child 4 a29ba54493af
--- a/bin/checkfs	Fri Jan 20 09:13:33 2012 +0100
+++ b/bin/checkfs	Fri Jan 20 13:21:49 2012 +0100
@@ -1,5 +1,7 @@
-#! /usr/bin/perl
-use 5.10.0;
+#! /usr/bin/perl 
+
+#use 5.10.0;
+use Switch 'Perl6';
 use strict;
 use warnings;
 use Pod::Usage;
@@ -17,18 +19,27 @@
             -noperldoc => system("perldoc -V 2>/dev/null 1>&2")
         );
     },
-) and $fs = shift // pod2usage;
+  )
+  and defined($fs = shift)
+  or 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";
+my @df = $ENV{HARNESS_ACTIVE} ? <STDIN> : `df -P -B 1K '$fs'`;
+
+($fs, my ($blocks, $used, $avail, undef, $mp)) = split " " => $df[1];
 
-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 }
+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