Importing Nagios hosts

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Importing Nagios hosts

Post 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
Nagios XI 5.8.1
https://outsideit.net
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Importing Nagios hosts

Post 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?
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Importing Nagios hosts

Post 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?
Nagios XI 5.8.1
https://outsideit.net
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Importing Nagios hosts

Post 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.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Importing Nagios hosts

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
benhank
Posts: 1264
Joined: Tue Apr 12, 2011 12:29 pm

Re: Importing Nagios hosts

Post by benhank »

SAAAYY.it would be awesome if, when completed you put in the Exchange =D
Proudly running:
NagiosXI 5.4.12 2 node Prod Env 2500 hosts, 13,000 services
Nagiosxi 5.5.7(test env) 2500 hosts, 13,000 services
Nagios Logserver 2 node Prod Env 500 objects sending
Nagios Network Analyser
Nagios Fusion
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Importing Nagios hosts

Post by sreinhardt »

I agree with mr benhank, that could be a pretty useful tool!
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Importing Nagios hosts

Post 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
Nagios XI 5.8.1
https://outsideit.net
Locked