Force check on all hosts on nagios
I had a minor problem with my nagios server – the clock got off by a few months. After correcting the clock, nagios would not check the status of any host for a few months because database said it wasnt time to do so . To correct without having to click on every single hosts and force a check, I used the following script:
#!/bin/sh
# you man need to adjust the locaton of the nagios.cmd file depending on your configuration
now=`date +%s` commandfile='/var/spool/nagios/cmd/nagios.cmd'
# you man need to adjust the location of your hosts.cfg files depending on youyr installation
for i in /etc/nagios/hosts/*.cfg
do
SITE=$(grep host_name $i | head -1 | sed 's/host_name//' | tr -d '[:blank:]')
/usr/bin/printf "[%lu] SCHEDULE_FORCED_HOST_CHECK;${SITE};1110741500\n" $now > $commandfile
done
Tested on Fedora 37 and nagios 4.4.9