Issues with a Script for automation
Posted: Mon Jun 15, 2015 1:35 pm
I had recieved some help and a script for a previous thread about the automation of adding new hosts through the command line. Said thread has been linked below.
http://support.nagios.com/forum/viewtop ... 16&t=32968
I just tried to add more than one host from the CSV file and the script ran and added the first device but then it stopped and did not continue onto the second line.
Here is the script:
Here is the Template:
And here is the CSV:
Is there a way to get this script to run through the whole CSV amd add multiple hosts?
http://support.nagios.com/forum/viewtop ... 16&t=32968
I just tried to add more than one host from the CSV file and the script ran and added the first device but then it stopped and did not continue onto the second line.
Here is the script:
Code: Select all
#!/bin/bash
/bin/cat /tmp/new-hosts.csv | while read LINE
do
Name=`/bin/echo $LINE | /bin/cut -d, -f1`
Address=`/bin/echo $LINE | /bin/cut -d, -f2`
Description=`/bin/echo $LINE | /bin/cut -d, -f3`
Hostgroup1=`/bin/echo $LINE | /bin/cut -d, -f4`
Hostgroup2=`/bin/echo $LINE | /bin/cut -d, -f5`
sed -e "s/AAAA/$Name/g; s/BBBB/$Address/g; s/CCCC/$Description/g; s/DDDD/$Hostgroup1/g; s/EEEE/$Hostgroup2/g" /usr/local/nagiosxi/scripts/base-template.cfg > /usr/local/nagios/etc/import/$N
ame.cfg
done
cd /usr/local/nagiosxi/scripts
./reconfigure_nagios.shCode: Select all
# Original (base) template
define host{
use xiwizard_windowsdesktop_host
host_name AAAA
address BBBB
alias CCCC
hostgroups DDDD,EEEE
check_command check_tcp_445!!!!!!!!
max_check_attempts 5
check_interval 15
retry_interval 1
check_period xi_timeperiod_24x7
notification_interval 60
notification_period xi_timeperiod_24x7
icon_image windowsxp.png
statusmap_image windowsxp.png
_xiwizard windowsdesktop
register 1
}Code: Select all
K4285572,K4285572,Test,LabDISDevices,DIS_RET_Servers,
K4283696,K4263696,Test,LabDISDevices,DIS_RET_Servers,