1 #! /usr/bin/perl -w -I ..
3 # Domain Name Server (DNS) Tests via check_dns
11 plan skip_all
=> "check_dns not compiled" unless (-x
"check_dns");
15 my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/';
17 my $hostname_valid = getTestParameter
(
19 "A valid (known to DNS) hostname",
20 "monitoring-plugins.org",
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_cidr = getTestParameter
(
30 "NP_HOSTNAME_VALID_CIDR",
31 "An valid CIDR range containing $hostname_valid_ip",
35 my $hostname_invalid_cidr = getTestParameter
(
36 "NP_HOSTNAME_INVALID_CIDR",
37 "An (valid) CIDR range NOT containing $hostname_valid_ip",
41 my $hostname_valid_reverse = getTestParameter
(
42 "NP_HOSTNAME_VALID_REVERSE",
43 "The hostname of $hostname_valid_ip",
44 "orwell.monitoring-plugins.org.",
47 my $hostname_invalid = getTestParameter
(
48 "NP_HOSTNAME_INVALID",
49 "An invalid (not known to DNS) hostname",
50 "nosuchhost.altinity.com",
53 my $dns_server = getTestParameter
(
55 "A non default (remote) DNS server",
58 my $host_nonresponsive = getTestParameter
(
59 "NP_HOST_NONRESPONSIVE",
60 "The hostname of system not responsive to network requests",
66 $res = NPTest
->testCmd("./check_dns -H $hostname_valid -t 5");
67 cmp_ok
( $res->return_code, '==', 0, "Found $hostname_valid");
68 like
( $res->output, $successOutput, "Output OK" );
70 $res = NPTest
->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 0");
71 cmp_ok
( $res->return_code, '==', 2, "Critical threshold passed");
73 $res = NPTest
->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 5");
74 cmp_ok
( $res->return_code, '==', 1, "Warning threshold passed");
75 like
( $res->output, '/\|time=[\d\.]+s;0.0*;5\.0*;0\.0*/', "Output performance data OK" );
77 $res = NPTest
->testCmd("./check_dns -H $hostname_invalid -t 1");
78 cmp_ok
( $res->return_code, '==', 2, "Invalid $hostname_invalid");
80 $res = NPTest
->testCmd("./check_dns -H $hostname_valid -s $dns_server -t 5");
81 cmp_ok
( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
82 like
( $res->output, $successOutput, "Output OK" );
84 $res = NPTest
->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1");
85 cmp_ok
( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server");
87 $res = NPTest
->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -s $host_nonresponsive -t 2");
88 cmp_ok
( $res->return_code, '==', 2, "Got no answer from unresponsive server");
89 like
( $res->output, "/CRITICAL - /", "Output OK");
91 $res = NPTest
->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5");
92 cmp_ok
( $res->return_code, '==', 0, "Got expected address");
94 $res = NPTest
->testCmd("./check_dns -H $hostname_valid -a 10.10.10.10 -t 5");
95 cmp_ok
( $res->return_code, '==', 2, "Got wrong address");
96 like
( $res->output, "/^DNS CRITICAL.*expected '10.10.10.10' but got '$hostname_valid_ip'".'$/', "Output OK");
98 $res = NPTest
->testCmd("./check_dns -H $hostname_valid_ip -a $hostname_valid_reverse -t 5");
99 cmp_ok
( $res->return_code, '==', 0, "Got expected fqdn");
100 like
( $res->output, $successOutput, "Output OK");
102 $res = NPTest
->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_cidr -t 5");
103 cmp_ok
( $res->return_code, '==', 0, "Got expected address");
105 $res = NPTest
->testCmd("./check_dns -H $hostname_valid -a $hostname_invalid_cidr -t 5");
106 cmp_ok
( $res->return_code, '==', 2, "Got wrong address");
107 like
( $res->output, "/^DNS CRITICAL.*expected '$hostname_invalid_cidr' but got '$hostname_valid_ip'".'$/', "Output OK");