3 # check_file_age.pl Copyright (C) 2003 Steven Grimm <koreth-nagios@midwinter.com>
5 # Checks a file's size and modification time to make sure it's not empty
6 # and that it's sufficiently recent.
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty
16 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
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
21 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 # Boston, MA 02111-1307, USA
28 use vars
qw($PROGNAME);
30 use utils qw (%ERRORS &print_revision &support);
35 my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V);
36 my ($result, $message, $age, $size, $st);
38 $PROGNAME="check_file_age";
46 Getopt::Long::Configure('bundling');
48 "V" => \$opt_V, "version" => \$opt_V,
49 "h" => \$opt_h, "help" => \$opt_h,
50 "f=s" => \$opt_f, "file" => \$opt_f,
51 "w=f" => \$opt_w, "warning-age=f" => \$opt_w,
52 "W=f" => \$opt_W, "warning-size=f" => \$opt_W,
53 "c=f" => \$opt_c, "critical-age=f" => \$opt_c,
54 "C=f" => \$opt_C, "critical-size=f" => \$opt_C);
57 print_revision($PROGNAME, '@NP_VERSION@');
66 $opt_f = shift unless ($opt_f);
69 print "FILE_AGE UNKNOWN: No file specified\n";
70 exit $ERRORS{'UNKNOWN'};
73 # Check that file exists (can be directory or link)
75 print "FILE_AGE CRITICAL: File not found - $opt_f\n";
76 exit $ERRORS{'CRITICAL'};
79 $st = File::stat::stat($opt_f);
80 $age = time - $st->mtime;
86 if (($opt_c and $age > $opt_c) or ($opt_C and $size < $opt_C)) {
89 elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) {
93 print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes\n";
94 exit $ERRORS{$result};
98 print " $PROGNAME [-w <secs>] [-c <secs>] [-W <size>] [-C <size>] -f <file>\n";
99 print " $PROGNAME [-h | --help]\n";
100 print " $PROGNAME [-V | --version]\n";
104 print_revision($PROGNAME, '@NP_VERSION@');
105 print "Copyright (c) 2003 Steven Grimm\n\n";
108 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";