Monitoring Web Virtual Hosts

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
miketartaglia
Posts: 5
Joined: Fri Apr 20, 2018 9:38 pm

Monitoring Web Virtual Hosts

Post by miketartaglia »

Below is the sample config I am using to try to monitor a web site. From all my reading I have done, I think this is the right way, however, when verifying the config file (websites.cfg) it doesn't like the check_http -H in the file. I am using Nagios Core 4.1.1. Any help would be appreciated.

Code: Select all

define host{
        use generic-host                ;Inherit default values from a template
        host_name website         ; The name we're giving to this host
        alias http://www.website.com             ; A longer name associated with the host
        address http://www.website.com           ; IP address of the host
         max_check_attempts 3
        contact_groups          admins
        #hostgroups allhosts            ; Host groups this host is associated with
        }

define service{
        use generic-service ; Name of service template to use
        host_name website
        service_description PING
        check_command check_ping!100.0,20%!500.0,60%
        }

define service{
        use generic-service             ; Name of service template to use
        host_name website
        service_description HTTP
        check_command check_http -H http://www.website.com
        notifications_enabled 0
        }
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Monitoring Web Virtual Hosts

Post by mcapra »

We would need to see your command definition for the check_http command to say whether or not this syntax is correct. Remember, the check_command directive of your service definitions references a command definition; Not an actual plugin.

What I suspect is happening is your check_http command definition is already accounting for the host's name via either the -I or -H flag of the check_http plugin. Here's the default command definition (installed via the make install-config step of the official installation documentation) for the check_http command:

Code: Select all

# 'check_http' command definition
define command{
        command_name    check_http
        command_line    $USER1$/check_http -H $HOSTADDRESS$ $ARG1$
        }
Where the $HOSTADDRESS$ macro is inherited from the service definition's parent host definition. Using the example host/service definitions you provided compared against the default check_http command definition:

Code: Select all

define host{
        use generic-host                ;Inherit default values from a template
        host_name website         ; The name we're giving to this host
        alias http://www.website.com             ; A longer name associated with the host
        address http://www.website.com           ; IP address of the host
         max_check_attempts 3
        contact_groups          admins
        #hostgroups allhosts            ; Host groups this host is associated with
        }
define service{
        use generic-service             ; Name of service template to use
        host_name website
        service_description HTTP
        check_command check_http -H http://www.website.com
        notifications_enabled 0
        }
If your command definition for check_http looks like mine, you're essentially passing the -H argument twice: Once via your command definition, then once again via your service definition's check_command directive. Using the above configuration, the actual command that is executed from the command-line would resolve to something like this:

Code: Select all

/path/to/check_http -H http://www.website.com -H http://www.website.com 
Former Nagios employee
https://www.mcapra.com/
miketartaglia
Posts: 5
Joined: Fri Apr 20, 2018 9:38 pm

Re: Monitoring Web Virtual Hosts

Post by miketartaglia »

Here is the check_http part of my command.cfg file.

# 'check_http' command definition
define command{
command_name check_http
command_line $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
}
miketartaglia
Posts: 5
Joined: Fri Apr 20, 2018 9:38 pm

Re: Monitoring Web Virtual Hosts

Post by miketartaglia »

One of the reasons why I am messing around with the check_http configuration is because when the site in question goes down Nagios still thinks it's online. So I thought maybe the default website was responding because the actual website is down.
miketartaglia
Posts: 5
Joined: Fri Apr 20, 2018 9:38 pm

Re: Monitoring Web Virtual Hosts

Post by miketartaglia »

I just denied access to the default website of my apache server and all my URL's that I am monitoring seem to be going to that site. This leads me to believe that the host headers aren't getting there via Nagios maybe? the sites work fine in a browser. What am I missing? Sorry for so many posts. I am new to this forum and I am still waiting for a couple posts to be approved.
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Monitoring Web Virtual Hosts

Post by tgriep »

Your missing the ! Exclamation point in the check command which is used to delineate the arguments for the checks and you also do not need the http:// in the command for the -I and the -H options for the command. The check_http plugin will fill it in for you.

Edit your service check and change this from

Code: Select all

check_command check_http -H http://www.website.com	

to

Code: Select all

check_command check_http!-H www.website.com
Then edit the host check and change this from

Code: Select all

address http://www.website.com           ; IP address of the host
to

Code: Select all

address www.website.com           ; IP address of the host
Save the changes and restart nagios and it should work for you.
If you get any errors, please post them here. Thanks.

https://assets.nagios.com/downloads/nag ... n/toc.html
https://assets.nagios.com/downloads/nag ... vices.html
Be sure to check out our Knowledgebase for helpful articles and solutions!
miketartaglia
Posts: 5
Joined: Fri Apr 20, 2018 9:38 pm

Re: Monitoring Web Virtual Hosts

Post by miketartaglia »

That worked!! Thank you so much!
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Monitoring Web Virtual Hosts

Post by tgriep »

Your welcome. Glad to help. I'll mark the post as solved and lock it. Feel free to open a new post for any other questions in the future.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked