diff options
Diffstat (limited to 'plugins-scripts/check_file_age.pl')
-rwxr-xr-x | plugins-scripts/check_file_age.pl | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/plugins-scripts/check_file_age.pl b/plugins-scripts/check_file_age.pl index 37bbe86f..e0280381 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 | ||
24 | use strict; | 23 | use strict; |
25 | use English; | 24 | use English; |
@@ -32,7 +31,7 @@ use utils qw (%ERRORS &print_revision &support); | |||
32 | sub print_help (); | 31 | sub print_help (); |
33 | sub print_usage (); | 32 | sub print_usage (); |
34 | 33 | ||
35 | my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V); | 34 | my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V, $opt_i); |
36 | my ($result, $message, $age, $size, $st); | 35 | my ($result, $message, $age, $size, $st); |
37 | 36 | ||
38 | $PROGNAME="check_file_age"; | 37 | $PROGNAME="check_file_age"; |
@@ -51,6 +50,7 @@ Getopt::Long::Configure('bundling'); | |||
51 | GetOptions( | 50 | GetOptions( |
52 | "V" => \$opt_V, "version" => \$opt_V, | 51 | "V" => \$opt_V, "version" => \$opt_V, |
53 | "h" => \$opt_h, "help" => \$opt_h, | 52 | "h" => \$opt_h, "help" => \$opt_h, |
53 | "i" => \$opt_i, "ignore-missing" => \$opt_i, | ||
54 | "f=s" => \$opt_f, "file" => \$opt_f, | 54 | "f=s" => \$opt_f, "file" => \$opt_f, |
55 | "w=f" => \$opt_w, "warning-age=f" => \$opt_w, | 55 | "w=f" => \$opt_w, "warning-age=f" => \$opt_w, |
56 | "W=f" => \$opt_W, "warning-size=f" => \$opt_W, | 56 | "W=f" => \$opt_W, "warning-size=f" => \$opt_W, |
@@ -76,8 +76,15 @@ if (! $opt_f) { | |||
76 | 76 | ||
77 | # Check that file exists (can be directory or link) | 77 | # Check that file exists (can be directory or link) |
78 | unless (-e $opt_f) { | 78 | unless (-e $opt_f) { |
79 | print "FILE_AGE CRITICAL: File not found - $opt_f\n"; | 79 | if ($opt_i) { |
80 | exit $ERRORS{'CRITICAL'}; | 80 | $result = 'OK'; |
81 | print "FILE_AGE $result: $opt_f doesn't exist, but ignore-missing was set\n"; | ||
82 | exit $ERRORS{$result}; | ||
83 | |||
84 | } else { | ||
85 | print "FILE_AGE CRITICAL: File not found - $opt_f\n"; | ||
86 | exit $ERRORS{'CRITICAL'}; | ||
87 | } | ||
81 | } | 88 | } |
82 | 89 | ||
83 | $st = File::stat::stat($opt_f); | 90 | $st = File::stat::stat($opt_f); |
@@ -99,7 +106,7 @@ exit $ERRORS{$result}; | |||
99 | 106 | ||
100 | sub print_usage () { | 107 | sub print_usage () { |
101 | print "Usage:\n"; | 108 | print "Usage:\n"; |
102 | print " $PROGNAME [-w <secs>] [-c <secs>] [-W <size>] [-C <size>] -f <file>\n"; | 109 | print " $PROGNAME [-w <secs>] [-c <secs>] [-W <size>] [-C <size>] [-i] -f <file>\n"; |
103 | print " $PROGNAME [-h | --help]\n"; | 110 | print " $PROGNAME [-h | --help]\n"; |
104 | print " $PROGNAME [-V | --version]\n"; | 111 | print " $PROGNAME [-V | --version]\n"; |
105 | } | 112 | } |
@@ -109,6 +116,7 @@ sub print_help () { | |||
109 | print "Copyright (c) 2003 Steven Grimm\n\n"; | 116 | print "Copyright (c) 2003 Steven Grimm\n\n"; |
110 | print_usage(); | 117 | print_usage(); |
111 | print "\n"; | 118 | print "\n"; |
119 | print " -i | --ignore-missing : return OK if the file does not exist\n"; | ||
112 | print " <secs> File must be no more than this many seconds old (default: warn 240 secs, crit 600)\n"; | 120 | print " <secs> File must be no more than this many seconds old (default: warn 240 secs, crit 600)\n"; |
113 | print " <size> File must be at least this many bytes long (default: crit 0 bytes)\n"; | 121 | print " <size> File must be at least this many bytes long (default: crit 0 bytes)\n"; |
114 | print "\n"; | 122 | print "\n"; |