Nagios - Is it possible to force check of all hosts by using a command in any given moment?
Solution 1:
The easiest way by far is to simply restart Nagios. Upon a restart it will begin a new checking cycle.
Solution 2:
So i was wondering, is there a way to force check all hosts?
SCHEDULE_FORCED_HOST_SVC_CHECKS
external command is what you're looking for.
To get all of your hosts, take a look at the MK Livestatus:
# echo -e 'GET hosts\nColumns: host_name' | unixcat /usr/local/nagios/var/rw/live
then pipe to the SCHEDULE_FORCED_HOST_SVC_CHECKS
command:
echo -e 'GET hosts\nColumns: host_name' | unixcat /usr/local/nagios/var/rw/live | while read host; do echo "[$(date +%s)] SCHEDULE_FORCED_HOST_SVC_CHECKS;$host;$(date +%s)\n" $(date +%s) >> /usr/local/nagios/var/rw/nagios.cmd; done
Solution 3:
Here's a bash script based on Nagios' sample script and the external command "SCHEDULE_FORCED_HOST_SVC_CHECKS":
#!/bin/sh
# This is a sample shell script showing how you can submit the SCHEDULE_HOST_SVC_CHECKS command
# to Nagios. Adjust variables to fit your environment as necessary.
now=`date +%s` commandfile='/usr/local/nagios/var/rw/nagios.cmd'
for i in hosts/*.cfg
do
SITE=$(grep host_name $i | head -1 | sed 's/host_name//' | tr -d '[:blank:]')
/usr/bin/printf "[%lu] SCHEDULE_HOST_SVC_CHECKS;${SITE};1110741500\n" $now > $commandfile
done