automagically add hosts

Thomas Guyot-Sionnest dermoth at aei.ca
Fri Mar 9 17:08:20 CET 2007


On 09/03/07 10:57 AM, Tom Brown wrote:
> Hi
> 
> Can i ask people how they have got around the auto adding of hosts to 
> their setup? I have a situation were _sometimes_ we have to build many 
> hosts, ~100, at a time so adding these is a bit of a pain. All checks 
> are the same so i can just add to hostgroups etc.
> 
> I can shell onto the monitoring box using keys so i can have scripts do 
> this but i wonder how people do it so i can get ideas on how to solve 
> this etc.
> 
> Or if someone has a script they would share that i can modify that would 
> also be great.
> 
> something like
> 
> ./add_host $HOSTNAME type affair

Something like this:


#!/bin/bash

dd if=/dev/null of=new/hostgroup.cfg
cat hostgroup_template.head >> new/hostgroup.cfg
for i in server1 server2 servern
do
  ip=$(gethostip -d $i.example.com|tr -d " \n")
  sed s/SERVER_NAME/$i.example.com/g hostgroup_template.cfg | sed
s/SERVER_IP/$ip/g >> new/hostgroup.cfg
done

You will need hostgroup_template.head which will look like the top of
your file, then hostgroup_template.cfg which contains one host
definision with the server name replaces with SERVER_NAME and IP address
replaced with SERVER_IP.

It will create a new file in new/ with the hostgroup_template.head as
header and one properly modified hostgroup_template.cfg per hosts in the
for loop after the header.

This is just an example; i.e. I used to use the above script to generate
my MRTG configs, but the same principle can apply for Nagios.

Thomas

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list