aboutsummaryrefslogtreecommitdiff
path: root/plugins-scripts/t
diff options
context:
space:
mode:
authorGravatar Sven Nierlein <sven@nierlein.org> 2017-04-20 16:28:15 +0200
committerGravatar GitHub <noreply@github.com> 2017-04-20 16:28:15 +0200
commit3b86c201a77209406fc48a6ceee2a9a0b92d863c (patch)
tree18819c40dbec1d226982a252aee137c86d979ed9 /plugins-scripts/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')
-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 @@
#
use strict;
-use Test::More tests => 17;
+use Test::More tests => 27;
use NPTest;
my $successOutput = '/^FILE_AGE OK: /';
my $warningOutput = '/^FILE_AGE WARNING: /';
my $criticalOutput = '/^FILE_AGE CRITICAL: /';
my $unknownOutput = '/^FILE_AGE UNKNOWN: /';
-my $performanceOutput = '/ \| age=[0-9]+s;[0-9]+;[0-9]+ size=[0-9]+B;[0-9]+;[0-9]+;0$/';
+my $performanceOutput = '/ \| age=[0-9]+s;[0-9:]+;[0-9:]+ size=[0-9]+B;[0-9:]+;[0-9:]+;0$/';
my $result;
my $temp_file = "/tmp/check_file_age.tmp";
@@ -48,22 +48,44 @@ cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old" );
like ( $result->output, $warningOutput, "Output for warning correct" );
$result = NPTest->testCmd(
+ "./check_file_age -f $temp_file -w 0:1"
+ );
+cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old by range" );
+like ( $result->output, $warningOutput, "Output for warning by range correct" );
+
+$result = NPTest->testCmd(
"./check_file_age -f $temp_file -c 1"
);
cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" );
like ( $result->output, $criticalOutput, "Output for critical correct" );
$result = NPTest->testCmd(
+ "./check_file_age -f $temp_file -c 0:1"
+ );
+cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old by range" );
+like ( $result->output, $criticalOutput, "Output for critical by range correct" );
+
+$result = NPTest->testCmd(
"./check_file_age -f $temp_file -c 1000 -W 100"
);
cmp_ok( $result->return_code, '==', 0, "Checking file size" );
$result = NPTest->testCmd(
+ "./check_file_age -f $temp_file -c 0:1000 -W 0:100"
+ );
+cmp_ok( $result->return_code, '==', 0, "Checking file size by range" );
+
+$result = NPTest->testCmd(
"./check_file_age -f $temp_file -c 1000 -W 100"
);
like( $result->output, $performanceOutput, "Checking for performance Output" );
$result = NPTest->testCmd(
+ "./check_file_age -f $temp_file -c 1000 -W 100"
+ );
+like( $result->output, $performanceOutput, "Checking for performance Output from range" );
+
+$result = NPTest->testCmd(
"./check_file_age -f /non/existent --ignore-missing"
);
cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" );
@@ -74,10 +96,30 @@ $result = NPTest->testCmd(
cmp_ok( $result->return_code, '==', 1, "One byte too short" );
$result = NPTest->testCmd(
+ "./check_file_age -f $temp_file -c 1000 -W 101:"
+ );
+cmp_ok( $result->return_code, '==', 1, "One byte too short by range" );
+
+$result = NPTest->testCmd(
"./check_file_age -f $temp_file -c 1000 -C 101"
);
cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" );
+$result = NPTest->testCmd(
+ "./check_file_age -f $temp_file -c 1000 -C 101:"
+ );
+cmp_ok( $result->return_code, '==', 2, "One byte too short by range - critical" );
+
+$result = NPTest->testCmd(
+ "./check_file_age -f $temp_file -c 1000 -W 0:99"
+ );
+cmp_ok( $result->return_code, '==', 1, "One byte too long by range" );
+
+$result = NPTest->testCmd(
+ "./check_file_age -f $temp_file -c 1000 -C 0:99"
+ );
+cmp_ok( $result->return_code, '==', 2, "One byte too long by range - critical" );
+
symlink $temp_file, $temp_link or die "Cannot create symlink";
$result = NPTest->testCmd("./check_file_age -f $temp_link -c 10");
cmp_ok( $result->return_code, '==', 0, "Works for symlinks" );