summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_file_age.pl
diff options
context:
space:
mode:
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 4cdb36db..2781c2ac 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";