Importing Nagios hosts
Posted: Thu Nov 21, 2013 8:03 am
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:
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)
Is my plan to automate host configuration realistic?
Thanks for any tips, suggestions.
Willem
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.5Could 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 }
}
}Thanks for any tips, suggestions.
Willem