summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/t/check_file_age.t
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.org>2017-04-20 16:28:15 +0200
committerGitHub <noreply@github.com>2017-04-20 16:28:15 +0200
commit3b86c201a77209406fc48a6ceee2a9a0b92d863c (patch)
tree18819c40dbec1d226982a252aee137c86d979ed9 /plugins-scripts/t/check_file_age.t
parent8306e76c327a1ed5cf68f1842873e40ad57b3b30 (diff)
parentd332ee1fa09f09e6025d58a99876d96d50bbf439 (diff)
downloadmonitoring-plugins-3b86c201a77209406fc48a6ceee2a9a0b92d863c.tar.gz
Merge pull request #1461 from philipowen/file-size-lessthan
Enable check_file_age to test for maximum file size
Diffstat (limited to 'plugins-scripts/t/check_file_age.t')
-rw-r--r--plugins-scripts/t/check_file_age.t46
1 files changed, 44 insertions, 2 deletions
diff --git a/plugins-scripts/t/check_file_age.t b/plugins-scripts/t/check_file_age.t
index 50a2e699..ebf673f5 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";
@@ -48,22 +48,44 @@ cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old" );
48like ( $result->output, $warningOutput, "Output for warning correct" ); 48like ( $result->output, $warningOutput, "Output for warning correct" );
49 49
50$result = NPTest->testCmd( 50$result = NPTest->testCmd(
51 "./check_file_age -f $temp_file -w 0:1"
52 );
53cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old by range" );
54like ( $result->output, $warningOutput, "Output for warning by range correct" );
55
56$result = NPTest->testCmd(
51 "./check_file_age -f $temp_file -c 1" 57 "./check_file_age -f $temp_file -c 1"
52 ); 58 );
53cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" ); 59cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" );
54like ( $result->output, $criticalOutput, "Output for critical correct" ); 60like ( $result->output, $criticalOutput, "Output for critical correct" );
55 61
56$result = NPTest->testCmd( 62$result = NPTest->testCmd(
63 "./check_file_age -f $temp_file -c 0:1"
64 );
65cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old by range" );
66like ( $result->output, $criticalOutput, "Output for critical by range correct" );
67
68$result = NPTest->testCmd(
57 "./check_file_age -f $temp_file -c 1000 -W 100" 69 "./check_file_age -f $temp_file -c 1000 -W 100"
58 ); 70 );
59cmp_ok( $result->return_code, '==', 0, "Checking file size" ); 71cmp_ok( $result->return_code, '==', 0, "Checking file size" );
60 72
61$result = NPTest->testCmd( 73$result = NPTest->testCmd(
74 "./check_file_age -f $temp_file -c 0:1000 -W 0:100"
75 );
76cmp_ok( $result->return_code, '==', 0, "Checking file size by range" );
77
78$result = NPTest->testCmd(
62 "./check_file_age -f $temp_file -c 1000 -W 100" 79 "./check_file_age -f $temp_file -c 1000 -W 100"
63 ); 80 );
64like( $result->output, $performanceOutput, "Checking for performance Output" ); 81like( $result->output, $performanceOutput, "Checking for performance Output" );
65 82
66$result = NPTest->testCmd( 83$result = NPTest->testCmd(
84 "./check_file_age -f $temp_file -c 1000 -W 100"
85 );
86like( $result->output, $performanceOutput, "Checking for performance Output from range" );
87
88$result = NPTest->testCmd(
67 "./check_file_age -f /non/existent --ignore-missing" 89 "./check_file_age -f /non/existent --ignore-missing"
68 ); 90 );
69cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" ); 91cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" );
@@ -74,10 +96,30 @@ $result = NPTest->testCmd(
74cmp_ok( $result->return_code, '==', 1, "One byte too short" ); 96cmp_ok( $result->return_code, '==', 1, "One byte too short" );
75 97
76$result = NPTest->testCmd( 98$result = NPTest->testCmd(
99 "./check_file_age -f $temp_file -c 1000 -W 101:"
100 );
101cmp_ok( $result->return_code, '==', 1, "One byte too short by range" );
102
103$result = NPTest->testCmd(
77 "./check_file_age -f $temp_file -c 1000 -C 101" 104 "./check_file_age -f $temp_file -c 1000 -C 101"
78 ); 105 );
79cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" ); 106cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" );
80 107
108$result = NPTest->testCmd(
109 "./check_file_age -f $temp_file -c 1000 -C 101:"
110 );
111cmp_ok( $result->return_code, '==', 2, "One byte too short by range - critical" );
112
113$result = NPTest->testCmd(
114 "./check_file_age -f $temp_file -c 1000 -W 0:99"
115 );
116cmp_ok( $result->return_code, '==', 1, "One byte too long by range" );
117
118$result = NPTest->testCmd(
119 "./check_file_age -f $temp_file -c 1000 -C 0:99"
120 );
121cmp_ok( $result->return_code, '==', 2, "One byte too long by range - critical" );
122
81symlink $temp_file, $temp_link or die "Cannot create symlink"; 123symlink $temp_file, $temp_link or die "Cannot create symlink";
82$result = NPTest->testCmd("./check_file_age -f $temp_link -c 10"); 124$result = NPTest->testCmd("./check_file_age -f $temp_link -c 10");
83cmp_ok( $result->return_code, '==', 0, "Works for symlinks" ); 125cmp_ok( $result->return_code, '==', 0, "Works for symlinks" );