002-ipv6.t 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. BEGIN {
  5. use File::Basename;
  6. use lib (dirname(__FILE__));
  7. }
  8. use Test::More;
  9. use nrpe;
  10. my @output;
  11. if (!check_if_ipv6_available()) {
  12. plan skip_all => 'IPv6 unavailable.';
  13. }
  14. plan tests => 12;
  15. ensure_daemon_running();
  16. switch_config_file("configs/ipv6.cfg");
  17. restart_daemon();
  18. @output = `$checknrpe -H ::1 -p 40321`;
  19. is($?, STATE_OK, 'connection ipv6') || diag @output;
  20. like($output[0], qr/NRPE v.*/, 'connection ipv6 response') || diag @output;
  21. @output = `$checknrpe -H 127.0.0.1 -p 40321`;
  22. is($?, STATE_OK, 'connection ipv4 on ipv6') || diag @output;
  23. like($output[0], qr/NRPE v.*/, 'connection ipv4 on ipv6 response') || diag @output;
  24. # ipv6.conf has a command_prefix of /bin/echo
  25. @output = `$checknrpe -H ::1 -p 40321 -c timeout`;
  26. is($?, STATE_OK, 'timeout (echo)') || diag @output;
  27. like($output[0], qr'checks/timeout', 'timeout (echo) response') || diag @output;
  28. #####################################################################################
  29. switch_config_file("configs/ipv6-only.cfg");
  30. restart_daemon();
  31. @output = `$checknrpe -H ::1 -p 40321`;
  32. is($?, STATE_OK, 'connection ipv6 only') || diag @output;
  33. like($output[0], qr/NRPE v.*/, 'connection ipv6 only response') || diag @output;
  34. @output = `$checknrpe -H 127.0.0.1 -p 40321 -E`;
  35. is($?, STATE_CRITICAL, 'connection ipv4 on ipv6 only') || diag @output;
  36. like($output[0], qr/connect to .*: Connection refused/, 'connection ipv6 only response') || diag @output;
  37. #####################################################################################
  38. switch_config_file("configs/ipv6-disallowed.cfg");
  39. restart_daemon();
  40. @output = `$checknrpe -H ::1 -p 40321`;
  41. is($?, STATE_UNKNOWN, 'connection ipv6 disallowed') || diag @output;
  42. like($output[0], qr/CHECK_NRPE:.* Error - Could not .*: /, 'connection ipv6 disallowed response') || diag @output;
  43. #####################################################################################
  44. done_testing();