Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a way to initiate a check of all services in a service group from either the Nagios web GUI or via the command line?

For example, I have a service group with a check that runs on 30 machines. I'd like to initiate a command that would force the check on all of those 30 machines. I know you can do it via the GUI on a single machine, but it would be great if it could be done against an entire service group.

share|improve this question

1 Answer 1

I am not aware of any way through the standard GUI to accomplish this.

But one thing you can do is install the livestatus module. This module makes Nagios listen on a socket, and you can run queries against it, and retrieve information. With this API enabled you should then be able write a script that gets information about the servicegroup, and then runs a series of commands.

Your system must also have External Commands enabled. Livestatus is how you get information out. External commands is how you send in your requests for an action to be performed.

This example script might be able to get you started. This script sends a query to live status to find all hosts with a non OK state. It then forces an immediate re-check for each host host found in this state.

#!/bin/bash
LIVESTATUSSOCKET=/var/lib/nagios3/rw/live
NAGIOS_CMD_SOCKET='/var/lib/nagios3/rw/nagios.cmd'

export IFS=';'
echo "GET hosts
Columns: state host_name
Filter: state != 0
" | unixcat $LIVESTATUSSOCKET \
  | (

  while read -a LINE ; do
     /usr/bin/printf "[%lu] SCHEDULE_HOST_CHECK;%s;%s\n" \
                      $(date +%s) \
                      "${LINE[1]}" \
                      $(date +%s) | tee -a $NAGIOS_CMD_SOCKET
  done
)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.