summaryrefslogtreecommitdiffstats
path: root/plugins/t/check_disk.t
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2005-11-12 23:48:29 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2005-11-12 23:48:29 (GMT)
commit7741c005fa10be018264f17e685d5bde34bc92a3 (patch)
treeb81b2adbc95748235d5329685daf819251a39c6c /plugins/t/check_disk.t
parent15330698d4294d428e10a38aa8e82207e57272d1 (diff)
downloadmonitoring-plugins-7741c005fa10be018264f17e685d5bde34bc92a3.tar.gz
Updated check_disk tests to use Test::More (Serhan Kiymaz)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1281 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/t/check_disk.t')
-rw-r--r--plugins/t/check_disk.t88
1 files changed, 77 insertions, 11 deletions
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index df6e149..be267f6 100644
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -6,24 +6,90 @@
6# 6#
7 7
8use strict; 8use strict;
9use Test; 9use Test::More tests => 24;
10use NPTest; 10use NPTest;
11 11use POSIX qw(ceil floor);
12use vars qw($tests);
13BEGIN {$tests = 8; plan tests => $tests}
14 12
15my $successOutput = '/^DISK OK - /'; 13my $successOutput = '/^DISK OK - /';
16my $failureOutput = '/^DISK CRITICAL - /'; 14my $failureOutput = '/^DISK CRITICAL - /';
15my $warningOutput = '/^DISK WARNING - /';
16
17my $result;
17 18
18my $mountpoint_valid = getTestParameter( "mountpoint_valid", "NP_MOUNTPOINT_VALID", "/", 19my $mountpoint_valid = getTestParameter( "mountpoint_valid", "NP_MOUNTPOINT_VALID", "/",
19 "The path to a valid mountpoint" ); 20 "The path to a valid mountpoint" );
20 21
21my $t; 22my $mountpoint2_valid = getTestParameter( "mountpoint2_valid", "NP_MOUNTPOINT2_VALID", "/var",
23 "The path to another valid mountpoint. Must be different from 1st one." );
24
25my $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
28cmp_ok( $result->return_code, "==", 0, "At least 100 free" );
29like( $result->output, $successOutput, "Right output" );
30
31$result = NPTest->testCmd( "./check_disk -w 0 -c 0 ".${mountpoint_valid} ); # 0 free
32cmp_ok( $result->return_code, "==", 0, "At least 0 free" );
33like( $result->output, $successOutput, "Right output" );
34
35$result = NPTest->testCmd( "./check_disk -w 1% -c 1% ".${mountpoint_valid} ); # 1% free
36cmp_ok( $result->return_code, "==", 0, "At least 1% free" );
37like( $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
40cmp_ok( $result->return_code, "==", 0, "At least 1% free on mountpoint_1, 1% free on mountpoint_2" );
41like( $result->output, $successOutput, "Right output" );
42
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) {
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
60cmp_ok( $result->return_code, "==", 2, "At least 1% free on $larger, 100% free on $smaller" );
61like( $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
64cmp_ok( $result->return_code, "==", 2, "At least ".$average."% free on $larger" );
65like( $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
68cmp_ok( $result->return_code, "==", 1, "At least ".$average."% free on $smaller" );
69like( $result->output, $warningOutput, "Right output" );
70
71TODO: {
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
83cmp_ok( $result->return_code, "==", 2, "100% empty" );
84like( $result->output, $failureOutput, "Right output" );
22 85
23$t += checkCmd( "./check_disk 100 100 ${mountpoint_valid}", 0, $successOutput ); 86TODO: {
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
28exit(0) if defined($Test::Harness::VERSION); 93$result = NPTest->testCmd( "./check_disk 0 0 ".${mountpoint_valid} ); # 0 critical
29exit($tests - $t); 94cmp_ok( $result->return_code, "==", 2, "No empty space" );
95like( $result->output, $failureOutput, "Right output" );