Page 1 of 1
Nagios Automation
Posted: Wed Jan 23, 2013 5:19 pm
by shahnn28
Is there a way to automate nagios core to pick up hosts from a file automating the process of creating a hosts in the hosts.cfg for 100s of nodes?
Example:
Generating a file called new_hosts that has the following:
Host: ServerA
IP: XXXXX
An automated process that will go ahead and create the following in the hosts.cfg:
define host{
use generic-host
host_name ServerA
alias Server A
address XXXXX
hostgroup_name web-server
}
Re: Nagios Automation
Posted: Sun Jan 27, 2013 12:25 am
by scottwilkerson
You would just want to write something in your favorite scripting language to create the file for you.
In Nagios XI the Bulk Host Import & Cloning Wizard does something similar to this.
Re: Nagios Automation
Posted: Tue Feb 05, 2013 1:57 pm
by shahnn28
Wouldn't I be able to use something similar from Nagios XI or copy that script that does that?
Re: Nagios Automation
Posted: Tue Feb 05, 2013 4:18 pm
by slansing
You could try to reproduce it if that is what you are looking for, though quite a few things would not function the same because of what the component was built on.
Re: Nagios Automation
Posted: Tue Feb 05, 2013 4:22 pm
by jsmurphy
Nagios XI is a paid for product and the bulk host import is a part of the application.
It's relatively simple to write something yourself anyway, I created one a while back that quiesces AD, virtual infrastructure and certain network segments for new hosts... unfortunately I can't share that because it's got a little to much company specific stuff in it. But I can at least give you the basics of how I did it.
1. Create a directory full of template files... these files are the full configuration files except with special key words to replace i.e. hostname $HOSTNAME$
2. Throw together something in your favourite language to read your import file and put the hosts/IP's into a hash table.
3. Loop through the hash table and load the relevant template for that host into an array and loop through doing a regex replace on the key words i.e. s/\$HOSTNAME\$/$myhosts{'host1'}/;
4. Write array back to a file.
All it really takes is some simple IO and regex
