Page 1 of 1

Importing Nagios hosts

Posted: Thu Nov 21, 2013 8:03 am
by WillemDH
Hello,

As I have a lot of hosts to add in the coming year and I'd like to automate things a litle bit, I wrote a Powershell script that creates a text file with hosts information.
The file would look like this:

Code: Select all

define host {
hostname	host1.gentgrp.gent.be
address		10.10.10.1
use		dig_server_win_prio2
address		10.10.10.1
hostgroup 	all_srv_role_dc
define host {
hostname	host2.gentgrp.gent.be
address		10.10.10.2
use		dig_server_win_prio2
address		10.10.10.2
hostgroup 	all_srv_role_dc
define host {
hostname	host3.gentgrp.gent.be
address		10.10.10.3
use		dig_server_win_prio2
address		10.10.10.3
hostgroup 	all_srv_role_appl
define host {
hostname	host4.gentgrp.gent.be
address		10.10.10.4
use		dig_server_win_prio2
address		10.10.10.4
hostgroup 	all_srv_role_appl
define host {
hostname	host5.gentgrp.gent.be
address		10.10.10.5
use		dig_server_win_prio2
address		10.10.10.5
Can I use the import config tool to import this file? Will the hosts in the file be added as new hosts? What happens if a host already exists?
Could I update an existing host this way?

The Powershell script would look +- like this: (but instead of getting the data from a csv, it would come from a sql db)

Code: Select all

$import=Import-CSV $inputcsv -Delimiter ","

foreach ($item in $import) {
   "define host {" | Out-File $outputcsv -Append
   "hostname	$($item.hostname)" | Out-File $outputcsv -Append
   "address		$($item.IP)" | Out-File $outputcsv -Append
   "use		$($item.template)" | Out-File $outputcsv -Append
   "address		$($item.IP)" | Out-File $outputcsv -Append
   switch ($($item.role)) {
   	"dc" 	{ "hostgroup 	all_srv_role_dc" | Out-File $outputcsv -Append }
	"appl" 	{ "hostgroup 	all_srv_role_appl" | Out-File $outputcsv -Append }
   }
}
Is my plan to automate host configuration realistic?

Thanks for any tips, suggestions.

Willem

Re: Importing Nagios hosts

Posted: Thu Nov 21, 2013 11:27 am
by slansing
You will likely need to run them through the prep PHP script to separate them out into logical host/service config files so XI can digest them, why do you have two addresses defined for each host?

Re: Importing Nagios hosts

Posted: Fri Nov 22, 2013 3:43 am
by WillemDH
The example I gave was just a quickly made from an example csv. The second address is a bug I will fix. So what happens when I import a host that already exists? Will it's properties be updated?

Re: Importing Nagios hosts

Posted: Fri Nov 22, 2013 12:06 pm
by slansing
Here are the two documents required for this process:

http://assets.nagios.com/downloads/nagi ... p_Tool.pdf

http://assets.nagios.com/downloads/nagi ... nto_XI.pdf

I do not believe that an entire existing host is overwritten by an imported one.

Re: Importing Nagios hosts

Posted: Fri Nov 22, 2013 12:25 pm
by lmiltchev
It will override some of the properties but not all. For example, if you would like to use a different host template, you can modify the config and import it. The "new" host template will be added, however the old host template would not be removed (replaced by the new one), so you will end up with both templates in the config.

Re: Importing Nagios hosts

Posted: Mon Nov 25, 2013 12:47 pm
by benhank
SAAAYY.it would be awesome if, when completed you put in the Exchange =D

Re: Importing Nagios hosts

Posted: Mon Nov 25, 2013 2:35 pm
by sreinhardt
I agree with mr benhank, that could be a pretty useful tool!

Re: Importing Nagios hosts

Posted: Tue Jun 02, 2015 11:18 am
by WillemDH
Hello,

I did not yet put it on the Nagios Exchange, as imho it's not 'ready' yet for 'the public' as it implies using specific templates and naming conventions. It does work however for me. For anyone who would be interested, I put it on my GitHub account:

https://github.com/willemdh/naf_add_server_windows

This thread can be closed.

Grtz

Willem