Code

check_host: Allocate a large-enough buffer for the host table.
[nagiosplug.git] / plugins / t / check_dns.t
1 #! /usr/bin/perl -w -I ..
2 #
3 # Domain Name Server (DNS) Tests via check_dns
4 #
5 #
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 => 13;
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                         "nagios.com"
21                         );
23 my $hostname_valid_ip = getTestParameter(
24                         "NP_HOSTNAME_VALID_IP",
25                         "The IP address of the valid hostname $hostname_valid",
26                         "66.118.156.50",
27                         );
29 my $hostname_valid_reverse = getTestParameter(
30                         "NP_HOSTNAME_VALID_REVERSE",
31                         "The hostname of $hostname_valid_ip",
32                         "66-118-156-50.static.sagonet.net.",
33                         );
35 my $hostname_invalid = getTestParameter( 
36                         "NP_HOSTNAME_INVALID", 
37                         "An invalid (not known to DNS) hostname",
38                         "nosuchhost.altinity.com",
39                         );
41 my $dns_server       = getTestParameter(
42                         "NP_DNS_SERVER",
43                         "A non default (remote) DNS server",
44                         );
46 my $res;
48 $res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5");
49 cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid");
50 like  ( $res->output, $successOutput, "Output OK" );
52 $res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 0");
53 cmp_ok( $res->return_code, '==', 2, "Critical threshold passed");
55 $res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 5");
56 cmp_ok( $res->return_code, '==', 1, "Warning threshold passed");
58 $res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1");
59 cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid");
61 $res = NPTest->testCmd("./check_dns -H $hostname_valid -s $dns_server -t 5");
62 cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
63 like  ( $res->output, $successOutput, "Output OK" );
65 $res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1");
66 cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server");
68 $res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5");
69 cmp_ok( $res->return_code, '==', 0, "Got expected address");
71 $res = NPTest->testCmd("./check_dns -H $hostname_valid -a 10.10.10.10 -t 5");
72 cmp_ok( $res->return_code, '==', 2, "Got wrong address");
73 like  ( $res->output, "/^DNS CRITICAL.*expected '10.10.10.10' but got '$hostname_valid_ip'".'$/', "Output OK");
75 $res = NPTest->testCmd("./check_dns -H $hostname_valid_ip -a $hostname_valid_reverse -t 5");
76 cmp_ok( $res->return_code, '==', 0, "Got expected fqdn");
77 like  ( $res->output, $successOutput, "Output OK");