diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2005-11-15 16:26:42 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2005-11-15 16:26:42 +0000 |
commit | 5c76cc6d172c76a6c28542ef37ece3b808df7d08 (patch) | |
tree | 8bbd97a58c68f5111197ed02b0dec47df36e6cb1 | |
parent | 2f6a959999bfe377d9752f64a7543413f948adb6 (diff) | |
download | monitoring-plugins-5c76cc6d172c76a6c28542ef37ece3b808df7d08.tar.gz |
Updated tests to minimise false positives. Breaking down so more obvious
what the tests are doing
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1285 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r-- | plugins/t/check_disk.t | 164 |
1 files changed, 113 insertions, 51 deletions
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index be267f69..d35d02c9 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t | |||
@@ -6,7 +6,7 @@ | |||
6 | # | 6 | # |
7 | 7 | ||
8 | use strict; | 8 | use strict; |
9 | use Test::More tests => 24; | 9 | use Test::More tests => 26; |
10 | use NPTest; | 10 | use NPTest; |
11 | use POSIX qw(ceil floor); | 11 | use POSIX qw(ceil floor); |
12 | 12 | ||
@@ -22,61 +22,98 @@ my $mountpoint_valid = getTestParameter( "mountpoint_valid", "NP_MOUNTPOINT_ | |||
22 | my $mountpoint2_valid = getTestParameter( "mountpoint2_valid", "NP_MOUNTPOINT2_VALID", "/var", | 22 | my $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 | ||
25 | my $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( |
28 | cmp_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" |
29 | like( $result->output, $successOutput, "Right output" ); | 28 | ); |
30 | 29 | cmp_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 | 30 | my $c = 0; |
32 | cmp_ok( $result->return_code, "==", 0, "At least 0 free" ); | 31 | $_ = $result->output; |
33 | like( $result->output, $successOutput, "Right output" ); | 32 | $c++ while /\(/g; # counts number of "(" - should be two |
34 | 33 | cmp_ok( $c, '==', 2, "Got two mountpoints in output"); | |
35 | $result = NPTest->testCmd( "./check_disk -w 1% -c 1% ".${mountpoint_valid} ); # 1% free | 34 | |
36 | cmp_ok( $result->return_code, "==", 0, "At least 1% free" ); | 35 | # Calculate avg_free free on mountpoint1 and mountpoint2 |
37 | like( $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 | 38 | my ($free_on_mp1, $free_on_mp2) = (m/\((\d+)%.*\((\d+)%/); |
40 | cmp_ok( $result->return_code, "==", 0, "At least 1% free on mountpoint_1, 1% free on mountpoint_2" ); | 39 | die "Cannot parse output: $_" unless ($free_on_mp1 && $free_on_mp2); |
41 | like( $result->output, $successOutput, "Right output" ); | 40 | my $avg_free = ceil(($free_on_mp1+$free_on_mp2)/2); |
42 | 41 | my ($more_free, $less_free); | |
43 | # Get free diskspace on NP_MOUNTPOINT_VALID and NP_MOUNTPOINT2_VALID | ||
44 | my $free_space_output = $result->output; | ||
45 | #$free_space_output =~ m/$free_regex/; | ||
46 | my ($free_on_mp1, $free_on_mp2) = ($free_space_output =~ m/\((\d+)%.*\((\d+)%/); | ||
47 | die "Cannot read free_on_mp1" unless $free_on_mp1; | ||
48 | die "Cannot read free_on_mp2" unless $free_on_mp2; | ||
49 | my $average = ceil(($free_on_mp1+$free_on_mp2)/2); | ||
50 | my ($larger, $smaller); | ||
51 | if ($free_on_mp1 > $free_on_mp2) { | 42 | if ($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 | ||
60 | cmp_ok( $result->return_code, "==", 2, "At least 1% free on $larger, 100% free on $smaller" ); | ||
61 | like( $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" ); |
64 | cmp_ok( $result->return_code, "==", 2, "At least ".$average."% free on $larger" ); | 54 | cmp_ok( $result->return_code, '==', 0, "At least 100 bytes available on $more_free"); |
55 | like ( $result->output, $successOutput, "OK output" ); | ||
56 | |||
57 | $result = NPTest->testCmd( "./check_disk 100 100 $more_free" ); | ||
58 | cmp_ok( $result->return_code, '==', 0, "Old syntax okay" ); | ||
59 | |||
60 | $result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p $more_free" ); | ||
61 | cmp_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 | ); | ||
66 | cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $less_free" ); | ||
65 | like( $result->output, $failureOutput, "Right output" ); | 67 | like( $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 | |
68 | cmp_ok( $result->return_code, "==", 1, "At least ".$average."% free on $smaller" ); | 70 | |
69 | like( $result->output, $warningOutput, "Right output" ); | 71 | |
72 | $result = NPTest->testCmd( | ||
73 | "./check_disk -w $avg_free% -c 0% -p $less_free" | ||
74 | ); | ||
75 | cmp_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 | ); | ||
80 | cmp_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 | ); | ||
85 | cmp_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 | ); | ||
92 | cmp_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 | ); | ||
97 | cmp_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 | ); | ||
102 | cmp_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 | ); | ||
109 | cmp_ok( $result->return_code, '==', 3, "Invalid command line options" ); | ||
70 | 110 | ||
71 | TODO: { | 111 | TODO: { |
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" ); | |||
84 | like( $result->output, $failureOutput, "Right output" ); | 121 | like( $result->output, $failureOutput, "Right output" ); |
85 | 122 | ||
86 | TODO: { | 123 | TODO: { |
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 | |||
129 | TODO: { | ||
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 | |
94 | cmp_ok( $result->return_code, "==", 2, "No empty space" ); | 136 | # Checking old syntax of check_disk warn crit [fs], with warn/crit at USED% thresholds |
95 | like( $result->output, $failureOutput, "Right output" ); | 137 | $result = NPTest->testCmd( "./check_disk 0 0 ".${mountpoint_valid} ); |
138 | cmp_ok( $result->return_code, "==", 2, "Old syntax: 0% used"); | ||
139 | |||
140 | $result = NPTest->testCmd( "./check_disk 100 100 $mountpoint_valid" ); | ||
141 | cmp_ok( $result->return_code, '==', 0, "Old syntax: 100% used" ); | ||
142 | |||
143 | $result = NPTest->testCmd( "./check_disk 0 100 $mountpoint_valid" ); | ||
144 | cmp_ok( $result->return_code, '==', 1, "Old syntax: warn 0% used" ); | ||
145 | |||
146 | $result = NPTest->testCmd( "./check_disk 0 200 $mountpoint_valid" ); | ||
147 | cmp_ok( $result->return_code, '==', 3, "Old syntax: Error with values outside percent range" ); | ||
148 | |||
149 | TODO: { | ||
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" ); | ||
156 | cmp_ok( $result->return_code, '==', 3, "Old syntax: Error with values outside percent range" ); | ||
157 | |||