Jan/100
Nagios Init-Script verifyconfig with verbose output
Did you ever wanted to restart your Nagios process and got the following message after a change to the Nagios configuration?:
CONFIG ERROR! Check your Nagios configuration.
If you changed anything in a Nagios configuration file at least once in your lifetime I am sure you know that message. Now what to do? If you are experienced with this error message you know what to do: Run the Nagios binary with the -v (verifyconfig) parameter. Mostly the command looks like this:
:> /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Having the command output you can easily find the source of the problem in your Nagios configuration.
But wait! Why is it so complicated?
As I am working for a long time with Nagios I recognized it is always the same: You change your Nagios configuration, then restart the daemon with /etc/init.d/nagios restart or reload. In cases of a broken configuration you see the config error message mentioned below. Then you need to put the whole path to the Nagios binary and configuration to get the configuration diagnostic output for easier configuration debugging. This is too complicated!
So I always extend the default Nagios init Script with the following patch to get a new command line parameter. The default Nagios Init-Script serves a paramater checkconfig. With this parameter you get one line as output (OK or CONFIG ERROR). But you get no details about the source of the problem in your Nagios configuration. It is interesting to know that the script calls the Nagios binary with the verifyconfig flag while simply suppressing the complete output and only using the exit code of the program.
So it is a quick win to get the whole output of the configuration check right out of the Init Script. Since I did not want to break up with the behaviour of the current parameter which could be used by any script out there in the world I added a new paramater checkconfig-verbose which does not suppress the output of the Nagios configuration validation.
The Init-Script Patch
--- daemon-init.in 2010-01-04 14:04:04.000000000 +0100 +++ daemon-init.in.new 2010-01-04 13:47:45.000000000 +0100 @@ -173,13 +173,14 @@ printstatus_nagios nagios ;; - checkconfig) + checkconfig|checkconfig-verbose) printf "Running configuration check..." - $NagiosBin -v $NagiosCfgFile > /dev/null 2>&1; + out=`$NagiosBin -v $NagiosCfgFile 2>&1` if [ $? -eq 0 ]; then echo " OK." else echo " CONFIG ERROR! Check your Nagios configuration." + echo "$out" exit 1 fi ;; @@ -222,7 +223,7 @@ ;; *) - echo "Usage: nagios {start|stop|restart|reload|force-reload|status|checkconfig}" + echo "Usage: nagios {start|stop|restart|reload|force-reload|status|checkconfig|checkconfig-verbose}" exit 1 ;;
Applying The Patch
To apply the patch simply paste the code to a file called e.g. daemon-init-checkconfig-verbose.patch in the source directory of Nagios. Then run
:> patch < daemon-init-checkconfig-verbose.patch
After that you need to re-run the
:> ./configure # (don't forget to re-add the paramaters which are needed in your setup)
command and then run
:> make install-init
to have the patched init script installed.
Now you can simply run
:> /etc/init.d/nagios checkconfig-verbose
to see the full Nagios configuration debug output.






