diff options
Diffstat (limited to 'web/attachments/169141-check_file_age.pl.patch')
-rw-r--r-- | web/attachments/169141-check_file_age.pl.patch | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/web/attachments/169141-check_file_age.pl.patch b/web/attachments/169141-check_file_age.pl.patch new file mode 100644 index 0000000..857e11c --- /dev/null +++ b/web/attachments/169141-check_file_age.pl.patch | |||
@@ -0,0 +1,101 @@ | |||
1 | diff -r -U1 nagios-plugins-HEAD-200602280052-orig/plugins-scripts/check_file_age.pl nagios-plugins-HEAD-200602280052/plugins-scripts/check_file_age.pl | ||
2 | --- nagios-plugins-HEAD-200602280052-orig/plugins-scripts/check_file_age.pl 2005-12-15 16:17:49.000000000 +0100 | ||
3 | +++ nagios-plugins-HEAD-200602280052/plugins-scripts/check_file_age.pl 2006-02-28 12:10:21.000000000 +0100 | ||
4 | @@ -35,4 +35,4 @@ | ||
5 | |||
6 | -my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V); | ||
7 | -my ($result, $message, $age, $size, $st); | ||
8 | +my ($opt_c, $opt_f, $opt_d, $opt_n, $opt_w, $opt_r, $opt_C, $opt_W, $opt_h, $opt_V); | ||
9 | +my ($result, $message, $age, $size, $st, @files, @failed, $file); | ||
10 | |||
11 | @@ -45,2 +45,5 @@ | ||
12 | $opt_f = ""; | ||
13 | +$opt_n = 1; | ||
14 | +$opt_d = ""; | ||
15 | +$opt_r = ""; | ||
16 | |||
17 | @@ -50,3 +53,6 @@ | ||
18 | "h" => \$opt_h, "help" => \$opt_h, | ||
19 | + "d" => \$opt_d, "dir-content" => \$opt_d, | ||
20 | "f=s" => \$opt_f, "file" => \$opt_f, | ||
21 | + "n=i" => \$opt_n, "num-files=i" => \$opt_n, | ||
22 | + "r=s" => \$opt_r, "regexp=s" => \$opt_r, | ||
23 | "w=f" => \$opt_w, "warning-age=f" => \$opt_w, | ||
24 | @@ -79,17 +85,54 @@ | ||
25 | |||
26 | -$st = File::stat::stat($opt_f); | ||
27 | -$age = time - $st->mtime; | ||
28 | -$size = $st->size; | ||
29 | - | ||
30 | +if ($opt_d) { | ||
31 | + if (!opendir(DIR, $opt_f)) { | ||
32 | + print "FILE_AGE CRITICAL: $opt_f: $!"; | ||
33 | + exit $ERRORS{'CRITICAL'}; | ||
34 | + } | ||
35 | + # remove . and .. and filter regular expression | ||
36 | + @files = grep { !/^\.{1,2}$/ } grep { /$opt_r/ } readdir(DIR); | ||
37 | + # print "@files"; | ||
38 | + closedir(DIR); | ||
39 | +} else { | ||
40 | + @files = ($opt_f); | ||
41 | +} | ||
42 | + | ||
43 | +my $crit = 0; | ||
44 | +my $warn = 0; | ||
45 | +foreach $file (@files) { | ||
46 | + if ($opt_d) { | ||
47 | + $file = "$opt_f/$file"; | ||
48 | + } | ||
49 | + $st = File::stat::stat("$file"); | ||
50 | + $age = time - $st->mtime; | ||
51 | + $size = $st->size; | ||
52 | + | ||
53 | + if (($opt_c and $age > $opt_c) or ($opt_C and $size < $opt_C)) { | ||
54 | + push (@failed,$file); | ||
55 | + $crit++; | ||
56 | + } | ||
57 | + elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) { | ||
58 | + push (@failed,$file); | ||
59 | + $warn++; | ||
60 | + } | ||
61 | +} | ||
62 | + | ||
63 | +# return maximum RC if the sum of nOK files exceeds $opt_n | ||
64 | +if ($warn + $crit >= $opt_n) { | ||
65 | + if ($crit > 0 ) { | ||
66 | + $result = 'CRITICAL'; | ||
67 | + } else { | ||
68 | + $result = 'WARNING'; | ||
69 | + } | ||
70 | +} else { | ||
71 | + $result = 'OK'; | ||
72 | +} | ||
73 | |||
74 | -$result = 'OK'; | ||
75 | |||
76 | -if (($opt_c and $age > $opt_c) or ($opt_C and $size < $opt_C)) { | ||
77 | - $result = 'CRITICAL'; | ||
78 | +if ( ! $opt_d ) { | ||
79 | + print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes\n"; | ||
80 | +} else { | ||
81 | + my $failed = @failed; | ||
82 | + print "FILE_AGE $result: @failed " . $failed ." files older/smaller than threshold thres: $opt_n\n"; | ||
83 | } | ||
84 | -elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) { | ||
85 | - $result = 'WARNING'; | ||
86 | -} | ||
87 | - | ||
88 | -print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes\n"; | ||
89 | + | ||
90 | exit $ERRORS{$result}; | ||
91 | @@ -98,3 +141,3 @@ | ||
92 | print "Usage:\n"; | ||
93 | - print " $PROGNAME [-w <secs>] [-c <secs>] [-W <size>] [-C <size>] -f <file>\n"; | ||
94 | + print " $PROGNAME [-w <secs>] [-c <secs>] [-W <size>] [-C <size>] [-d [-r <regexp>] [-n <num>] -f <file>\n"; | ||
95 | print " $PROGNAME [-h | --help]\n"; | ||
96 | @@ -110,2 +153,5 @@ | ||
97 | print " <size> File must be at least this many bytes long (default: crit 0 bytes)\n"; | ||
98 | + print " -d check all files in <file> (if <file> is a directory)\n"; | ||
99 | + print " -r only check files maching regular expression in directory (only if -d is given)\n"; | ||
100 | + print " -n minimum number of files that have to be crit/warn to reach non OK state\n"; | ||
101 | print "\n"; | ||