diff options
author | Ton Voon <tonvoon@macbook.local> | 2009-02-19 23:43:15 (GMT) |
---|---|---|
committer | Ton Voon <tonvoon@macbook.local> | 2009-02-19 23:43:15 (GMT) |
commit | 31efea1b490a12a64ce0359c2d847a381d2efb7b (patch) | |
tree | 6aa46c2ca01a830fdeaff19e545ec3fcbdf436c8 /plugins/tests | |
parent | b99afc69bf36131f70a7cd312577118c65300ba6 (diff) | |
download | monitoring-plugins-31efea1b490a12a64ce0359c2d847a381d2efb7b.tar.gz |
Fixed coredump from check_nt when drive not found (Olli Hauer - SF 2179754)
Diffstat (limited to 'plugins/tests')
-rwxr-xr-x | plugins/tests/check_nt.t | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/plugins/tests/check_nt.t b/plugins/tests/check_nt.t new file mode 100755 index 0000000..d1600c7 --- /dev/null +++ b/plugins/tests/check_nt.t | |||
@@ -0,0 +1,77 @@ | |||
1 | #! /usr/bin/perl -w -I .. | ||
2 | # | ||
3 | # Test check_nt by having a stub check_nt daemon | ||
4 | # | ||
5 | |||
6 | use strict; | ||
7 | use Test::More; | ||
8 | use NPTest; | ||
9 | use FindBin qw($Bin); | ||
10 | |||
11 | use IO::Socket; | ||
12 | use IO::Select; | ||
13 | use POSIX; | ||
14 | |||
15 | my $port = 50000 + int(rand(1000)); | ||
16 | |||
17 | my $pid = fork(); | ||
18 | if ($pid) { | ||
19 | # Parent | ||
20 | #print "parent\n"; | ||
21 | # give our webserver some time to startup | ||
22 | sleep(1); | ||
23 | } else { | ||
24 | # Child | ||
25 | #print "child\n"; | ||
26 | |||
27 | my $server = IO::Socket::INET->new( | ||
28 | LocalPort => $port, | ||
29 | Type => SOCK_STREAM, | ||
30 | Reuse => 1, | ||
31 | Proto => "tcp", | ||
32 | Listen => 10, | ||
33 | ) or die "Cannot be a tcp server on port $port: $@"; | ||
34 | |||
35 | $server->autoflush(1); | ||
36 | |||
37 | print "Please contact me at port $port\n"; | ||
38 | while (my $client = $server->accept ) { | ||
39 | my $data = ""; | ||
40 | my $rv = $client->recv($data, POSIX::BUFSIZ, 0); | ||
41 | |||
42 | my ($password, $command, $arg) = split('&', $data); | ||
43 | |||
44 | if ($command eq "4") { | ||
45 | if ($arg eq "c") { | ||
46 | print $client "930000000&1000000000"; | ||
47 | } elsif ($arg eq "d") { | ||
48 | print $client "UNKNOWN: Drive is not a fixed drive"; | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | exit; | ||
53 | } | ||
54 | |||
55 | END { if ($pid) { print "Killing $pid\n"; kill "INT", $pid } }; | ||
56 | |||
57 | if ($ARGV[0] && $ARGV[0] eq "-d") { | ||
58 | sleep 1000; | ||
59 | } | ||
60 | |||
61 | if (-x "./check_nt") { | ||
62 | plan tests => 4; | ||
63 | } else { | ||
64 | plan skip_all => "No check_nt compiled"; | ||
65 | } | ||
66 | |||
67 | my $result; | ||
68 | my $command = "./check_nt -H 127.0.0.1 -p $port"; | ||
69 | |||
70 | $result = NPTest->testCmd( "$command -v USEDDISKSPACE -l c" ); | ||
71 | is( $result->return_code, 0, "USEDDISKSPACE c"); | ||
72 | is( $result->output, q{c:\ - total: 0.93 Gb - used: 0.07 Gb (7%) - free 0.87 Gb (93%) | 'c:\ Used Space'=0.07Gb;0.00;0.00;0.00;0.93}, "Output right" ); | ||
73 | |||
74 | $result = NPTest->testCmd( "$command -v USEDDISKSPACE -l d" ); | ||
75 | is( $result->return_code, 3, "USEDDISKSPACE d - invalid"); | ||
76 | is( $result->output, "Free disk space : Invalid drive", "Output right" ); | ||
77 | |||