summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_file_age.pl
diff options
context:
space:
mode:
authorJan Wagner <waja@cyconet.org>2013-09-30 23:38:45 (GMT)
committerJan Wagner <waja@cyconet.org>2014-01-24 19:43:01 (GMT)
commit0b9b300f856d021b56950030f4e6053d84bc77c8 (patch)
tree57191e44659a3306616788d63a9ec977d13fd0c1 /plugins-scripts/check_file_age.pl
parent455fe96e7dcadd433973b1709ee79cdb58ffe428 (diff)
downloadmonitoring-plugins-0b9b300f856d021b56950030f4e6053d84bc77c8.tar.gz
check_file_age: support for --ignore-missing
Patch to provide for a -i | --ignore-missing option. This allows files that don't exist to be monitored for without causing an error. The use case is: * one process periodically pushes files to an "input" queue for a second process * the second process, when running cleanly will "consume" (process and remove) these files So the conditions to meet are: 1. If the file doesn't exist, that's fine (OK) 2. If the file exists, but is less than X seconds, that's fine (OK) 3. If the file exists, but greater than X seconds, no good (CRITICAL) Since now check_file_age doesn't permit this behavior, as a non-existent file is considered CRITICAL. Test case was contributed by our lovely Holger. Closes #1181, Closes #989, Closes #862, Closes #1187, Closes #845 Closes Debian Bug #496307
Diffstat (limited to 'plugins-scripts/check_file_age.pl')
-rwxr-xr-xplugins-scripts/check_file_age.pl17
1 files changed, 13 insertions, 4 deletions
diff --git a/plugins-scripts/check_file_age.pl b/plugins-scripts/check_file_age.pl
index 4cdb36d..2781c2a 100755
--- a/plugins-scripts/check_file_age.pl
+++ b/plugins-scripts/check_file_age.pl
@@ -31,7 +31,7 @@ use utils qw (%ERRORS &print_revision &support);
31sub print_help (); 31sub print_help ();
32sub print_usage (); 32sub print_usage ();
33 33
34my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V); 34my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V, $opt_i);
35my ($result, $message, $age, $size, $st); 35my ($result, $message, $age, $size, $st);
36 36
37$PROGNAME="check_file_age"; 37$PROGNAME="check_file_age";
@@ -46,6 +46,7 @@ Getopt::Long::Configure('bundling');
46GetOptions( 46GetOptions(
47 "V" => \$opt_V, "version" => \$opt_V, 47 "V" => \$opt_V, "version" => \$opt_V,
48 "h" => \$opt_h, "help" => \$opt_h, 48 "h" => \$opt_h, "help" => \$opt_h,
49 "i" => \$opt_i, "ignore-missing" => \$opt_i,
49 "f=s" => \$opt_f, "file" => \$opt_f, 50 "f=s" => \$opt_f, "file" => \$opt_f,
50 "w=f" => \$opt_w, "warning-age=f" => \$opt_w, 51 "w=f" => \$opt_w, "warning-age=f" => \$opt_w,
51 "W=f" => \$opt_W, "warning-size=f" => \$opt_W, 52 "W=f" => \$opt_W, "warning-size=f" => \$opt_W,
@@ -71,8 +72,15 @@ if (! $opt_f) {
71 72
72# Check that file exists (can be directory or link) 73# Check that file exists (can be directory or link)
73unless (-e $opt_f) { 74unless (-e $opt_f) {
74 print "FILE_AGE CRITICAL: File not found - $opt_f\n"; 75 if ($opt_i) {
75 exit $ERRORS{'CRITICAL'}; 76 $result = 'OK';
77 print "FILE_AGE $result: $opt_f doesn't exist, but ignore-missing was set\n";
78 exit $ERRORS{$result};
79
80 } else {
81 print "FILE_AGE CRITICAL: File not found - $opt_f\n";
82 exit $ERRORS{'CRITICAL'};
83 }
76} 84}
77 85
78$st = File::stat::stat($opt_f); 86$st = File::stat::stat($opt_f);
@@ -94,7 +102,7 @@ exit $ERRORS{$result};
94 102
95sub print_usage () { 103sub print_usage () {
96 print "Usage:\n"; 104 print "Usage:\n";
97 print " $PROGNAME [-w <secs>] [-c <secs>] [-W <size>] [-C <size>] -f <file>\n"; 105 print " $PROGNAME [-w <secs>] [-c <secs>] [-W <size>] [-C <size>] [-i] -f <file>\n";
98 print " $PROGNAME [-h | --help]\n"; 106 print " $PROGNAME [-h | --help]\n";
99 print " $PROGNAME [-V | --version]\n"; 107 print " $PROGNAME [-V | --version]\n";
100} 108}
@@ -104,6 +112,7 @@ sub print_help () {
104 print "Copyright (c) 2003 Steven Grimm\n\n"; 112 print "Copyright (c) 2003 Steven Grimm\n\n";
105 print_usage(); 113 print_usage();
106 print "\n"; 114 print "\n";
115 print " -i | --ignore-missing : return OK if the file does not exist\n";
107 print " <secs> File must be no more than this many seconds old (default: warn 240 secs, crit 600)\n"; 116 print " <secs> File must be no more than this many seconds old (default: warn 240 secs, crit 600)\n";
108 print " <size> File must be at least this many bytes long (default: crit 0 bytes)\n"; 117 print " <size> File must be at least this many bytes long (default: crit 0 bytes)\n";
109 print "\n"; 118 print "\n";