9a95e808598b8521a578d3c2ab7b5a6999e2babe
1 #! /usr/bin/perl -w -I ..
2 #
3 # Domain Name Server (DNS) Tests via check_dns
4 #
5 # $Id$
6 #
8 use strict;
9 use Test::More;
10 use NPTest;
12 plan skip_all => "check_dns not compiled" unless (-x "check_dns");
14 plan tests => 13;
16 my $successOutput = '/DNS OK: [\.0-9]+ seconds response time/';
18 my $hostname_valid = getTestParameter(
19 "NP_HOSTNAME_VALID",
20 "A valid (known to DNS) hostname",
21 "www.apple.com"
22 );
24 my $hostname_valid_ip = getTestParameter(
25 "NP_HOSTNAME_VALID_IP",
26 "The IP address of the valid hostname $hostname_valid",
27 "17.112.152.32"
28 );
30 my $hostname_valid_reverse = getTestParameter(
31 "NP_HOSTNAME_VALID_REVERSE",
32 "The hostname of $hostname_valid_ip",
33 $hostname_valid
34 );
36 my $hostname_invalid = getTestParameter(
37 "NP_HOSTNAME_INVALID",
38 "An invalid (not known to DNS) hostname",
39 "nosuchhost.altinity.com",
40 );
42 my $dns_server = getTestParameter(
43 "NP_DNS_SERVER",
44 "A non default (remote) DNS server",
45 );
47 my $res;
49 $res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5");
50 cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid");
51 like ( $res->output, $successOutput, "Output OK" );
53 $res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 0");
54 cmp_ok( $res->return_code, '==', 2, "Critical threshold passed");
56 $res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 5");
57 cmp_ok( $res->return_code, '==', 1, "Warning threshold passed");
59 $res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1");
60 cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid");
62 $res = NPTest->testCmd("./check_dns -H $hostname_valid -s $dns_server -t 5");
63 cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
64 like ( $res->output, $successOutput, "Output OK" );
66 $res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1");
67 cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server");
69 $res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5");
70 cmp_ok( $res->return_code, '==', 0, "Got expected address");
72 $res = NPTest->testCmd("./check_dns -H $hostname_valid -a 10.10.10.10 -t 5");
73 cmp_ok( $res->return_code, '==', 2, "Got wrong address");
74 like ( $res->output, "/^DNS CRITICAL.*expected '10.10.10.10' but got '$hostname_valid_ip'".'$/', "Output OK");
76 $res = NPTest->testCmd("./check_dns -H $hostname_valid_ip -a $hostname_valid_reverse -t 5");
77 cmp_ok( $res->return_code, '==', 0, "Got expected fqdn");
78 like ( $res->output, $successOutput, "Output OK");