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.pl22
1 files changed, 15 insertions, 7 deletions
diff --git a/plugins-scripts/check_file_age.pl b/plugins-scripts/check_file_age.pl
index dcd5efa..2781c2a 100755
--- a/plugins-scripts/check_file_age.pl
+++ b/plugins-scripts/check_file_age.pl
@@ -17,9 +17,8 @@
17# GNU General Public License for more details. 17# GNU General Public License for more details.
18# 18#
19# you should have received a copy of the GNU General Public License 19# you should have received a copy of the GNU General Public License
20# along with this program (or with Nagios); if not, write to the 20# along with this program if not, write to the Free Software Foundation,
21# Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22# Boston, MA 02111-1307, USA
23 22
24use strict; 23use strict;
25use English; 24use English;
@@ -32,7 +31,7 @@ use utils qw (%ERRORS &print_revision &support);
32sub print_help (); 31sub print_help ();
33sub print_usage (); 32sub print_usage ();
34 33
35my ($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);
36my ($result, $message, $age, $size, $st); 35my ($result, $message, $age, $size, $st);
37 36
38$PROGNAME="check_file_age"; 37$PROGNAME="check_file_age";
@@ -47,6 +46,7 @@ Getopt::Long::Configure('bundling');
47GetOptions( 46GetOptions(
48 "V" => \$opt_V, "version" => \$opt_V, 47 "V" => \$opt_V, "version" => \$opt_V,
49 "h" => \$opt_h, "help" => \$opt_h, 48 "h" => \$opt_h, "help" => \$opt_h,
49 "i" => \$opt_i, "ignore-missing" => \$opt_i,
50 "f=s" => \$opt_f, "file" => \$opt_f, 50 "f=s" => \$opt_f, "file" => \$opt_f,
51 "w=f" => \$opt_w, "warning-age=f" => \$opt_w, 51 "w=f" => \$opt_w, "warning-age=f" => \$opt_w,
52 "W=f" => \$opt_W, "warning-size=f" => \$opt_W, 52 "W=f" => \$opt_W, "warning-size=f" => \$opt_W,
@@ -72,8 +72,15 @@ if (! $opt_f) {
72 72
73# Check that file exists (can be directory or link) 73# Check that file exists (can be directory or link)
74unless (-e $opt_f) { 74unless (-e $opt_f) {
75 print "FILE_AGE CRITICAL: File not found - $opt_f\n"; 75 if ($opt_i) {
76 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 }
77} 84}
78 85
79$st = File::stat::stat($opt_f); 86$st = File::stat::stat($opt_f);
@@ -95,7 +102,7 @@ exit $ERRORS{$result};
95 102
96sub print_usage () { 103sub print_usage () {
97 print "Usage:\n"; 104 print "Usage:\n";
98 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";
99 print " $PROGNAME [-h | --help]\n"; 106 print " $PROGNAME [-h | --help]\n";
100 print " $PROGNAME [-V | --version]\n"; 107 print " $PROGNAME [-V | --version]\n";
101} 108}
@@ -105,6 +112,7 @@ sub print_help () {
105 print "Copyright (c) 2003 Steven Grimm\n\n"; 112 print "Copyright (c) 2003 Steven Grimm\n\n";
106 print_usage(); 113 print_usage();
107 print "\n"; 114 print "\n";
115 print " -i | --ignore-missing : return OK if the file does not exist\n";
108 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";
109 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";
110 print "\n"; 118 print "\n";