1 #! /usr/bin/perl -w -I ..
3 # Domain Name Server (DNS) Tests via check_dig
11 plan skip_all
=> "check_dig not compiled" unless (-x
"check_dig");
15 my $successOutput = '/DNS OK - [\.0-9]+ seconds? response time/';
17 my $hostname_valid = getTestParameter
(
19 "A valid (known to DNS) hostname",
23 my $hostname_valid_ip = getTestParameter
(
24 "NP_HOSTNAME_VALID_IP",
25 "The IP address of the valid hostname $hostname_valid",
29 my $hostname_valid_reverse = getTestParameter
(
30 "NP_HOSTNAME_VALID_REVERSE",
31 "The hostname of $hostname_valid_ip",
32 "66-118-156-50.static.sagonet.net.",
35 my $hostname_invalid = getTestParameter
(
36 "NP_HOSTNAME_INVALID",
37 "An invalid (not known to DNS) hostname",
38 "nosuchhost.altinity.com",
41 my $dns_server = getTestParameter
(
43 "A non default (remote) DNS server",
49 skip
"check_dig.t: not enough parameters given",
50 12 unless ($hostname_valid && $hostname_valid_ip && $hostname_valid_reverse && $hostname_invalid && $dns_server);
52 $res = NPTest
->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5");
53 cmp_ok
( $res->return_code, '==', 0, "Found $hostname_valid");
54 like
( $res->output, $successOutput, "Output OK" );
56 $res = NPTest
->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -w 0.000001 -c 0.00001");
57 cmp_ok
( $res->return_code, '==', 2, "Critical threshold passed");
59 $res = NPTest
->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -w 0.000001 -c 5");
60 cmp_ok
( $res->return_code, '==', 1, "Warning threshold passed");
62 $res = NPTest
->testCmd("./check_dig -H $dns_server -t 1");
63 cmp_ok
( $res->return_code, '==', 3, "Invalid command line -l missing");
65 $res = NPTest
->testCmd("./check_dig -H $dns_server -l $hostname_invalid -t 1");
66 cmp_ok
( $res->return_code, '==', 2, "Invalid $hostname_invalid");
68 $res = NPTest
->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5");
69 cmp_ok
( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
70 like
( $res->output, $successOutput, "Output OK" );
72 $res = NPTest
->testCmd("./check_dig -H $dns_server -l $hostname_valid -a $hostname_valid_ip -t 5");
73 cmp_ok
( $res->return_code, '==', 0, "Got expected address");
75 $res = NPTest
->testCmd("./check_dig -H $dns_server -l $hostname_valid -a 10.10.10.10 -t 5");
76 cmp_ok
( $res->return_code, '==', 1, "Got wrong address");
78 my $ip_reverse = $hostname_valid_ip;
79 $ip_reverse =~ s/(\d+)\.(\d+)\.(\d+)\.(\d+)/$4.$3.$2.$1.in-addr.arpa/;
80 $res = NPTest
->testCmd("./check_dig -H $dns_server -l $ip_reverse -a $hostname_valid_reverse -T PTR -t 5");
81 cmp_ok
( $res->return_code, '==', 0, "Got expected fqdn");
82 like
( $res->output, $successOutput, "Output OK");