summaryrefslogtreecommitdiffstats
path: root/plugins/t/check_dns.t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t/check_dns.t')
-rw-r--r--plugins/t/check_dns.t75
1 files changed, 53 insertions, 22 deletions
diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t
index fbaca79..5d750d3 100644
--- a/plugins/t/check_dns.t
+++ b/plugins/t/check_dns.t
@@ -6,37 +6,68 @@
6# 6#
7 7
8use strict; 8use strict;
9use Test; 9use Test::More;
10use NPTest; 10use NPTest;
11 11
12use vars qw($tests); 12plan skip_all => "check_dns not compiled" unless (-x "check_dns");
13BEGIN {$tests = 6; plan tests => $tests} 13
14plan tests => 11;
14 15
15my $successOutput = '/DNS OK: [\.0-9]+ seconds response time/'; 16my $successOutput = '/DNS OK: [\.0-9]+ seconds response time/';
16 17
17my $hostname_valid = getTestParameter( "hostname_valid", "NP_HOSTNAME_VALID", "localhost", 18my $hostname_valid = getTestParameter(
18 "A valid (known to DNS) hostname" ); 19 "NP_HOSTNAME_VALID",
20 "A valid (known to DNS) hostname",
21 "www.apple.com"
22 );
19 23
20my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", 24my $hostname_valid_ip = getTestParameter(
21 "An invalid (not known to DNS) hostname" ); 25 "NP_HOSTNAME_VALID_IP",
26 "The IP address of the valid hostname $hostname_valid",
27 "17.112.152.32"
28 );
22 29
23my $dns_server = getTestParameter( "dns_server", "NP_DNS_SERVER", undef, 30my $hostname_valid_reverse = getTestParameter(
24 "A non default (remote) DNS server" ); 31 "NP_HOSTNAME_VALID_REVERSE",
32 "The hostname of $hostname_valid_ip",
33 $hostname_valid
34 );
25 35
26my $t; 36my $hostname_invalid = getTestParameter(
37 "NP_HOSTNAME_INVALID",
38 "An invalid (not known to DNS) hostname",
39 "nosuchhost.altinity.com",
40 );
27 41
28# 42my $dns_server = getTestParameter(
29# Default DNS Server 43 "NP_DNS_SERVER",
30# 44 "A non default (remote) DNS server",
31$t += checkCmd( "./check_dns -H $hostname_valid -t 5", 0, $successOutput ); 45 );
32$t += checkCmd( "./check_dns -H $hostname_invalid -t 1", 2 );
33 46
34# 47my $res;
35# Specified DNS Server 48
36# 49$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5");
37$t += checkCmd( "./check_dns -H $hostname_valid -s $dns_server -t 5", 0, $successOutput ); 50cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid");
38$t += checkCmd( "./check_dns -H $hostname_invalid -s $dns_server -t 1", 2 ); 51like ( $res->output, $successOutput, "Output OK" );
52
53$res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1");
54cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid");
55
56$res = NPTest->testCmd("./check_dns -H $hostname_valid -s $dns_server -t 5");
57cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
58like ( $res->output, $successOutput, "Output OK" );
59
60$res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1");
61cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server");
62
63$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5");
64cmp_ok( $res->return_code, '==', 0, "Got expected address");
65
66$res = NPTest->testCmd("./check_dns -H $hostname_valid -a 10.10.10.10 -t 5");
67cmp_ok( $res->return_code, '==', 2, "Got wrong address");
68like ( $res->output, "/^DNS CRITICAL.*expected '10.10.10.10' but got '$hostname_valid_ip'".'$/', "Output OK");
39 69
40exit(0) if defined($Test::Harness::VERSION); 70$res = NPTest->testCmd("./check_dns -H $hostname_valid_ip -a $hostname_valid_reverse -t 5");
41exit($tests - $t); 71cmp_ok( $res->return_code, '==', 0, "Got expected fqdn");
72like ( $res->output, $successOutput, "Output OK");
42 73