check_dns_random.pl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/perl
  2. # ------------------------------------------------------------------------------
  3. # File Name: check_dns_random.pl
  4. # Author: Richard Mayhew - South Africa
  5. # Date: 2000/01/26
  6. # Version: 1.0
  7. # Description: This script will check to see if dns resolves hosts
  8. # randomly from a list using the check_dns plugin.
  9. # Email: netsaint@splash.co.za
  10. # ------------------------------------------------------------------------------
  11. # Copyright 1999 (c) Richard Mayhew
  12. # Credits go to Ethan Galstad for coding Nagios
  13. # If any changes are made to this script, please mail me a copy of the
  14. # changes :)
  15. # License GPL
  16. # ------------------------------------------------------------------------------
  17. # Date Author Reason
  18. # ---- ------ ------
  19. # 1999/09/26 RM Creation
  20. # ------------------------------------------------------------------------------
  21. # -----------------------------------------------------------------[ Require ]--
  22. require 5.004;
  23. # --------------------------------------------------------------------[ Uses ]--
  24. use Socket;
  25. use strict;
  26. # --------------------------------------------------------------[ Enviroment ]--
  27. $ENV{PATH} = "/bin";
  28. $ENV{BASH_ENV} = "";
  29. $|=1;
  30. my $host = shift || &usage;
  31. my $domainfile = "/usr/local/nagios/etc/domains.list";
  32. my $wc = `/usr/bin/wc -l $domainfile`;
  33. my $check = "/usr/local/nagios/libexec/check_dns";
  34. my $x = 0;
  35. my $srv_file = "";
  36. my $z = "";
  37. my $y = "";
  38. open(DOMAIN,"<$domainfile") or die "Error Opening $domainfile File!\n";
  39. while (<DOMAIN>) {
  40. $srv_file .= $_;
  41. }
  42. close(DOMAIN);
  43. my @data = split(/\n/,$srv_file);
  44. chomp $wc;
  45. $wc =~ s/ //g;
  46. $wc =~ s/domains//g;
  47. $x = rand $wc;
  48. ($z,$y) = split(/\./,$x);
  49. print `$check $data[$z] $host`;
  50. sub usage
  51. {
  52. print "Minimum arguments not supplied!\n";
  53. print "\n";
  54. print "Perl Check Random DNS plugin for Nagios\n";
  55. print "Copyright (c) 2000 Richard Mayhew\n";
  56. print "\n";
  57. print "Usage: check_dns_random.pl <host>\n";
  58. print "\n";
  59. print "<host> = DNS server you would like to query.\n";
  60. exit -1;
  61. }