diff options
Diffstat (limited to 'plugins-scripts/check_file_age.pl')
-rwxr-xr-x | plugins-scripts/check_file_age.pl | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/plugins-scripts/check_file_age.pl b/plugins-scripts/check_file_age.pl index dcd5efab..ae25201e 100755 --- a/plugins-scripts/check_file_age.pl +++ b/plugins-scripts/check_file_age.pl | |||
@@ -1,4 +1,4 @@ | |||
1 | #!/bin/perl -w | 1 | #!@PERL@ -w |
2 | 2 | ||
3 | # check_file_age.pl Copyright (C) 2003 Steven Grimm <koreth-nagios@midwinter.com> | 3 | # check_file_age.pl Copyright (C) 2003 Steven Grimm <koreth-nagios@midwinter.com> |
4 | # | 4 | # |
@@ -17,26 +17,30 @@ | |||
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; |
26 | use Getopt::Long; | 25 | use Getopt::Long; |
27 | use File::stat; | 26 | use File::stat; |
28 | use vars qw($PROGNAME); | 27 | use vars qw($PROGNAME); |
29 | use lib "."; | 28 | use FindBin; |
29 | use lib "$FindBin::Bin"; | ||
30 | use utils qw (%ERRORS &print_revision &support); | 30 | use utils qw (%ERRORS &print_revision &support); |
31 | 31 | ||
32 | sub print_help (); | 32 | sub print_help (); |
33 | sub print_usage (); | 33 | sub print_usage (); |
34 | 34 | ||
35 | my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V); | 35 | my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V, $opt_i); |
36 | my ($result, $message, $age, $size, $st); | 36 | my ($result, $message, $age, $size, $st); |
37 | 37 | ||
38 | $PROGNAME="check_file_age"; | 38 | $PROGNAME="check_file_age"; |
39 | 39 | ||
40 | $ENV{'PATH'}='@TRUSTED_PATH@'; | ||
41 | $ENV{'BASH_ENV'}=''; | ||
42 | $ENV{'ENV'}=''; | ||
43 | |||
40 | $opt_w = 240; | 44 | $opt_w = 240; |
41 | $opt_c = 600; | 45 | $opt_c = 600; |
42 | $opt_W = 0; | 46 | $opt_W = 0; |
@@ -47,6 +51,7 @@ Getopt::Long::Configure('bundling'); | |||
47 | GetOptions( | 51 | GetOptions( |
48 | "V" => \$opt_V, "version" => \$opt_V, | 52 | "V" => \$opt_V, "version" => \$opt_V, |
49 | "h" => \$opt_h, "help" => \$opt_h, | 53 | "h" => \$opt_h, "help" => \$opt_h, |
54 | "i" => \$opt_i, "ignore-missing" => \$opt_i, | ||
50 | "f=s" => \$opt_f, "file" => \$opt_f, | 55 | "f=s" => \$opt_f, "file" => \$opt_f, |
51 | "w=f" => \$opt_w, "warning-age=f" => \$opt_w, | 56 | "w=f" => \$opt_w, "warning-age=f" => \$opt_w, |
52 | "W=f" => \$opt_W, "warning-size=f" => \$opt_W, | 57 | "W=f" => \$opt_W, "warning-size=f" => \$opt_W, |
@@ -72,8 +77,15 @@ if (! $opt_f) { | |||
72 | 77 | ||
73 | # Check that file exists (can be directory or link) | 78 | # Check that file exists (can be directory or link) |
74 | unless (-e $opt_f) { | 79 | unless (-e $opt_f) { |
75 | print "FILE_AGE CRITICAL: File not found - $opt_f\n"; | 80 | if ($opt_i) { |
76 | exit $ERRORS{'CRITICAL'}; | 81 | $result = 'OK'; |
82 | print "FILE_AGE $result: $opt_f doesn't exist, but ignore-missing was set\n"; | ||
83 | exit $ERRORS{$result}; | ||
84 | |||
85 | } else { | ||
86 | print "FILE_AGE CRITICAL: File not found - $opt_f\n"; | ||
87 | exit $ERRORS{'CRITICAL'}; | ||
88 | } | ||
77 | } | 89 | } |
78 | 90 | ||
79 | $st = File::stat::stat($opt_f); | 91 | $st = File::stat::stat($opt_f); |
@@ -95,7 +107,7 @@ exit $ERRORS{$result}; | |||
95 | 107 | ||
96 | sub print_usage () { | 108 | sub print_usage () { |
97 | print "Usage:\n"; | 109 | print "Usage:\n"; |
98 | print " $PROGNAME [-w <secs>] [-c <secs>] [-W <size>] [-C <size>] -f <file>\n"; | 110 | print " $PROGNAME [-w <secs>] [-c <secs>] [-W <size>] [-C <size>] [-i] -f <file>\n"; |
99 | print " $PROGNAME [-h | --help]\n"; | 111 | print " $PROGNAME [-h | --help]\n"; |
100 | print " $PROGNAME [-V | --version]\n"; | 112 | print " $PROGNAME [-V | --version]\n"; |
101 | } | 113 | } |
@@ -105,6 +117,7 @@ sub print_help () { | |||
105 | print "Copyright (c) 2003 Steven Grimm\n\n"; | 117 | print "Copyright (c) 2003 Steven Grimm\n\n"; |
106 | print_usage(); | 118 | print_usage(); |
107 | print "\n"; | 119 | print "\n"; |
120 | 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"; | 121 | 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"; | 122 | print " <size> File must be at least this many bytes long (default: crit 0 bytes)\n"; |
110 | print "\n"; | 123 | print "\n"; |