Would it be as easy as adding a set of E's on the template, adding a fifth value in the CSV and adding one more hostgroup echo and cut and throwing the argument in the sed such as:peter.zanetti wrote:That was the issue. I figured it out right about the same time you posted back.
Now to throw another curveball in this, if we wanted to add a device but give it two host groups, is that possible?
Code: Select all
# Original (base) template
define host{
use xiwizard_windowsdesktop_host
host_name AAAA
address BBBB
alias CCCC
hostgroups DDDD,EEEE
}
Code: Select all
#!/bin/bash
/bin/cat /usr/local/nagiosxi/scripts/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/$Name.cfg
done
cd /usr/local/nagiosxi/scripts
./reconfigure_nagios.sh