Merge pull request #2053 from klaernie/support
[monitoring-plugins.git] / plugins / t / check_dig.t
blob3ed6cc8ef38385d4fbbbe13f2bf424ee6e2c9800
1 #! /usr/bin/perl -w -I ..
3 # Domain Name Server (DNS) Tests via check_dig
7 use strict;
8 use Test::More;
11 use vars qw($tests $has_ipv6);
12 BEGIN {
13 plan skip_all => "check_dig not compiled" unless (-x "check_dig");
14 use NPTest;
15 $has_ipv6 = NPTest::has_ipv6();
16 $tests = $has_ipv6 ? 16 : 14;
17 plan tests => $tests;
20 my $successOutput = '/DNS OK - [\.0-9]+ seconds? response time/';
22 my $hostname_valid = getTestParameter(
23 "NP_HOSTNAME_VALID",
24 "A valid (known to DNS) hostname",
25 "orwell.monitoring-plugins.org"
28 my $hostname_valid_ip = getTestParameter(
29 "NP_HOSTNAME_VALID_IP",
30 "The IP address of the valid hostname $hostname_valid",
31 "130.133.8.40",
34 my $hostname_valid_reverse = getTestParameter(
35 "NP_HOSTNAME_VALID_REVERSE",
36 "The hostname of $hostname_valid_ip",
37 "orwell.monitoring-plugins.org.",
40 my $hostname_invalid = getTestParameter(
41 "NP_HOSTNAME_INVALID",
42 "An invalid (not known to DNS) hostname",
43 "nosuchhost.monitoring-plugins.org",
46 my $dns_server = getTestParameter(
47 "NP_DNS_SERVER",
48 "A non default (remote) DNS server",
51 my $res;
53 SKIP: {
54 skip "check_dig.t: not enough parameters given",
55 12 unless ($hostname_valid && $hostname_valid_ip && $hostname_valid_reverse && $hostname_invalid && $dns_server);
57 $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5");
58 cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid");
59 like ( $res->output, $successOutput, "Output OK" );
61 $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -w 0.000001 -c 0.00001");
62 cmp_ok( $res->return_code, '==', 2, "Critical threshold passed");
64 $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -w 0.000001 -c 5");
65 cmp_ok( $res->return_code, '==', 1, "Warning threshold passed");
67 $res = NPTest->testCmd("./check_dig -H $dns_server -t 1");
68 cmp_ok( $res->return_code, '==', 3, "Invalid command line -l missing");
70 $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_invalid -t 1");
71 cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid");
73 $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5");
74 cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
75 like ( $res->output, $successOutput, "Output OK" );
77 $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -4");
78 cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
79 like ( $res->output, $successOutput, "Output OK for IPv4" );
81 $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -a $hostname_valid_ip -t 5");
82 cmp_ok( $res->return_code, '==', 0, "Got expected address");
84 $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -a 10.10.10.10 -t 5");
85 cmp_ok( $res->return_code, '==', 1, "Got wrong address");
87 my $ip_reverse = $hostname_valid_ip;
88 $ip_reverse =~ s/(\d+)\.(\d+)\.(\d+)\.(\d+)/$4.$3.$2.$1.in-addr.arpa/;
89 $res = NPTest->testCmd("./check_dig -H $dns_server -l $ip_reverse -a $hostname_valid_reverse -T PTR -t 5");
90 cmp_ok( $res->return_code, '==', 0, "Got expected fqdn");
91 like ( $res->output, $successOutput, "Output OK");
93 if($has_ipv6) {
94 $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -6");
95 cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
96 like ( $res->output, $successOutput, "Output OK for IPv6" );