Nagios Automation

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
shahnn28
Posts: 4
Joined: Wed Jan 23, 2013 5:13 pm

Nagios Automation

Post 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
}
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios Automation

Post 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.
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
shahnn28
Posts: 4
Joined: Wed Jan 23, 2013 5:13 pm

Re: Nagios Automation

Post by shahnn28 »

Wouldn't I be able to use something similar from Nagios XI or copy that script that does that?
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Nagios Automation

Post 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.
User avatar
jsmurphy
Posts: 989
Joined: Wed Aug 18, 2010 9:46 pm

Re: Nagios Automation

Post 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 :)
Locked