Nagios check all services script
If you’re running a Nagios server, sometimes you may want to check all services across all of your hosts. As of the time of writing, Nagios doesn’t have a built in feature to do this.
However, there is one way to force a recheck of all services across all hosts using bash.
The script makes use of two special nagios files:
/var/log/nagios/status.dat
/var/spool/nagios/cmd/nagios.cmd
The status.dat file holds the current state of the Nagios system, including all host and service states.
The nagios.cmd file is a pipe file in which you can send commands to.
Please check those paths are valid on your filesystem and, in necessary, update the script with the new paths.
The following is a bash script, which, when run without any arguments, will re-check all services across all hosts that you are monitoring:
#!/usr/bin/env bash
### This program will run a check on all services on all hosts immediately.
array_of_hosts_with_dups=()
for temp_host in `cat /var/log/nagios/status.dat | egrep 'host_name'`; do
fixed_host=$(echo $temp_host | sed -e 's/host_name=//g' | sed -e 's/^[ \t]*//');
array_of_hosts_with_dups+=($fixed_host)
done
### This removes all duplicates
array_of_unique_hosts=($(for v in "${array_of_hosts_with_dups[@]}"; do echo "$v";done| sort| uniq| xargs))
### Print out list of unique hosts
### Do a scheduled forced recheck of all hosts in array_of_unique_hosts
for uniquehost in "${array_of_unique_hosts[@]}"
do
echo $uniquehost
/bin/printf "[%lu] SCHEDULE_FORCED_HOST_SVC_CHECKS;$uniquehost;1110741500\n" $now > /var/spool/nagios/cmd/nagios.cmd
done
Recent Comments