.
.
.
When you have to load 400 IPs into Nagios/Centreon configuration, how do you do it? By hand?
Well, I wrote a script that pulls all hosts from a CVS file with the fields (HOSTNAME,INFO,IP)
and generates de hosts.cfg file that can afterwards be Loaded by the web frontend of Centreon.
call the script like:
#bash hosts.sh hosts.txt

->hosts.sh script:

#!/bin/sh
#SCRIPT TO MAKE A HOST.CFG list
#By Felipe Ferreira 09/10/2008 version 2.0
file=$1
echo “Nombre del Script: $0”;
echo “Nombre del Host.txt : $file”;
cat $file |while read line;
do
echo “${line}”
NAME=`echo ${line}|cut -d, -f1`
INFO=`echo ${line}|cut -d, -f2`
IP=`echo ${line}|cut -d, -f3`
cat hosts.skel | sed -e “s/NAME/$NAME/” -e “s/INFO/$INFO/” -e “s/IP/$IP/”>>hosts.cfg
done
#clean Illegal Chars
cat hosts.cfg | sed -e “s/ç/c/” -e “s/é/e/” -e “s/è/e/” -e “s/ó/o/” -e “s/ò/o/” -e “s/à/a/” -e “s/´/_/” -e “s/í/i/” -e “s/ú/u/” -e “s/’/_/” >>hostsCLEAN.cfg


->You will also need a hosts.skel file like this:

define host{
host_name Loopback_NAME
use Routers-Diba
alias INFO
address IP
hostgroups DIBA_Loopback
}

->output hosts.cfg:

define host{
host_name Loopback_Alpina
use Routers-Caqi
alias 199.77.200.125 (ZAT)
address 10.0.0.5
hostgroups Caqi_Loopback
}

Tags: , , , , ,

2 thoughts on “Nagios script to load host

  1. Hi Felipe
    I´m trying to use your script but i have a problem with the sed line on the script. The problem is that sed don´t scape the “.” of the ip inside the hosts.txt.
    I have your script, the hosts.txt:
    ABAGU,”10.0.220.1″,ABAGU
    the hosts.skel:
    define host{
    host_name NAME
    use critical-host
    alias INFO
    address IP
    hostgroups HOTELS_BU_SPAIN
    }
    and i execute like you do but with the same error:
    [root@spmdct-mon01 etc]# bash hosts.sh hosts.txt
    .Nombre del Script: hosts.sh.
    .Nombre del Host.txt : hosts.txt.
    .ABAGU,10.0.220.1,ABAGU.
    sed: -e expression #1, char 1: unknown command: `.’
    sed: -e expression #1, char 1: unknown command: `.’
    Please there is something that i´m doing wrong?
    I have to add 500 hosts and your script is a very good tool.
    Thanks

  2. Felipe,
    Is there a away to do a similar thing to load performance data? We have a modem that cannot be polled directly via nagios/centreon. So we need to load in a csv file into centreon?
    Any help is greatly appreciated.
    Regards
    Wes

Leave a Reply

Your email address will not be published. Required fields are marked *