Merge pull request #1586 from computersalat/master
[monitoring-plugins.git] / plugins / t / check_dns.t
blobcdfbe60d4df200f19ed3b24a17cfff0a823cf554
1 #! /usr/bin/perl -w -I ..
3 # Domain Name Server (DNS) Tests via check_dns
7 use strict;
8 use Test::More;
9 use NPTest;
11 plan skip_all => "check_dns not compiled" unless (-x "check_dns");
13 plan tests => 19;
15 my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/';
17 my $hostname_valid = getTestParameter(
18 "NP_HOSTNAME_VALID",
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",
26 "130.133.8.40",
29 my $hostname_valid_cidr = getTestParameter(
30 "NP_HOSTNAME_VALID_CIDR",
31 "An valid CIDR range containing $hostname_valid_ip",
32 "130.133.8.41/30",
35 my $hostname_invalid_cidr = getTestParameter(
36 "NP_HOSTNAME_INVALID_CIDR",
37 "An (valid) CIDR range NOT containing $hostname_valid_ip",
38 "130.133.8.39/30",
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(
54 "NP_DNS_SERVER",
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",
61 "10.0.0.1",
64 my $res;
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");