4
0

check_dns.t 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 => 20;
  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-plugins.org"
  16. );
  17. my $hostname_valid_ip = getTestParameter(
  18. "NP_HOSTNAME_VALID_IP",
  19. "The IP address of the valid hostname $hostname_valid",
  20. "72.14.186.43",
  21. );
  22. my $hostname_valid_reverse = getTestParameter(
  23. "NP_HOSTNAME_VALID_REVERSE",
  24. "The hostname of $hostname_valid_ip",
  25. "nagios-plugins.org.",
  26. );
  27. my $hostname_invalid = getTestParameter(
  28. "NP_HOSTNAME_INVALID",
  29. "An invalid (not known to DNS) hostname",
  30. "nosuchhost.nagios-plugins.org",
  31. );
  32. my $dns_server = getTestParameter(
  33. "NP_DNS_SERVER",
  34. "A non default (remote) DNS server",
  35. );
  36. my $hostname_valid_aaaa = getTestParameter(
  37. "NP_HOSTNAME_VALID_AAAA",
  38. "A valid hostname for AAAA records"
  39. );
  40. my $hostname_valid_mx = getTestParameter(
  41. "NP_HOSTNAME_VALID_MX",
  42. "A valid hostname for MX records",
  43. "nagios-plugins.org",
  44. );
  45. my $hostname_valid_srv = getTestParameter(
  46. "NP_HOSTNAME_VALID_SRV",
  47. "A valid hostname for SRV records"
  48. );
  49. my $hostname_valid_txt = getTestParameter(
  50. "NP_HOSTNAME_VALID_TXT",
  51. "A valid hostname for TXT records"
  52. );
  53. my $res;
  54. $res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5");
  55. cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid");
  56. like ( $res->output, $successOutput, "Output OK" );
  57. $res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 0");
  58. cmp_ok( $res->return_code, '==', 2, "Critical threshold passed");
  59. $res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 5");
  60. cmp_ok( $res->return_code, '==', 1, "Warning threshold passed");
  61. like( $res->output, '/\|time=[\d\.]+s;0.0*;5\.0*;0\.0*/', "Output performance data OK" );
  62. $res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1");
  63. cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid");
  64. $res = NPTest->testCmd("./check_dns -H $hostname_valid -s $dns_server -t 5");
  65. cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
  66. like ( $res->output, $successOutput, "Output OK" );
  67. $res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1");
  68. cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server");
  69. $res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5");
  70. cmp_ok( $res->return_code, '==', 0, "Got expected address");
  71. $res = NPTest->testCmd("./check_dns -H $hostname_valid -a 10.10.10.10 -t 5");
  72. cmp_ok( $res->return_code, '==', 2, "Got wrong address");
  73. like ( $res->output, "/^DNS CRITICAL.*expected '10.10.10.10' but got '$hostname_valid_ip'".'$/', "Output OK");
  74. $res = NPTest->testCmd("./check_dns -H $hostname_valid_ip -a $hostname_valid_reverse -t 5");
  75. cmp_ok( $res->return_code, '==', 0, "Got expected fqdn");
  76. like ( $res->output, $successOutput, "Output OK");
  77. SKIP: {
  78. skip "No server specified for checking TXT records", 2 unless $hostname_valid_txt;
  79. $res = NPTest->testCmd("./check_dns -H $hostname_valid_txt -s $dns_server -q TXT");
  80. cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid_txt");
  81. like ( $res->output, $successOutput, "TXT Output OK" );
  82. }
  83. SKIP: {
  84. skip "No server specified for checking SRV records", 2 unless $hostname_valid_srv;
  85. $res = NPTest->testCmd("./check_dns -H $hostname_valid_srv -s $dns_server -q SRV");
  86. cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid_srv");
  87. like ( $res->output, $successOutput, "SRV Output OK" );
  88. }
  89. SKIP: {
  90. skip "No server specified for checking AAAA records", 2 unless $hostname_valid_aaaa;
  91. $res = NPTest->testCmd("./check_dns -H $hostname_valid_aaaa -s $dns_server -q AAAA");
  92. cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid_aaaa");
  93. like ( $res->output, $successOutput, "TXT Output OK" );
  94. }