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) | |||
| 165 | /* compare to expected address */ | 165 | /* compare to expected address */ |
| 166 | if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) { | 166 | if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) { |
| 167 | result = STATE_CRITICAL; | 167 | result = STATE_CRITICAL; |
| 168 | asprintf(&msg, _("expected %s but got %s"), expected_address, address); | 168 | asprintf(&msg, _("expected '%s' but got '%s'"), expected_address, address); |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | /* check if authoritative */ | 171 | /* check if authoritative */ |
| @@ -379,55 +379,24 @@ print_help (void) | |||
| 379 | printf (COPYRIGHT, copyright, email); | 379 | printf (COPYRIGHT, copyright, email); |
| 380 | 380 | ||
| 381 | printf (_("This plugin uses the nslookup program to obtain the IP address for the given host/domain query.")); | 381 | printf (_("This plugin uses the nslookup program to obtain the IP address for the given host/domain query.")); |
| 382 | |||
| 383 | printf ("\n"); | 382 | printf ("\n"); |
| 384 | |||
| 385 | printf (_("An optional DNS server to use may be specified.")); | 383 | printf (_("An optional DNS server to use may be specified.")); |
| 386 | |||
| 387 | printf ("\n"); | 384 | printf ("\n"); |
| 388 | 385 | printf (_("If no DNS server is specified, the default server(s) specified in /etc/resolv.conf will be used.")); | |
| 389 | printf (_("If no DNS server is specified, the default server(s)specified in /etc/resolv.conf will be used.")); | ||
| 390 | |||
| 391 | printf ("\n\n"); | 386 | printf ("\n\n"); |
| 392 | 387 | ||
| 393 | print_usage (); | 388 | print_usage (); |
| 394 | |||
| 395 | printf (_(UT_HELP_VRSN)); | 389 | printf (_(UT_HELP_VRSN)); |
| 396 | 390 | printf (" -H, --hostname=HOST\n"); | |
| 397 | printf (" -H, --hostname=HOST"); | 391 | printf (" %s\n", _("The name or address you want to query")); |
| 398 | 392 | printf (" -s, --server=HOST\n"); | |
| 399 | printf ("\n"); | 393 | printf (" %s\n", _("Optional DNS server you want to use for the lookup")); |
| 400 | 394 | printf (" -a, --expected-address=IP-ADDRESS|HOST\n"); | |
| 401 | printf (_("the name or address you want to query")); | 395 | printf (" %s\n", _("Optional IP-ADDRESS you expect the DNS server to return. HOST must end with .")); |
| 402 | 396 | printf (" -A, --expect-authority\n"); | |
| 403 | printf ("\n"); | 397 | printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup")); |
| 404 | |||
| 405 | printf (" -s, --server=HOST"); | ||
| 406 | |||
| 407 | printf ("\n"); | ||
| 408 | |||
| 409 | printf (_("optional DNS server you want to use for the lookup")); | ||
| 410 | |||
| 411 | printf ("\n"); | ||
| 412 | |||
| 413 | printf (" -a, --expected-address=IP-ADDRESS"); | ||
| 414 | |||
| 415 | printf ("\n"); | ||
| 416 | |||
| 417 | printf (_("optional IP address you expect the DNS server to return")); | ||
| 418 | |||
| 419 | printf ("\n"); | ||
| 420 | |||
| 421 | printf (" -A, --expect-authority"); | ||
| 422 | |||
| 423 | printf ("\n"); | ||
| 424 | |||
| 425 | printf (_("optionally expect the DNS server to be authoritative for the lookup")); | ||
| 426 | |||
| 427 | printf ("\n"); | ||
| 428 | 398 | ||
| 429 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | 399 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); |
| 430 | |||
| 431 | printf (_(UT_SUPPORT)); | 400 | printf (_(UT_SUPPORT)); |
| 432 | } | 401 | } |
| 433 | 402 | ||
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 @@ | |||
| 6 | # | 6 | # |
| 7 | 7 | ||
| 8 | use strict; | 8 | use strict; |
| 9 | use Test; | 9 | use Test::More; |
| 10 | use NPTest; | 10 | use NPTest; |
| 11 | 11 | ||
| 12 | use vars qw($tests); | 12 | plan skip_all => "check_dns not compiled" unless (-x "check_dns"); |
| 13 | BEGIN {$tests = 6; plan tests => $tests} | 13 | |
| 14 | plan tests => 11; | ||
| 14 | 15 | ||
| 15 | my $successOutput = '/DNS OK: [\.0-9]+ seconds response time/'; | 16 | my $successOutput = '/DNS OK: [\.0-9]+ seconds response time/'; |
| 16 | 17 | ||
| 17 | my $hostname_valid = getTestParameter( "hostname_valid", "NP_HOSTNAME_VALID", "localhost", | 18 | my $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 | ||
| 20 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | 24 | my $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 | ||
| 23 | my $dns_server = getTestParameter( "dns_server", "NP_DNS_SERVER", undef, | 30 | my $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 | ||
| 26 | my $t; | 36 | my $hostname_invalid = getTestParameter( |
| 37 | "NP_HOSTNAME_INVALID", | ||
| 38 | "An invalid (not known to DNS) hostname", | ||
| 39 | "nosuchhost.altinity.com", | ||
| 40 | ); | ||
| 27 | 41 | ||
| 28 | # | 42 | my $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 | # | 47 | my $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 ); | 50 | cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid"); |
| 38 | $t += checkCmd( "./check_dns -H $hostname_invalid -s $dns_server -t 1", 2 ); | 51 | like ( $res->output, $successOutput, "Output OK" ); |
| 52 | |||
| 53 | $res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1"); | ||
| 54 | cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid"); | ||
| 55 | |||
| 56 | $res = NPTest->testCmd("./check_dns -H $hostname_valid -s $dns_server -t 5"); | ||
| 57 | cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server"); | ||
| 58 | like ( $res->output, $successOutput, "Output OK" ); | ||
| 59 | |||
| 60 | $res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1"); | ||
| 61 | cmp_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"); | ||
| 64 | cmp_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"); | ||
| 67 | cmp_ok( $res->return_code, '==', 2, "Got wrong address"); | ||
| 68 | like ( $res->output, "/^DNS CRITICAL.*expected '10.10.10.10' but got '$hostname_valid_ip'".'$/', "Output OK"); | ||
| 39 | 69 | ||
| 40 | exit(0) if defined($Test::Harness::VERSION); | 70 | $res = NPTest->testCmd("./check_dns -H $hostname_valid_ip -a $hostname_valid_reverse -t 5"); |
| 41 | exit($tests - $t); | 71 | cmp_ok( $res->return_code, '==', 0, "Got expected fqdn"); |
| 72 | like ( $res->output, $successOutput, "Output OK"); | ||
| 42 | 73 | ||
