check_dns.t 2.5 KB

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