add dsa-check-file_size
authorMartin Zobel-Helas <zobel@debian.org>
Mon, 2 Jan 2012 15:30:54 +0000 (16:30 +0100)
committerMartin Zobel-Helas <zobel@debian.org>
Mon, 2 Jan 2012 15:30:54 +0000 (16:30 +0100)
Signed-off-by: Martin Zobel-Helas <zobel@debian.org>
dsa-nagios-checks/checks/dsa-check-file_size [new file with mode: 0755]

diff --git a/dsa-nagios-checks/checks/dsa-check-file_size b/dsa-nagios-checks/checks/dsa-check-file_size
new file mode 100755 (executable)
index 0000000..0d1fcc1
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/perl 
+# $Id: filesize.pl 230 2006-09-30 20:11:05Z touche $
+#  julien.touche@touche.fr.st
+#
+# Added use strict, warning, treshold for min size
+#
+# from http://www.nagiosexchange.org/NRPE_Plugins.66.0.html?&tx_netnagext_pi1[p_view]=81
+#################################################
+# Small quick and dirty perl example from Larry #
+#################################################
+# downloaded from http://exchange.nagios.org/directory/Plugins/System-Metrics/File-System/filesize-2Epl/details
+# by zobel 2012-01-02
+
+use strict;
+
+if($#ARGV+1!=3 || ! -f $ARGV[0]){
+    print "Usage: \"Filename\" \"Critical filesize\" \"Warning filesize\"\n";
+    print " exemples: $0 <file> 1024 512\n";
+    print " exemples: $0 <file> 16:1024 128:512\n";
+    exit 0;
+}
+my $exit=0;
+my ($file,$maxwarn,$maxcrit,$minwarn,$mincrit);
+$file = $ARGV[0];
+$maxcrit = $ARGV[1];
+if ($maxcrit =~ m/([0-9].+):([0-9].+)/) {
+    $mincrit = $1;
+    $maxcrit = $2;
+}
+$maxwarn = $ARGV[2];
+if ($maxwarn =~ m/([0-9].+):([0-9].+)/) {
+    $minwarn = $1;
+    $maxwarn = $2;
+}
+
+my $size= (-s $file);
+
+if ($size>$maxcrit) {
+    print "Critical: Filesize of '$file' too large $size > $maxcrit.\n";$exit=2;
+} elsif (defined($mincrit) && $size < $mincrit) {
+    print "Critical: Filesize of '$file' too small $size < $mincrit.\n";$exit=2;
+} elsif ($size>$maxwarn) {
+    print "Warning: Filesize of '$file' $size > $maxwarn.\n";$exit=1;
+} elsif (defined($minwarn) && $size < $minwarn) {
+    print "Warning: Filesize of '$file' $size < $minwarn.\n";$exit=1;
+} else {
+    print "OK: Filesize of '$file' $size.\n"; $exit = 0;
+}
+exit $exit;