summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/t/check_file_age.t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts/t/check_file_age.t')
-rw-r--r--plugins-scripts/t/check_file_age.t75
1 files changed, 43 insertions, 32 deletions
diff --git a/plugins-scripts/t/check_file_age.t b/plugins-scripts/t/check_file_age.t
index 50a2e69..8b87670 100644
--- a/plugins-scripts/t/check_file_age.t
+++ b/plugins-scripts/t/check_file_age.t
@@ -5,14 +5,14 @@
5# 5#
6 6
7use strict; 7use strict;
8use Test::More tests => 17; 8use Test::More tests => 27;
9use NPTest; 9use NPTest;
10 10
11my $successOutput = '/^FILE_AGE OK: /'; 11my $successOutput = '/^FILE_AGE OK: /';
12my $warningOutput = '/^FILE_AGE WARNING: /'; 12my $warningOutput = '/^FILE_AGE WARNING: /';
13my $criticalOutput = '/^FILE_AGE CRITICAL: /'; 13my $criticalOutput = '/^FILE_AGE CRITICAL: /';
14my $unknownOutput = '/^FILE_AGE UNKNOWN: /'; 14my $unknownOutput = '/^FILE_AGE UNKNOWN: /';
15my $performanceOutput = '/ \| age=[0-9]+s;[0-9]+;[0-9]+ size=[0-9]+B;[0-9]+;[0-9]+;0$/'; 15my $performanceOutput = '/ \| age=[0-9]+s;[0-9:]+;[0-9:]+ size=[0-9]+B;[0-9:]+;[0-9:]+;0$/';
16 16
17my $result; 17my $result;
18my $temp_file = "/tmp/check_file_age.tmp"; 18my $temp_file = "/tmp/check_file_age.tmp";
@@ -20,64 +20,75 @@ my $temp_link = "/tmp/check_file_age.link.tmp";
20 20
21unlink $temp_file, $temp_link; 21unlink $temp_file, $temp_link;
22 22
23$result = NPTest->testCmd( 23$result = NPTest->testCmd("./check_file_age");
24 "./check_file_age"
25 );
26cmp_ok( $result->return_code, '==', 3, "Missing parameters" ); 24cmp_ok( $result->return_code, '==', 3, "Missing parameters" );
27like ( $result->output, $unknownOutput, "Output for unknown correct" ); 25like ( $result->output, $unknownOutput, "Output for unknown correct" );
28 26
29$result = NPTest->testCmd( 27$result = NPTest->testCmd("./check_file_age -f $temp_file");
30 "./check_file_age -f $temp_file"
31 );
32cmp_ok( $result->return_code, '==', 2, "File not exists" ); 28cmp_ok( $result->return_code, '==', 2, "File not exists" );
33like ( $result->output, $criticalOutput, "Output for file missing correct" ); 29like ( $result->output, $criticalOutput, "Output for file missing correct" );
34 30
35write_chars(100); 31write_chars(100);
36$result = NPTest->testCmd( 32$result = NPTest->testCmd("./check_file_age -f $temp_file");
37 "./check_file_age -f $temp_file"
38 );
39cmp_ok( $result->return_code, '==', 0, "File is new enough" ); 33cmp_ok( $result->return_code, '==', 0, "File is new enough" );
40like ( $result->output, $successOutput, "Output for success correct" ); 34like ( $result->output, $successOutput, "Output for success correct" );
41 35
42sleep 2; 36sleep 2;
43 37
44$result = NPTest->testCmd( 38$result = NPTest->testCmd("./check_file_age -f $temp_file -w 1");
45 "./check_file_age -f $temp_file -w 1"
46 );
47cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old" ); 39cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old" );
48like ( $result->output, $warningOutput, "Output for warning correct" ); 40like ( $result->output, $warningOutput, "Output for warning correct" );
49 41
50$result = NPTest->testCmd( 42$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1");
51 "./check_file_age -f $temp_file -c 1"
52 );
53cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" ); 43cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" );
54like ( $result->output, $criticalOutput, "Output for critical correct" ); 44like ( $result->output, $criticalOutput, "Output for critical correct" );
55 45
56$result = NPTest->testCmd( 46$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100");
57 "./check_file_age -f $temp_file -c 1000 -W 100"
58 );
59cmp_ok( $result->return_code, '==', 0, "Checking file size" ); 47cmp_ok( $result->return_code, '==', 0, "Checking file size" );
60 48
61$result = NPTest->testCmd( 49$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100");
62 "./check_file_age -f $temp_file -c 1000 -W 100"
63 );
64like( $result->output, $performanceOutput, "Checking for performance Output" ); 50like( $result->output, $performanceOutput, "Checking for performance Output" );
65 51
66$result = NPTest->testCmd( 52$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100");
67 "./check_file_age -f /non/existent --ignore-missing" 53like( $result->output, $performanceOutput, "Checking for performance Output from range" );
68 ); 54
55$result = NPTest->testCmd("./check_file_age -f /non/existent --ignore-missing");
69cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" ); 56cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" );
70 57
71$result = NPTest->testCmd( 58$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 101");
72 "./check_file_age -f $temp_file -c 1000 -W 101"
73 );
74cmp_ok( $result->return_code, '==', 1, "One byte too short" ); 59cmp_ok( $result->return_code, '==', 1, "One byte too short" );
75 60
76$result = NPTest->testCmd( 61$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 101");
77 "./check_file_age -f $temp_file -c 1000 -C 101"
78 );
79cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" ); 62cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" );
80 63
64SKIP: {
65 eval 'use Monitoring::Plugin::Range';
66 skip "Monitoring::Plugin::Range module require", 9 if $@;
67
68 $result = NPTest->testCmd("./check_file_age -f $temp_file -w 0:1");
69 cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old by range" );
70 like ( $result->output, $warningOutput, "Output for warning by range correct" );
71
72 $result = NPTest->testCmd("./check_file_age -f $temp_file -c 0:1");
73 cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old by range" );
74 like ( $result->output, $criticalOutput, "Output for critical by range correct" );
75
76 $result = NPTest->testCmd("./check_file_age -f $temp_file -c 0:1000 -W 0:100");
77 cmp_ok( $result->return_code, '==', 0, "Checking file size by range" );
78
79 $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 101:");
80 cmp_ok( $result->return_code, '==', 1, "One byte too short by range" );
81
82 $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 0:99");
83 cmp_ok( $result->return_code, '==', 1, "One byte too long by range" );
84
85 $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 101:");
86 cmp_ok( $result->return_code, '==', 2, "One byte too short by range - critical" );
87
88 $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 0:99");
89 cmp_ok( $result->return_code, '==', 2, "One byte too long by range - critical" );
90};
91
81symlink $temp_file, $temp_link or die "Cannot create symlink"; 92symlink $temp_file, $temp_link or die "Cannot create symlink";
82$result = NPTest->testCmd("./check_file_age -f $temp_link -c 10"); 93$result = NPTest->testCmd("./check_file_age -f $temp_link -c 10");
83cmp_ok( $result->return_code, '==', 0, "Works for symlinks" ); 94cmp_ok( $result->return_code, '==', 0, "Works for symlinks" );