diff options
-rw-r--r-- | NEWS | 1 | ||||
-rwxr-xr-x | plugins-scripts/check_file_age.pl | 5 | ||||
-rw-r--r-- | plugins-scripts/t/check_file_age.t | 8 |
3 files changed, 11 insertions, 3 deletions
@@ -13,6 +13,7 @@ This file documents the major additions and syntax changes between releases. | |||
13 | check_disk shows now troubled partions in verbose mode | 13 | check_disk shows now troubled partions in verbose mode |
14 | check_dig has now support for drill and dig | 14 | check_dig has now support for drill and dig |
15 | check_dig has now support for -6 option | 15 | check_dig has now support for -6 option |
16 | Add performance data to check_file_age | ||
16 | 17 | ||
17 | FIXES | 18 | FIXES |
18 | Fix check_jabber to work with Openfire servers | 19 | Fix check_jabber to work with Openfire servers |
diff --git a/plugins-scripts/check_file_age.pl b/plugins-scripts/check_file_age.pl index 453e0f5..4415fdf 100755 --- a/plugins-scripts/check_file_age.pl +++ b/plugins-scripts/check_file_age.pl | |||
@@ -34,7 +34,7 @@ sub print_help (); | |||
34 | sub print_usage (); | 34 | sub print_usage (); |
35 | 35 | ||
36 | my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V, $opt_i); | 36 | my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V, $opt_i); |
37 | my ($result, $message, $age, $size, $st); | 37 | my ($result, $message, $age, $size, $st, $perfdata); |
38 | 38 | ||
39 | $PROGNAME="check_file_age"; | 39 | $PROGNAME="check_file_age"; |
40 | 40 | ||
@@ -92,6 +92,7 @@ unless (-e $opt_f) { | |||
92 | $st = File::stat::stat($opt_f); | 92 | $st = File::stat::stat($opt_f); |
93 | $age = time - $st->mtime; | 93 | $age = time - $st->mtime; |
94 | $size = $st->size; | 94 | $size = $st->size; |
95 | $perfdata = "age=${age}s;${opt_w};${opt_c} size=${size}B;${opt_W};${opt_C};0"; | ||
95 | 96 | ||
96 | 97 | ||
97 | $result = 'OK'; | 98 | $result = 'OK'; |
@@ -103,7 +104,7 @@ elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) { | |||
103 | $result = 'WARNING'; | 104 | $result = 'WARNING'; |
104 | } | 105 | } |
105 | 106 | ||
106 | print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes\n"; | 107 | print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes | $perfdata\n"; |
107 | exit $ERRORS{$result}; | 108 | exit $ERRORS{$result}; |
108 | 109 | ||
109 | sub print_usage () { | 110 | sub print_usage () { |
diff --git a/plugins-scripts/t/check_file_age.t b/plugins-scripts/t/check_file_age.t index a515649..50a2e69 100644 --- a/plugins-scripts/t/check_file_age.t +++ b/plugins-scripts/t/check_file_age.t | |||
@@ -5,13 +5,14 @@ | |||
5 | # | 5 | # |
6 | 6 | ||
7 | use strict; | 7 | use strict; |
8 | use Test::More tests => 16; | 8 | use Test::More tests => 17; |
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | my $successOutput = '/^FILE_AGE OK: /'; | 11 | my $successOutput = '/^FILE_AGE OK: /'; |
12 | my $warningOutput = '/^FILE_AGE WARNING: /'; | 12 | my $warningOutput = '/^FILE_AGE WARNING: /'; |
13 | my $criticalOutput = '/^FILE_AGE CRITICAL: /'; | 13 | my $criticalOutput = '/^FILE_AGE CRITICAL: /'; |
14 | my $unknownOutput = '/^FILE_AGE UNKNOWN: /'; | 14 | my $unknownOutput = '/^FILE_AGE UNKNOWN: /'; |
15 | my $performanceOutput = '/ \| age=[0-9]+s;[0-9]+;[0-9]+ size=[0-9]+B;[0-9]+;[0-9]+;0$/'; | ||
15 | 16 | ||
16 | my $result; | 17 | my $result; |
17 | my $temp_file = "/tmp/check_file_age.tmp"; | 18 | my $temp_file = "/tmp/check_file_age.tmp"; |
@@ -58,6 +59,11 @@ $result = NPTest->testCmd( | |||
58 | cmp_ok( $result->return_code, '==', 0, "Checking file size" ); | 59 | cmp_ok( $result->return_code, '==', 0, "Checking file size" ); |
59 | 60 | ||
60 | $result = NPTest->testCmd( | 61 | $result = NPTest->testCmd( |
62 | "./check_file_age -f $temp_file -c 1000 -W 100" | ||
63 | ); | ||
64 | like( $result->output, $performanceOutput, "Checking for performance Output" ); | ||
65 | |||
66 | $result = NPTest->testCmd( | ||
61 | "./check_file_age -f /non/existent --ignore-missing" | 67 | "./check_file_age -f /non/existent --ignore-missing" |
62 | ); | 68 | ); |
63 | cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" ); | 69 | cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" ); |