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.

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? Maybe is it 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!

share|improve this question

4 Answers 4

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.

share|improve this answer

Write a bash script that calls check_http.pl multiple times for every argument passed.

Configure it as your own service type and you're ready to go.

I'm not familiar enough with bash to do this off the top of my head, but some basic bash tutorials will get you basically through all of this easily.

share|improve this answer

The "correct" way to do this is to use check_multi:

http://my-plugin.de/wiki/projects/check_multi/start

Configure a check_multi to call multiple check_http checks at once (see check_http --help and look at the -H and -I flags). You can give it thresholds for how many need to be warn/crit until the multi-service is warn/crit, etc. It's very powerful and flexible.

You could also use check_cluster (this is an old-fasioned way to do it, and it results in lots of extra services littering the nagios web UI). If you wanted to go this route, you can read the official docs about monitoring clusters:

http://nagios.sourceforge.net/docs/3_0/clusters.html

share|improve this answer

Yes it's possible, I blogged about it. Duplicating core stuff here.

You need (1) a script that takes a list of URLs, checks them and returns status codes as appropriate, (2) a Nagios command that uses the script, (3) a host definition that uses the command for checking.

Put the script in /etc/nagios3/check_urls.

Define the command in /etc/nagios3/conf.d/commands.cfg:

define command {
    command_name check_urls
    command_line /etc/nagios3/check_urls $_HOSTURLS$
}

Define the host in /etc/nagios3/conf.d/hosts.cfg:

define host {
    host_name     example-host
    alias         My Example
    address       123.123.123.123
    check_command check_urls
    _urls         my-blog.com,my-api.com/check
}
share|improve this answer
    
Thank for the answer, finally i went with Xymon that fits the customers requirements and in my opinion configuration is easier and simpler than nagios! –  Adrian Perez May 20 '13 at 16:55

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.