diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/t/check_disk.t | 88 |
1 files changed, 77 insertions, 11 deletions
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index df6e1495..be267f69 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t | |||
@@ -6,24 +6,90 @@ | |||
6 | # | 6 | # |
7 | 7 | ||
8 | use strict; | 8 | use strict; |
9 | use Test; | 9 | use Test::More tests => 24; |
10 | use NPTest; | 10 | use NPTest; |
11 | 11 | use POSIX qw(ceil floor); | |
12 | use vars qw($tests); | ||
13 | BEGIN {$tests = 8; plan tests => $tests} | ||
14 | 12 | ||
15 | my $successOutput = '/^DISK OK - /'; | 13 | my $successOutput = '/^DISK OK - /'; |
16 | my $failureOutput = '/^DISK CRITICAL - /'; | 14 | my $failureOutput = '/^DISK CRITICAL - /'; |
15 | my $warningOutput = '/^DISK WARNING - /'; | ||
16 | |||
17 | my $result; | ||
17 | 18 | ||
18 | my $mountpoint_valid = getTestParameter( "mountpoint_valid", "NP_MOUNTPOINT_VALID", "/", | 19 | my $mountpoint_valid = getTestParameter( "mountpoint_valid", "NP_MOUNTPOINT_VALID", "/", |
19 | "The path to a valid mountpoint" ); | 20 | "The path to a valid mountpoint" ); |
20 | 21 | ||
21 | my $t; | 22 | my $mountpoint2_valid = getTestParameter( "mountpoint2_valid", "NP_MOUNTPOINT2_VALID", "/var", |
23 | "The path to another valid mountpoint. Must be different from 1st one." ); | ||
24 | |||
25 | my $free_regex = '^DISK OK - free space: '.$mountpoint_valid.' .* MB \((\d+)%[\)]*\); '.$mountpoint2_valid.' .* MB \((\d+)%[\)]*\);|'; | ||
26 | |||
27 | $result = NPTest->testCmd( "./check_disk 100 100 ".${mountpoint_valid} ); # 100 free | ||
28 | cmp_ok( $result->return_code, "==", 0, "At least 100 free" ); | ||
29 | like( $result->output, $successOutput, "Right output" ); | ||
30 | |||
31 | $result = NPTest->testCmd( "./check_disk -w 0 -c 0 ".${mountpoint_valid} ); # 0 free | ||
32 | cmp_ok( $result->return_code, "==", 0, "At least 0 free" ); | ||
33 | like( $result->output, $successOutput, "Right output" ); | ||
34 | |||
35 | $result = NPTest->testCmd( "./check_disk -w 1% -c 1% ".${mountpoint_valid} ); # 1% free | ||
36 | cmp_ok( $result->return_code, "==", 0, "At least 1% free" ); | ||
37 | like( $result->output, $successOutput, "Right output" ); | ||
38 | |||
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 | ||
40 | cmp_ok( $result->return_code, "==", 0, "At least 1% free on mountpoint_1, 1% free on mountpoint_2" ); | ||
41 | like( $result->output, $successOutput, "Right output" ); | ||
42 | |||
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) { | ||
52 | $larger = $mountpoint_valid; | ||
53 | $smaller = $mountpoint2_valid; | ||
54 | } else { | ||
55 | $larger = $mountpoint2_valid; | ||
56 | $smaller = $mountpoint_valid; | ||
57 | } | ||
58 | |||
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 | |||
63 | $result = NPTest->testCmd( "./check_disk -w ".$average."% -c 0% -p ".${larger}." -w ".$average."% -c ".$average."% -p ".${smaller} ); # Average free | ||
64 | cmp_ok( $result->return_code, "==", 2, "At least ".$average."% free on $larger" ); | ||
65 | like( $result->output, $failureOutput, "Right output" ); | ||
66 | |||
67 | $result = NPTest->testCmd( "./check_disk -w ".$average."% -c ".$average."% -p ".${larger}." -w ".$average."% -c 0% -p ".${smaller} ); # Average free | ||
68 | cmp_ok( $result->return_code, "==", 1, "At least ".$average."% free on $smaller" ); | ||
69 | like( $result->output, $warningOutput, "Right output" ); | ||
70 | |||
71 | TODO: { | ||
72 | local $TODO = "We have a bug in check_disk - -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 | ||
74 | cmp_ok( $result->return_code, "==", 2, "At least ".$average."% free on mountpoint_1" ); | ||
75 | like( $result->output, $failureOutput, "Right output" ); | ||
76 | |||
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 | } | ||
81 | |||
82 | $result = NPTest->testCmd( "./check_disk -w 100% -c 100% ".${mountpoint_valid} ); # 100% empty | ||
83 | cmp_ok( $result->return_code, "==", 2, "100% empty" ); | ||
84 | like( $result->output, $failureOutput, "Right output" ); | ||
22 | 85 | ||
23 | $t += checkCmd( "./check_disk 100 100 ${mountpoint_valid}", 0, $successOutput ); | 86 | TODO: { |
24 | $t += checkCmd( "./check_disk -w 0 -c 0 ${mountpoint_valid}", 0, $successOutput ); | 87 | local $TODO = "-u GB sometimes does not work?"; |
25 | $t += checkCmd( "./check_disk -w 1\% -c 1\% ${mountpoint_valid}", 0, $successOutput ); | 88 | $result = NPTest->testCmd( "./check_disk -w 100 -c 100 -u GB ".${mountpoint_valid} ); # 100 GB empty |
26 | $t += checkCmd( "./check_disk 0 0 ${mountpoint_valid}", 2, $failureOutput ); | 89 | cmp_ok( $result->return_code, "==", 2, "100 GB empty" ); |
90 | like( $result->output, $failureOutput, "Right output" ); | ||
91 | } | ||
27 | 92 | ||
28 | exit(0) if defined($Test::Harness::VERSION); | 93 | $result = NPTest->testCmd( "./check_disk 0 0 ".${mountpoint_valid} ); # 0 critical |
29 | exit($tests - $t); | 94 | cmp_ok( $result->return_code, "==", 2, "No empty space" ); |
95 | like( $result->output, $failureOutput, "Right output" ); | ||