diff options
author | Matthias Eble <psychotrahe@users.sourceforge.net> | 2008-06-09 19:47:36 +0000 |
---|---|---|
committer | Matthias Eble <psychotrahe@users.sourceforge.net> | 2008-06-09 19:47:36 +0000 |
commit | d8577e19942b4885ac642513540fc1791a0fa38b (patch) | |
tree | e31b28007cee8baf4c76ed5a3eb2312d0a6fdac8 /plugins | |
parent | 5c3d4aea27de408cb7b04f5aab83558efbf841f4 (diff) | |
download | monitoring-plugins-d8577e19942b4885ac642513540fc1791a0fa38b.tar.gz |
Added testcases for check_dig
check_dig's -l option is mandatory now (#1986306)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2011 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_dig.c | 11 | ||||
-rw-r--r-- | plugins/t/check_dig.t | 85 |
2 files changed, 93 insertions, 3 deletions
diff --git a/plugins/check_dig.c b/plugins/check_dig.c index e3f7adbd..34197ecc 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c | |||
@@ -143,8 +143,10 @@ main (int argc, char **argv) | |||
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
146 | if (result == STATE_UNKNOWN) | 146 | if (result == STATE_UNKNOWN) { |
147 | msg = (char *)_("No ANSWER SECTION found"); | 147 | msg = (char *)_("No ANSWER SECTION found"); |
148 | result = STATE_CRITICAL; | ||
149 | } | ||
148 | 150 | ||
149 | /* If we get anything on STDERR, at least set warning */ | 151 | /* If we get anything on STDERR, at least set warning */ |
150 | if(chld_err.buflen > 0) { | 152 | if(chld_err.buflen > 0) { |
@@ -295,7 +297,10 @@ process_arguments (int argc, char **argv) | |||
295 | int | 297 | int |
296 | validate_arguments (void) | 298 | validate_arguments (void) |
297 | { | 299 | { |
298 | return OK; | 300 | if (query_address != NULL) |
301 | return OK; | ||
302 | else | ||
303 | return ERROR; | ||
299 | } | 304 | } |
300 | 305 | ||
301 | 306 | ||
@@ -357,7 +362,7 @@ void | |||
357 | print_usage (void) | 362 | print_usage (void) |
358 | { | 363 | { |
359 | printf (_("Usage:")); | 364 | printf (_("Usage:")); |
360 | printf ("%s -H <host> -l <query_address> [-p <server port>]\n", progname); | 365 | printf ("%s -l <query_address> [-H <host>] [-p <server port>]\n", progname); |
361 | printf (" [-T <query type>] [-w <warning interval>] [-c <critical interval>]\n"); | 366 | printf (" [-T <query type>] [-w <warning interval>] [-c <critical interval>]\n"); |
362 | printf (" [-t <timeout>] [-a <expected answer address>] [-v]\n"); | 367 | printf (" [-t <timeout>] [-a <expected answer address>] [-v]\n"); |
363 | } | 368 | } |
diff --git a/plugins/t/check_dig.t b/plugins/t/check_dig.t new file mode 100644 index 00000000..937eec33 --- /dev/null +++ b/plugins/t/check_dig.t | |||
@@ -0,0 +1,85 @@ | |||
1 | #! /usr/bin/perl -w -I .. | ||
2 | # | ||
3 | # Domain Name Server (DNS) Tests via check_dig | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
7 | |||
8 | use strict; | ||
9 | use Test::More; | ||
10 | use NPTest; | ||
11 | |||
12 | plan skip_all => "check_dig not compiled" unless (-x "check_dig"); | ||
13 | |||
14 | plan tests => 12; | ||
15 | |||
16 | my $successOutput = '/DNS OK - [\.0-9]+ seconds? response time/'; | ||
17 | |||
18 | my $hostname_valid = getTestParameter( | ||
19 | "NP_HOSTNAME_VALID", | ||
20 | "A valid (known to DNS) hostname", | ||
21 | "nagios.com" | ||
22 | ); | ||
23 | |||
24 | my $hostname_valid_ip = getTestParameter( | ||
25 | "NP_HOSTNAME_VALID_IP", | ||
26 | "The IP address of the valid hostname $hostname_valid", | ||
27 | "66.118.156.50", | ||
28 | ); | ||
29 | |||
30 | my $hostname_valid_reverse = getTestParameter( | ||
31 | "NP_HOSTNAME_VALID_REVERSE", | ||
32 | "The hostname of $hostname_valid_ip", | ||
33 | "66-118-156-50.static.sagonet.net.", | ||
34 | ); | ||
35 | |||
36 | my $hostname_invalid = getTestParameter( | ||
37 | "NP_HOSTNAME_INVALID", | ||
38 | "An invalid (not known to DNS) hostname", | ||
39 | "nosuchhost.altinity.com", | ||
40 | ); | ||
41 | |||
42 | my $dns_server = getTestParameter( | ||
43 | "NP_DNS_SERVER", | ||
44 | "A non default (remote) DNS server", | ||
45 | ); | ||
46 | |||
47 | my $res; | ||
48 | |||
49 | SKIP: { | ||
50 | skip "check_dig.t: not enough parameters given", | ||
51 | 12 unless ($hostname_valid && $hostname_valid_ip && $hostname_valid_reverse && $hostname_invalid && $dns_server); | ||
52 | |||
53 | $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5"); | ||
54 | cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid"); | ||
55 | like ( $res->output, $successOutput, "Output OK" ); | ||
56 | |||
57 | $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -w 0.000001 -c 0.00001"); | ||
58 | cmp_ok( $res->return_code, '==', 2, "Critical threshold passed"); | ||
59 | |||
60 | $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -w 0.000001 -c 5"); | ||
61 | cmp_ok( $res->return_code, '==', 1, "Warning threshold passed"); | ||
62 | |||
63 | $res = NPTest->testCmd("./check_dig -H $dns_server -t 1"); | ||
64 | cmp_ok( $res->return_code, '==', 3, "Invalid command line -l missing"); | ||
65 | |||
66 | $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_invalid -t 1"); | ||
67 | cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid"); | ||
68 | |||
69 | $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5"); | ||
70 | cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server"); | ||
71 | like ( $res->output, $successOutput, "Output OK" ); | ||
72 | |||
73 | $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -a $hostname_valid_ip -t 5"); | ||
74 | cmp_ok( $res->return_code, '==', 0, "Got expected address"); | ||
75 | |||
76 | $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -a 10.10.10.10 -t 5"); | ||
77 | cmp_ok( $res->return_code, '==', 1, "Got wrong address"); | ||
78 | |||
79 | my $ip_reverse = $hostname_valid_ip; | ||
80 | $ip_reverse =~ s/(\d+)\.(\d+)\.(\d+)\.(\d+)/$4.$3.$2.$1.in-addr.arpa/; | ||
81 | $res = NPTest->testCmd("./check_dig -H $dns_server -l $ip_reverse -a $hostname_valid_reverse -T PTR -t 5"); | ||
82 | cmp_ok( $res->return_code, '==', 0, "Got expected fqdn"); | ||
83 | like ( $res->output, $successOutput, "Output OK"); | ||
84 | |||
85 | } | ||