My Deploy Script for Sharing with All NConf Fans

Tell us how you use NConf, what environment you have, what challenges you face, what solutions you've implemented

My Deploy Script for Sharing with All NConf Fans

Postby damcool » Sat Dec 17, 2011 15:22

Hi, All

Very exciting to have nconf as my centralized config tool of my servral nagios servers. And I found the 1.3 version power enough for deploy the config to all servers. Rather than using the web based one coming with nconf, I wrote my bash script. and set it as the cron job of user nagios. Referenced the deploy_local.sh


Installation Steps:
1. make nagios ssh to all other nagios servers without password keyin by ssh-keygen & ssh-copy-id command, google for detail instructions
2. put the script in the home folder of nagios with the name of deploy_all.sh
3.configure all distrbution collector names with the hostnames of collectors
4. create a cron job for nagios via crontab -e
* * * * * sh ~/deploy_all.sh >/dev/null 2>&1


Code: Select all
#!/bin/bash

OUTPUT_DIR="/var/www/html/nconf/output/"
NAGIOS_DIR="/usr/local/nagios/etc/"
TEMP_DIR=${NAGIOS_DIR}"import/"
CONF_ARCHIVE="NagiosConfig.tgz"
HOST_LIST=(shamnt01 suzmnt01 nanmnt01)
#IF YOU WANT THE LOCAL HOST AS NAGIOS SERVER EITHER
ENABLE_LOCAL=0

if [ ! -e ${TEMP_DIR} ] ; then
mkdir -p ${TEMP_DIR}
fi

if [ ${OUTPUT_DIR}${CONF_ARCHIVE} -nt ${TEMP_DIR}${CONF_ARCHIVE} ] ; then
   cp -p ${OUTPUT_DIR}${CONF_ARCHIVE} ${TEMP_DIR}${CONF_ARCHIVE}
   tar -xf ${TEMP_DIR}${CONF_ARCHIVE} -C ${NAGIOS_DIR}
   rm -f ${NAGIOS_DIR}nagios.cfg.deployed
   cp ${NAGIOS_DIR}nagios.cfg ${NAGIOS_DIR}nagios.cfg.deployed
   grep -v -E "^#" ${NAGIOS_DIR}nagios.cfg > ${NAGIOS_DIR}nagios.cfg.deployed
   grep -v -E "^(cfg_file|cfg_dir)" ${NAGIOS_DIR}nagios.cfg.deployed > ${NAGIOS_DIR}nagios.cfg
   echo "cfg_dir=${NAGIOS_DIR}global" >> ${NAGIOS_DIR}nagios.cfg
   
   for host in ${HOST_LIST[*]}; do
      scp -r ${NAGIOS_DIR}"global" $host:$NAGIOS_DIR
      scp -r ${NAGIOS_DIR}"$host" $host:$NAGIOS_DIR
      ssh $host "grep -v -E \"^#\" ${NAGIOS_DIR}nagios.cfg > ${NAGIOS_DIR}nagios.cfg.deployed;grep -v -E \"^(cfg_file|cfg_dir)\" ${NAGIOS_DIR}nagios.cfg.deployed> ${NAGIOS_DIR}nagios.cfg"
      ssh $host "echo \"cfg_dir=${NAGIOS_DIR}global\" >> ${NAGIOS_DIR}nagios.cfg;echo \"cfg_dir=${NAGIOS_DIR}$host\" >> ${NAGIOS_DIR}nagios.cfg"
      ssh $host "/etc/init.d/nagios reload"
      echo "cfg_dir=${NAGIOS_DIR}$host" >> ${NAGIOS_DIR}nagios.cfg
   done
   [ $ENABLE_LOCAL -eq 1 ] && /etc/init.d/nagios reload
fi

exit
damcool
beginner
beginner
 
Posts: 8
Joined: Sun Dec 11, 2011 14:59

Re: My Deploy Script for Sharing with All NConf Fans

Postby fgander » Sat Dec 17, 2011 22:53

Hey!

Great thanks!

I moved your post into the "NConf in action" part, because that better matches ;)

Regards Fabian
F.G. - NConf developer
http://www.nconf.org
Image
Follow NConf on Twitter!
User avatar
fgander
NConf developer
NConf developer
 
Posts: 308
Joined: Mon Mar 16, 2009 14:23
Location: Bern, Switzerland


Return to NConf in action

Who is online

Users browsing this forum: No registered users and 1 guest

cron