diff options
Diffstat (limited to 'plugins-scripts')
-rwxr-xr-x | plugins-scripts/check_file_age.pl | 17 | ||||
-rw-r--r-- | plugins-scripts/t/check_file_age.t | 7 |
2 files changed, 19 insertions, 5 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); | |||
31 | sub print_help (); | 31 | sub print_help (); |
32 | sub print_usage (); | 32 | sub print_usage (); |
33 | 33 | ||
34 | 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); |
35 | my ($result, $message, $age, $size, $st); | 35 | my ($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'); | |||
46 | GetOptions( | 46 | GetOptions( |
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) |
73 | unless (-e $opt_f) { | 74 | unless (-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 | ||
95 | sub print_usage () { | 103 | sub 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"; |
diff --git a/plugins-scripts/t/check_file_age.t b/plugins-scripts/t/check_file_age.t index 384c276..a515649 100644 --- a/plugins-scripts/t/check_file_age.t +++ b/plugins-scripts/t/check_file_age.t | |||
@@ -5,7 +5,7 @@ | |||
5 | # | 5 | # |
6 | 6 | ||
7 | use strict; | 7 | use strict; |
8 | use Test::More tests => 15; | 8 | use Test::More tests => 16; |
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | my $successOutput = '/^FILE_AGE OK: /'; | 11 | my $successOutput = '/^FILE_AGE OK: /'; |
@@ -58,6 +58,11 @@ $result = NPTest->testCmd( | |||
58 | cmp_ok( $result->return_code, '==', 0, "Checking file size" ); | 58 | cmp_ok( $result->return_code, '==', 0, "Checking file size" ); |
59 | 59 | ||
60 | $result = NPTest->testCmd( | 60 | $result = NPTest->testCmd( |
61 | "./check_file_age -f /non/existent --ignore-missing" | ||
62 | ); | ||
63 | cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" ); | ||
64 | |||
65 | $result = NPTest->testCmd( | ||
61 | "./check_file_age -f $temp_file -c 1000 -W 101" | 66 | "./check_file_age -f $temp_file -c 1000 -W 101" |
62 | ); | 67 | ); |
63 | cmp_ok( $result->return_code, '==', 1, "One byte too short" ); | 68 | cmp_ok( $result->return_code, '==', 1, "One byte too short" ); |