Monitor multiple webs within a server in nagios

monitoringnagios

I would like to monitor/test multiple virtual hosts in an Apache Webserver and besides, I would like that these checks appears as a one service in Nagios -> HTTP. And if one of the web/URL fails, the service appears as failed/alarm. I dont know if it's possible.

i've installed Nagios in another server and i want to check if the webs are answering status code 200.

So, the question is, nagios could be configurated to check multiple websites in the same service?
Is it maybe possible to set multiple check_command in a service?

check_command   check_httpv!google.com
check_command   check_httpv!gmail.com

How are you monitoring virtual hosts in nagios? are you creating a service per website?

Regards and thank you in advance!

Best Answer

check_http can only check one site at a time. If you need to check multiple sites in a single service check, you would need to write your own check to implement the logic. This could easily be done in a simple shell script that calls check_http for each virtual host and returns the appropriate failure code to Nagios if any of the check_http executions are unsuccessful. Such a script might look like the following.

#!/bin/sh

for HOST in $* ; do
   check_http -H $HOST [...other args...] >/dev/null 
   if [ $? -ne 0 ] ; then
      echo "$HOST not responding"
      exit 2
   fi
done
echo "All hosts ok"
exit 0

Alternatively, you may be able to use Nagios' service dependencies to reach your goal. Assume for the moment that you wish to check all of your Apache virtual hosts but not be flooded with a notification for each one if the Apache process is not available. This would allow you to see the status detail of each virtual host, allow for more fine grained reporting, and let you have different notification and time period options.

To implement this you would create a service check for each virtual host, then create one check for Apache, presumably by using check_http to check via the IP address and make sure something is listening on port 80.

Next you would create service dependencies for each virtual host's service check and configure them to be dependent on the Apache check. If the Apache check fails, all of the virtual host checks (which depend on the Apache check) will stop sending notifications and/or executing checks until the Apache check recovers.