diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2006-03-22 14:17:10 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2006-03-22 14:17:10 +0000 |
commit | 300a7768a862f05482015ba67fd384b2d3a85d37 (patch) | |
tree | 57fb4e7e61b70e71ab288e5de61a59c5ac9773b4 | |
parent | dfbd0be38961413594e6bdddec3858e0a276d780 (diff) | |
download | monitoring-plugins-300a7768a862f05482015ba67fd384b2d3a85d37.tar.gz |
New style tests. Cleanup of presentation of help. Added '' around -a checks
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1342 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r-- | plugins/check_dns.c | 51 | ||||
-rw-r--r-- | plugins/t/check_dns.t | 75 |
2 files changed, 63 insertions, 63 deletions
diff --git a/plugins/check_dns.c b/plugins/check_dns.c index faa1e150..2a3e3760 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c @@ -165,7 +165,7 @@ main (int argc, char **argv) /* compare to expected address */ if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) { result = STATE_CRITICAL; - asprintf(&msg, _("expected %s but got %s"), expected_address, address); + asprintf(&msg, _("expected '%s' but got '%s'"), expected_address, address); } /* check if authoritative */ @@ -379,55 +379,24 @@ print_help (void) printf (COPYRIGHT, copyright, email); printf (_("This plugin uses the nslookup program to obtain the IP address for the given host/domain query.")); - printf ("\n"); - printf (_("An optional DNS server to use may be specified.")); - printf ("\n"); - - printf (_("If no DNS server is specified, the default server(s)specified in /etc/resolv.conf will be used.")); - + printf (_("If no DNS server is specified, the default server(s) specified in /etc/resolv.conf will be used.")); printf ("\n\n"); print_usage (); - printf (_(UT_HELP_VRSN)); - - printf (" -H, --hostname=HOST"); - - printf ("\n"); - - printf (_("the name or address you want to query")); - - printf ("\n"); - - printf (" -s, --server=HOST"); - - printf ("\n"); - - printf (_("optional DNS server you want to use for the lookup")); - - printf ("\n"); - - printf (" -a, --expected-address=IP-ADDRESS"); - - printf ("\n"); - - printf (_("optional IP address you expect the DNS server to return")); - - printf ("\n"); - - printf (" -A, --expect-authority"); - - printf ("\n"); - - printf (_("optionally expect the DNS server to be authoritative for the lookup")); - - printf ("\n"); + printf (" -H, --hostname=HOST\n"); + printf (" %s\n", _("The name or address you want to query")); + printf (" -s, --server=HOST\n"); + printf (" %s\n", _("Optional DNS server you want to use for the lookup")); + printf (" -a, --expected-address=IP-ADDRESS|HOST\n"); + printf (" %s\n", _("Optional IP-ADDRESS you expect the DNS server to return. HOST must end with .")); + printf (" -A, --expect-authority\n"); + printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup")); printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); - printf (_(UT_SUPPORT)); } diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t index fbaca794..5d750d3f 100644 --- a/plugins/t/check_dns.t +++ b/plugins/t/check_dns.t @@ -6,37 +6,68 @@ # use strict; -use Test; +use Test::More; use NPTest; -use vars qw($tests); -BEGIN {$tests = 6; plan tests => $tests} +plan skip_all => "check_dns not compiled" unless (-x "check_dns"); + +plan tests => 11; my $successOutput = '/DNS OK: [\.0-9]+ seconds response time/'; -my $hostname_valid = getTestParameter( "hostname_valid", "NP_HOSTNAME_VALID", "localhost", - "A valid (known to DNS) hostname" ); +my $hostname_valid = getTestParameter( + "NP_HOSTNAME_VALID", + "A valid (known to DNS) hostname", + "www.apple.com" + ); -my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", - "An invalid (not known to DNS) hostname" ); +my $hostname_valid_ip = getTestParameter( + "NP_HOSTNAME_VALID_IP", + "The IP address of the valid hostname $hostname_valid", + "17.112.152.32" + ); -my $dns_server = getTestParameter( "dns_server", "NP_DNS_SERVER", undef, - "A non default (remote) DNS server" ); +my $hostname_valid_reverse = getTestParameter( + "NP_HOSTNAME_VALID_REVERSE", + "The hostname of $hostname_valid_ip", + $hostname_valid + ); -my $t; +my $hostname_invalid = getTestParameter( + "NP_HOSTNAME_INVALID", + "An invalid (not known to DNS) hostname", + "nosuchhost.altinity.com", + ); -# -# Default DNS Server -# -$t += checkCmd( "./check_dns -H $hostname_valid -t 5", 0, $successOutput ); -$t += checkCmd( "./check_dns -H $hostname_invalid -t 1", 2 ); +my $dns_server = getTestParameter( + "NP_DNS_SERVER", + "A non default (remote) DNS server", + ); -# -# Specified DNS Server -# -$t += checkCmd( "./check_dns -H $hostname_valid -s $dns_server -t 5", 0, $successOutput ); -$t += checkCmd( "./check_dns -H $hostname_invalid -s $dns_server -t 1", 2 ); +my $res; + +$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5"); +cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid"); +like ( $res->output, $successOutput, "Output OK" ); + +$res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1"); +cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid"); + +$res = NPTest->testCmd("./check_dns -H $hostname_valid -s $dns_server -t 5"); +cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server"); +like ( $res->output, $successOutput, "Output OK" ); + +$res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1"); +cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server"); + +$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5"); +cmp_ok( $res->return_code, '==', 0, "Got expected address"); + +$res = NPTest->testCmd("./check_dns -H $hostname_valid -a 10.10.10.10 -t 5"); +cmp_ok( $res->return_code, '==', 2, "Got wrong address"); +like ( $res->output, "/^DNS CRITICAL.*expected '10.10.10.10' but got '$hostname_valid_ip'".'$/', "Output OK"); -exit(0) if defined($Test::Harness::VERSION); -exit($tests - $t); +$res = NPTest->testCmd("./check_dns -H $hostname_valid_ip -a $hostname_valid_reverse -t 5"); +cmp_ok( $res->return_code, '==', 0, "Got expected fqdn"); +like ( $res->output, $successOutput, "Output OK"); |