summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/t/check_disk.t164
1 files changed, 113 insertions, 51 deletions
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index be267f6..d35d02c 100644
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -6,7 +6,7 @@
6# 6#
7 7
8use strict; 8use strict;
9use Test::More tests => 24; 9use Test::More tests => 26;
10use NPTest; 10use NPTest;
11use POSIX qw(ceil floor); 11use POSIX qw(ceil floor);
12 12
@@ -22,61 +22,98 @@ my $mountpoint_valid = getTestParameter( "mountpoint_valid", "NP_MOUNTPOINT_
22my $mountpoint2_valid = getTestParameter( "mountpoint2_valid", "NP_MOUNTPOINT2_VALID", "/var", 22my $mountpoint2_valid = getTestParameter( "mountpoint2_valid", "NP_MOUNTPOINT2_VALID", "/var",
23 "The path to another valid mountpoint. Must be different from 1st one." ); 23 "The path to another valid mountpoint. Must be different from 1st one." );
24 24
25my $free_regex = '^DISK OK - free space: '.$mountpoint_valid.' .* MB \((\d+)%[\)]*\); '.$mountpoint2_valid.' .* MB \((\d+)%[\)]*\);|';
26 25
27$result = NPTest->testCmd( "./check_disk 100 100 ".${mountpoint_valid} ); # 100 free 26$result = NPTest->testCmd(
28cmp_ok( $result->return_code, "==", 0, "At least 100 free" ); 27 "./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -p $mountpoint2_valid"
29like( $result->output, $successOutput, "Right output" ); 28 );
30 29cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free)");
31$result = NPTest->testCmd( "./check_disk -w 0 -c 0 ".${mountpoint_valid} ); # 0 free 30my $c = 0;
32cmp_ok( $result->return_code, "==", 0, "At least 0 free" ); 31$_ = $result->output;
33like( $result->output, $successOutput, "Right output" ); 32$c++ while /\(/g; # counts number of "(" - should be two
34 33cmp_ok( $c, '==', 2, "Got two mountpoints in output");
35$result = NPTest->testCmd( "./check_disk -w 1% -c 1% ".${mountpoint_valid} ); # 1% free 34
36cmp_ok( $result->return_code, "==", 0, "At least 1% free" ); 35# Calculate avg_free free on mountpoint1 and mountpoint2
37like( $result->output, $successOutput, "Right output" ); 36# because if you check in the middle, you should get different errors
38 37$_ = $result->output;
39$result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p ".${mountpoint_valid}." -w 1% -c 1% -p ".$mountpoint2_valid ); # MP1 1% free MP2 100% free 38my ($free_on_mp1, $free_on_mp2) = (m/\((\d+)%.*\((\d+)%/);
40cmp_ok( $result->return_code, "==", 0, "At least 1% free on mountpoint_1, 1% free on mountpoint_2" ); 39die "Cannot parse output: $_" unless ($free_on_mp1 && $free_on_mp2);
41like( $result->output, $successOutput, "Right output" ); 40my $avg_free = ceil(($free_on_mp1+$free_on_mp2)/2);
42 41my ($more_free, $less_free);
43# Get free diskspace on NP_MOUNTPOINT_VALID and NP_MOUNTPOINT2_VALID
44my $free_space_output = $result->output;
45#$free_space_output =~ m/$free_regex/;
46my ($free_on_mp1, $free_on_mp2) = ($free_space_output =~ m/\((\d+)%.*\((\d+)%/);
47die "Cannot read free_on_mp1" unless $free_on_mp1;
48die "Cannot read free_on_mp2" unless $free_on_mp2;
49my $average = ceil(($free_on_mp1+$free_on_mp2)/2);
50my ($larger, $smaller);
51if ($free_on_mp1 > $free_on_mp2) { 42if ($free_on_mp1 > $free_on_mp2) {
52 $larger = $mountpoint_valid; 43 $more_free = $mountpoint_valid;
53 $smaller = $mountpoint2_valid; 44 $less_free = $mountpoint2_valid;
45} elsif ($free_on_mp1 < $free_on_mp2) {
46 $more_free = $mountpoint2_valid;
47 $less_free = $mountpoint_valid;
54} else { 48} else {
55 $larger = $mountpoint2_valid; 49 die "Two mountpoints are the same - cannot do rest of test";
56 $smaller = $mountpoint_valid;
57} 50}
58 51
59$result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p ".${larger}." -w 100% -c 100% -p ".$smaller ); # MP1 1% free MP2 100% free
60cmp_ok( $result->return_code, "==", 2, "At least 1% free on $larger, 100% free on $smaller" );
61like( $result->output, $failureOutput, "Right output" );
62 52
63$result = NPTest->testCmd( "./check_disk -w ".$average."% -c 0% -p ".${larger}." -w ".$average."% -c ".$average."% -p ".${smaller} ); # Average free 53$result = NPTest->testCmd( "./check_disk -w 100 -c 100 -p $more_free" );
64cmp_ok( $result->return_code, "==", 2, "At least ".$average."% free on $larger" ); 54cmp_ok( $result->return_code, '==', 0, "At least 100 bytes available on $more_free");
55like ( $result->output, $successOutput, "OK output" );
56
57$result = NPTest->testCmd( "./check_disk 100 100 $more_free" );
58cmp_ok( $result->return_code, '==', 0, "Old syntax okay" );
59
60$result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p $more_free" );
61cmp_ok( $result->return_code, "==", 0, "At least 1% free" );
62
63$result = NPTest->testCmd(
64 "./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free"
65 );
66cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $less_free" );
65like( $result->output, $failureOutput, "Right output" ); 67like( $result->output, $failureOutput, "Right output" );
66 68
67$result = NPTest->testCmd( "./check_disk -w ".$average."% -c ".$average."% -p ".${larger}." -w ".$average."% -c 0% -p ".${smaller} ); # Average free 69
68cmp_ok( $result->return_code, "==", 1, "At least ".$average."% free on $smaller" ); 70
69like( $result->output, $warningOutput, "Right output" ); 71
72$result = NPTest->testCmd(
73 "./check_disk -w $avg_free% -c 0% -p $less_free"
74 );
75cmp_ok( $result->return_code, '==', 1, "Get warning on less_free mountpoint, when checking avg_free");
76
77$result = NPTest->testCmd(
78 "./check_disk -w $avg_free% -c $avg_free% -p $more_free"
79 );
80cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, when checking avg_free");
81
82$result = NPTest->testCmd(
83 "./check_disk -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free"
84 );
85cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning");
86
87
88
89$result = NPTest->testCmd(
90 "./check_disk -w $avg_free% -c 0% -p $more_free"
91 );
92cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, checking avg_free");
93
94$result = NPTest->testCmd(
95 "./check_disk -w $avg_free% -c $avg_free% -p $less_free"
96 );
97cmp_ok( $result->return_code, '==', 2, "Get critical on less_free, checking avg_free");
98
99$result = NPTest->testCmd(
100 "./check_disk -w $avg_free% -c 0% -p $more_free -w $avg_free% -c $avg_free% -p $less_free"
101 );
102cmp_ok( $result->return_code, '==', 2, "Combining above two tests, get critical");
103
104
105
106$result = NPTest->testCmd(
107 "./check_disk -w 10% -c 15% -p $mountpoint_valid"
108 );
109cmp_ok( $result->return_code, '==', 3, "Invalid command line options" );
70 110
71TODO: { 111TODO: {
72 local $TODO = "We have a bug in check_disk - -p must come after -w and -c"; 112 local $TODO = "-p must come after -w and -c";
73 $result = NPTest->testCmd( "./check_disk -p ".${mountpoint_valid}." -w ".$average."% -c 0% -p ".${mountpoint_valid}." -w ".$average."% -c ".$average."%" ); # Average free 113 $result = NPTest->testCmd(
74 cmp_ok( $result->return_code, "==", 2, "At least ".$average."% free on mountpoint_1" ); 114 "./check_disk -p $mountpoint_valid -w 10% -c 15%"
75 like( $result->output, $failureOutput, "Right output" ); 115 );
76 116 cmp_ok( $result->return_code, "==", 3, "Invalid options - order unimportant" );
77 $result = NPTest->testCmd( "./check_disk -p ".${mountpoint_valid}." -w ".$average."% -c ".$average."% -p ".${mountpoint_valid}." -w ".$average."% -c 0%" ); # Average free
78 cmp_ok( $result->return_code, "==", 1, "At least ".$average."% free on mountpoint_2" );
79 like( $result->output, $warningOutput, "Right output" );
80} 117}
81 118
82$result = NPTest->testCmd( "./check_disk -w 100% -c 100% ".${mountpoint_valid} ); # 100% empty 119$result = NPTest->testCmd( "./check_disk -w 100% -c 100% ".${mountpoint_valid} ); # 100% empty
@@ -84,12 +121,37 @@ cmp_ok( $result->return_code, "==", 2, "100% empty" );
84like( $result->output, $failureOutput, "Right output" ); 121like( $result->output, $failureOutput, "Right output" );
85 122
86TODO: { 123TODO: {
87 local $TODO = "-u GB sometimes does not work?"; 124 local $TODO = "Requesting 100GB free is should be critical";
125 $result = NPTest->testCmd( "./check_disk -w 100000 -c 100000 $mountpoint_valid" );
126 cmp_ok( $result->return_code, '==', 2, "Check for 100GB free" );
127}
128
129TODO: {
130 local $TODO = "-u GB does not work";
88 $result = NPTest->testCmd( "./check_disk -w 100 -c 100 -u GB ".${mountpoint_valid} ); # 100 GB empty 131 $result = NPTest->testCmd( "./check_disk -w 100 -c 100 -u GB ".${mountpoint_valid} ); # 100 GB empty
89 cmp_ok( $result->return_code, "==", 2, "100 GB empty" ); 132 cmp_ok( $result->return_code, "==", 2, "100 GB empty" );
90 like( $result->output, $failureOutput, "Right output" );
91} 133}
92 134
93$result = NPTest->testCmd( "./check_disk 0 0 ".${mountpoint_valid} ); # 0 critical 135
94cmp_ok( $result->return_code, "==", 2, "No empty space" ); 136# Checking old syntax of check_disk warn crit [fs], with warn/crit at USED% thresholds
95like( $result->output, $failureOutput, "Right output" ); 137$result = NPTest->testCmd( "./check_disk 0 0 ".${mountpoint_valid} );
138cmp_ok( $result->return_code, "==", 2, "Old syntax: 0% used");
139
140$result = NPTest->testCmd( "./check_disk 100 100 $mountpoint_valid" );
141cmp_ok( $result->return_code, '==', 0, "Old syntax: 100% used" );
142
143$result = NPTest->testCmd( "./check_disk 0 100 $mountpoint_valid" );
144cmp_ok( $result->return_code, '==', 1, "Old syntax: warn 0% used" );
145
146$result = NPTest->testCmd( "./check_disk 0 200 $mountpoint_valid" );
147cmp_ok( $result->return_code, '==', 3, "Old syntax: Error with values outside percent range" );
148
149TODO: {
150 local $TODO = "Need to properly check input";
151 $result = NPTest->testCmd( "./check_disk 200 200 $mountpoint_valid" );
152 cmp_ok( $result->return_code, '==', 3, "Old syntax: Error with values outside percent range" );
153}
154
155$result = NPTest->testCmd( "./check_disk 200 0 $mountpoint_valid" );
156cmp_ok( $result->return_code, '==', 3, "Old syntax: Error with values outside percent range" );
157