From e3108042c5f76acd268b02c59b52435591ede554 Mon Sep 17 00:00:00 2001 From: Martin Zobel-Helas Date: Mon, 2 Jan 2012 16:30:54 +0100 Subject: [PATCH] add dsa-check-file_size Signed-off-by: Martin Zobel-Helas --- dsa-nagios-checks/checks/dsa-check-file_size | 49 ++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 dsa-nagios-checks/checks/dsa-check-file_size diff --git a/dsa-nagios-checks/checks/dsa-check-file_size b/dsa-nagios-checks/checks/dsa-check-file_size new file mode 100755 index 0000000..0d1fcc1 --- /dev/null +++ b/dsa-nagios-checks/checks/dsa-check-file_size @@ -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 1024 512\n"; + print " exemples: $0 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; -- 2.20.1