check_dns.t 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # Domain Name Server (DNS) Tests via check_dns
  4. #
  5. # $Id$
  6. #
  7. use strict;
  8. use Test::More;
  9. use NPTest;
  10. plan skip_all => "check_dns not compiled" unless (-x "check_dns");
  11. plan tests => 11;
  12. my $successOutput = '/DNS OK: [\.0-9]+ seconds response time/';
  13. my $hostname_valid = getTestParameter(
  14. "NP_HOSTNAME_VALID",
  15. "A valid (known to DNS) hostname",
  16. "www.apple.com"
  17. );
  18. my $hostname_valid_ip = getTestParameter(
  19. "NP_HOSTNAME_VALID_IP",
  20. "The IP address of the valid hostname $hostname_valid",
  21. "17.112.152.32"
  22. );
  23. my $hostname_valid_reverse = getTestParameter(
  24. "NP_HOSTNAME_VALID_REVERSE",
  25. "The hostname of $hostname_valid_ip",
  26. $hostname_valid
  27. );
  28. my $hostname_invalid = getTestParameter(
  29. "NP_HOSTNAME_INVALID",
  30. "An invalid (not known to DNS) hostname",
  31. "nosuchhost.altinity.com",
  32. );
  33. my $dns_server = getTestParameter(
  34. "NP_DNS_SERVER",
  35. "A non default (remote) DNS server",
  36. );
  37. my $res;
  38. $res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5");
  39. cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid");
  40. like ( $res->output, $successOutput, "Output OK" );
  41. $res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1");
  42. cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid");
  43. $res = NPTest->testCmd("./check_dns -H $hostname_valid -s $dns_server -t 5");
  44. cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
  45. like ( $res->output, $successOutput, "Output OK" );
  46. $res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1");
  47. cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server");
  48. $res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5");
  49. cmp_ok( $res->return_code, '==', 0, "Got expected address");
  50. $res = NPTest->testCmd("./check_dns -H $hostname_valid -a 10.10.10.10 -t 5");
  51. cmp_ok( $res->return_code, '==', 2, "Got wrong address");
  52. like ( $res->output, "/^DNS CRITICAL.*expected '10.10.10.10' but got '$hostname_valid_ip'".'$/', "Output OK");
  53. $res = NPTest->testCmd("./check_dns -H $hostname_valid_ip -a $hostname_valid_reverse -t 5");
  54. cmp_ok( $res->return_code, '==', 0, "Got expected fqdn");
  55. like ( $res->output, $successOutput, "Output OK");