I have created a simple Check & restart script for Nagios..
It does the "nagios -v .. check" and if errors found, it will report which cfg files and which lines.. If none found it will restart with a 5 seconds timer (in case you regret).
I was looking for something like this to make it easier to "test/restart" when I started using nagios, so I thought I would share it with you.
/usr/local/bin/nagios-reload
Code: Select all
#/bin/bash
# Restart Script - Trazzdk november 2014
# Simple Nagios reload/restart script
# Load nagios cfg files into the variable nagios_err
nagios_err=$(/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg)
# Total Warnings and Errors into variables.. and cfg error into variable
total_warnings_flag=$(echo "$nagios_err"|grep "Total Warnings"|awk '{print $3}')
total_errors_flag=$(echo "$nagios_err"|grep "Total Errors"|awk '{print $3}')
cfg_err=$(echo "$nagios_err"|grep Error:)
# If Total Warnings & Total Errors == 0, restart nagios
if [ "$total_errors_flag" == 0 ] && [ "$total_warnings_flag" == 0 ] ; then
echo -e "\033[33;32mEverything is fine!\033[0m"
echo "Will proceed by restarting nagios in 5 seconds"
# All OK, restart nagios
for i in {5..1};do echo -n "$i.." && sleep 1; done
/etc/init.d/nagios restart
# If errors found, abort and tell wich cfg file has trouble
else
echo -e "\033[33;31m You have Errors, so we will abort this operation\033[0m"
echo "$cfg_err"
fi