How to monitor Nagwin itself ?

As you use Nagwin to monitor other hosts, you may wonder how the Nagwin itself can be monitored. This can be achieved by checking status.dat file age and existence of key processes. Here is a recipe to establish an out-of-band monitoring of Nagwin:

  • Make sure that your Nagwin installation is configured to send notifications. See FAQ for instructions.
  • Create bin/check_nagwin.sh script with the content below (Unix-format):
#!/bin/bash
# customize - start
server=smtp.server
# customize - end
 
instroot=$(cygpath -m /)
logdir=/var/log/check_nagwin
mkdir -p $logdir
logfile=$logdir/$(date +"%d").log
echo "***" `date` >> $logfile
 
# Function to report failure, message body as argument
CheckFail ()
{
printf "$1" | /bin/blat - -to $to -f $from -subject "Nagwin is not operational" -server $server >> $logfile
exit 1
}
 
# Function to check a process, process name and expected number of instances as arguments
CheckProcess ()
{
/plugins/check_winprocess --filter "imagename eq $1.exe" --compare lt --critical $2 >> $logfile
if (($? > 0)); then
CheckFail "Must be at least $2 $1 process(es) running."
fi
}
 
# check status.dat age
/plugins/check_winfile --target "$instroot/var/opt/nagios/status.dat" --filter "age lt -15 minutes" --critical 1 --compare eq >> $logfile
if (($? > 0)); then
CheckFail "Nagios status.dat getting old."
fi

# check processes

CheckProcess nagios 4
CheckProcess nginx 2
CheckProcess php-cgi 1
CheckProcess cgi2fcgi-wrapper 1
printf "\n" >> $logfile

You need to customize mail configuration (red) according to your setup. The script above checks if status.dat is updated within the last 15 minutes and if key processes are running with an expected number of intances. It will send an e-mail if any of the criteria are not met. Results from checks will be logged in /var/log/check_nagwin directory in a rotating manner for days of a month.

  • Create a Windows scheduled task by using the following command:

schtasks /create /sc minute /mo 15 /tn check-nagwin /tr "nagwin-inst-dir\bin\bash.exe -c /bin/check_nagwin.sh"

This command will create the scheduled task check-nagwin running the script above each 15 minutes.