check_dns.t 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 => 13;
  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. "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.254.3.183"
  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_valid -t 5 -w 0 -c 0");
  42. cmp_ok( $res->return_code, '==', 2, "Critical threshold passed");
  43. $res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 5");
  44. cmp_ok( $res->return_code, '==', 1, "Warning threshold passed");
  45. $res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1");
  46. cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid");
  47. $res = NPTest->testCmd("./check_dns -H $hostname_valid -s $dns_server -t 5");
  48. cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
  49. like ( $res->output, $successOutput, "Output OK" );
  50. $res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1");
  51. cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server");
  52. $res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5");
  53. cmp_ok( $res->return_code, '==', 0, "Got expected address");
  54. $res = NPTest->testCmd("./check_dns -H $hostname_valid -a 10.10.10.10 -t 5");
  55. cmp_ok( $res->return_code, '==', 2, "Got wrong address");
  56. like ( $res->output, "/^DNS CRITICAL.*expected '10.10.10.10' but got '$hostname_valid_ip'".'$/', "Output OK");
  57. $res = NPTest->testCmd("./check_dns -H $hostname_valid_ip -a $hostname_valid_reverse -t 5");
  58. cmp_ok( $res->return_code, '==', 0, "Got expected fqdn");
  59. like ( $res->output, $successOutput, "Output OK");