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