From 0b6423f9c99d9edf8c96fefd0f6c453859395aa1 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Mon, 30 Sep 2013 00:03:24 +0200 Subject: Import Nagios Plugins site Import the Nagios Plugins web site, Cronjobs, infrastructure scripts, and configuration files. --- web/attachments/169141-check_file_age.pl.patch | 101 +++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 web/attachments/169141-check_file_age.pl.patch (limited to 'web/attachments/169141-check_file_age.pl.patch') diff --git a/web/attachments/169141-check_file_age.pl.patch b/web/attachments/169141-check_file_age.pl.patch new file mode 100644 index 0000000..857e11c --- /dev/null +++ b/web/attachments/169141-check_file_age.pl.patch @@ -0,0 +1,101 @@ +diff -r -U1 nagios-plugins-HEAD-200602280052-orig/plugins-scripts/check_file_age.pl nagios-plugins-HEAD-200602280052/plugins-scripts/check_file_age.pl +--- nagios-plugins-HEAD-200602280052-orig/plugins-scripts/check_file_age.pl 2005-12-15 16:17:49.000000000 +0100 ++++ nagios-plugins-HEAD-200602280052/plugins-scripts/check_file_age.pl 2006-02-28 12:10:21.000000000 +0100 +@@ -35,4 +35,4 @@ + +-my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V); +-my ($result, $message, $age, $size, $st); ++my ($opt_c, $opt_f, $opt_d, $opt_n, $opt_w, $opt_r, $opt_C, $opt_W, $opt_h, $opt_V); ++my ($result, $message, $age, $size, $st, @files, @failed, $file); + +@@ -45,2 +45,5 @@ + $opt_f = ""; ++$opt_n = 1; ++$opt_d = ""; ++$opt_r = ""; + +@@ -50,3 +53,6 @@ + "h" => \$opt_h, "help" => \$opt_h, ++ "d" => \$opt_d, "dir-content" => \$opt_d, + "f=s" => \$opt_f, "file" => \$opt_f, ++ "n=i" => \$opt_n, "num-files=i" => \$opt_n, ++ "r=s" => \$opt_r, "regexp=s" => \$opt_r, + "w=f" => \$opt_w, "warning-age=f" => \$opt_w, +@@ -79,17 +85,54 @@ + +-$st = File::stat::stat($opt_f); +-$age = time - $st->mtime; +-$size = $st->size; +- ++if ($opt_d) { ++ if (!opendir(DIR, $opt_f)) { ++ print "FILE_AGE CRITICAL: $opt_f: $!"; ++ exit $ERRORS{'CRITICAL'}; ++ } ++ # remove . and .. and filter regular expression ++ @files = grep { !/^\.{1,2}$/ } grep { /$opt_r/ } readdir(DIR); ++ # print "@files"; ++ closedir(DIR); ++} else { ++ @files = ($opt_f); ++} ++ ++my $crit = 0; ++my $warn = 0; ++foreach $file (@files) { ++ if ($opt_d) { ++ $file = "$opt_f/$file"; ++ } ++ $st = File::stat::stat("$file"); ++ $age = time - $st->mtime; ++ $size = $st->size; ++ ++ if (($opt_c and $age > $opt_c) or ($opt_C and $size < $opt_C)) { ++ push (@failed,$file); ++ $crit++; ++ } ++ elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) { ++ push (@failed,$file); ++ $warn++; ++ } ++} ++ ++# return maximum RC if the sum of nOK files exceeds $opt_n ++if ($warn + $crit >= $opt_n) { ++ if ($crit > 0 ) { ++ $result = 'CRITICAL'; ++ } else { ++ $result = 'WARNING'; ++ } ++} else { ++ $result = 'OK'; ++} + +-$result = 'OK'; + +-if (($opt_c and $age > $opt_c) or ($opt_C and $size < $opt_C)) { +- $result = 'CRITICAL'; ++if ( ! $opt_d ) { ++ print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes\n"; ++} else { ++ my $failed = @failed; ++ print "FILE_AGE $result: @failed " . $failed ." files older/smaller than threshold thres: $opt_n\n"; + } +-elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) { +- $result = 'WARNING'; +-} +- +-print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes\n"; ++ + exit $ERRORS{$result}; +@@ -98,3 +141,3 @@ + print "Usage:\n"; +- print " $PROGNAME [-w ] [-c ] [-W ] [-C ] -f \n"; ++ print " $PROGNAME [-w ] [-c ] [-W ] [-C ] [-d [-r ] [-n ] -f \n"; + print " $PROGNAME [-h | --help]\n"; +@@ -110,2 +153,5 @@ + print " File must be at least this many bytes long (default: crit 0 bytes)\n"; ++ print " -d check all files in (if is a directory)\n"; ++ print " -r only check files maching regular expression in directory (only if -d is given)\n"; ++ print " -n minimum number of files that have to be crit/warn to reach non OK state\n"; + print "\n"; -- cgit v1.2.3-74-g34f1