When you are one of a few System Administrators in a large enterprise, new hosts are added that you may not hear about. I created a Perl script that uses the “dig” command to:
- Find new hosts added to DNS and obtain the hostname and IP address.
- Searches the Nagios hosts directory to make sure it does not exist within Nagios.
- Adds the commented-out host definition to a file new_found_host.cfg file. You want the entry to be commented out, because if there is a new entry in DNS that does not mean the server is actually up-and-running.
- Scheduled to run in the crontab each night and send out email about new hosts discovered on the domain.
When you initially run the script you will receive a listing of ALL hosts found in DNS, unless you modify the exclude search filters in the Perl script. However, once it is added to the host configuration file, the host will not be rediscovered in subsequent passes.
The Perl script was created quickly, so there is a whole lot of room for System Administrators to modify the script. The script is covered under the GNU license, so we ask that you share with the Nagios community any methods to improve the script.
Here is a link to the ZIP file. Nagios: Dynamically discover hosts on a domain and add them to a Nagios hosts file. The files are placed in a folder, then zipped so you do not have to worry about trying to find them once you open the package.