cron for updating the nagios config with NConf generated one

Everything else...
Locked
mboeru
starter
starter
Posts:2
Joined:Sat Apr 04, 2009 20:36
cron for updating the nagios config with NConf generated one

Post by mboeru » Sat Apr 04, 2009 20:47

Hi,
I'm Zen from the other topics :)

I made a small script to automaticly deploy the generated confs from NConf and thought until this will be done from the interface you guys could use it. So here it is:

Code: Select all

#!/bin/bash

CFOLDER=/var/www/html/nconf/output/        # Generated config folder
CFILE=NagiosConfig.tgz 			           # Generated config name
NACONFDIR=/etc/nagios			          # Actual Nagios config dir
NACONFMAINFILE=/etc/nagios/nagios.cfg           # Nagios  Main Config File

if [ -e ${CFOLDER}${CFILE} ] ; then
		tar --overwrite -xzvf ${CFOLDER}${CFILE} -C $NACONFDIR
		NABIN=`which nagios`
		ERRORS=`$NABIN -v $NACONFMAINFILE | grep "Total Errors:" | cut -d: -f2 | sed -e"s/ //g"`
		if [ "$ERRORS" == "0" ] ; then
			/etc/init.d/nagios restart
			mv ${CFOLDER}${CFILE} ${CFOLDER}${CFILE}.`date +'%Y%m%d'`
		else echo Errors
		fi

fi
put this code into a new file. Be sure to modify the paths at the beginning with what corresponds with your setup.
do a chmod +x filename on the file

then run crontab -e
and add a silimar line:
*/5 * * * * /path/to/filename

Now every 5 minutes the script will look for new generated configs and put the into nagios. Then checks if there are errors and if there aren't it restarts nagios.

Hope this will help some of you and hope it's ok that I post it here :)

User avatar
agargiulo
NConf developer
NConf developer
Posts:725
Joined:Fri Mar 06, 2009 17:50
Location:Zurich, Switzerland
Contact:

Re: cron for updating the nagios config with NConf generated one

Post by agargiulo » Mon Apr 06, 2009 09:33

Thanks Zen.

With the next release we will supply a similar script to add to crontab.

Regards,
Angelo

Guest

Re: cron for updating the nagios config with NConf generated one

Post by Guest » Tue Apr 14, 2009 08:13

Thx Zen.

I have a newbie's question : A reload of Nagios configuration is not enougth ? Or restart is necessary (very slow on big config)?

User avatar
linux-onkel
beginner
beginner
Posts:7
Joined:Tue Mar 10, 2009 15:32
Location:Offenburg, Germany
Contact:

Re: cron for updating the nagios config with NConf generated one

Post by linux-onkel » Tue Apr 14, 2009 09:47

Guest wrote:I have a newbie's question : A reload of Nagios configuration is not enougth ? Or restart is necessary (very slow on big config)?
Hi Guest,

A reload only loads the new config into a running nagios process. If you have an error in your config files (maybe you have some non-nconf configs in it) nagios will be running with the old config.
A restart first stops the running nagios-process and then tries to start with the new config. On an error this startup will fail. Nagios will not run.

Regards
Steffen
Image


Locked