Nagios check_http checking private IP

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
srikanthm
Posts: 2
Joined: Fri Mar 06, 2015 1:20 am

Nagios check_http checking private IP

Post by srikanthm »

Hi I set up two hosts (host1, host2) and check_http service for each and when I test them:

Code: Select all

# ./check_http -H host1publicIP -p 9080 -w 5 -c 10
HTTP OK: HTTP/1.1 200 OK - 7909 bytes in 0.002 second response time |time=0.001918s;5.000000;10.000000;0.000000 size=7909B;;;0


When I added the new host - host2, I copied the above service and changed the ip and port to the new service. When I test it - works fine as below:

Code: Select all

# ./check_http -H host2publicIP -p 8080 -w 5 -c 10
HTTP OK: HTTP/1.1 200 OK - 7909 bytes in 0.003 second response time |time=0.002571s;5.000000;10.000000;0.000000 size=7909B;;;0
But when the command is executed as part of the nagios service - I get an error for host2 service:

Code: Select all

connect to address host2privateIP and port 8080: Connection refused
HTTP CRITICAL - Unable to open TCP socket
I do not have any problem with host1: check_http or other services of host2 - only check_http fails.

Here are the complete service descriptions:

host 1:

Code: Select all

define service{
        use                     generic-service
        host_name               host1
        service_description     DEMO-APP
        check_command           check_http!-H host1publicIP -p 9080 -u http://host1publicIP:9080/login/auth -w 5 -c 10
        max_check_attempts      1
        contact_groups          Escalation
        }
host 2:

Code: Select all

define service{
        use                     generic-service
        host_name               host2
        service_description     APP1
        check_command           check_http!-H host2publicIP -p 8080 -u http://host2publicIP:8080/login/auth -w 5 -c 10
        contact_groups          Escalation
        max_check_attempts      1
        }
Based on the error, nagios is trying to connect using private IP rather than public IP provided??
To verify this, I tested using the private IP and got the same error at prompt:

Code: Select all

# ./check_http -H host2privateIP -p 8080 -w 5 -c 10
connect to address host2privateIP and port 8080: Connection refused
HTTP CRITICAL - Unable to open TCP socket
Anybody can advise how to fix this??

thanks in advance.
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Nagios check_http checking private IP

Post by jdalrymple »

You'll either need to modify your command definition for check_http to use your arguments or modify your host definition to have the public IP of the machine. The check by default uses the macro $HOSTADDRESS$ which presumably is your private IP.

As an aside, the -H argument isn't used in the check_http plugin.
srikanthm
Posts: 2
Joined: Fri Mar 06, 2015 1:20 am

Re: Nagios check_http checking private IP

Post by srikanthm »

jdalrymple, thanks for your quick response.

I tried playing with the command in different ways and solved the issue. Instead of "-H" I used "-I" and it worked.

But still the big question why it works for one host but not other is not answered.

Also -H argument is available according to usage help, atleast in the version I am using:

Code: Select all

Usage:
 check_http[b] -H <vhost>[/b] | -I <IP-address> [-u <uri>] [-p <port>]
       [-J <client certificate file>] [-K <private key>]
       [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]
       [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]
       [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]
       [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]
       [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]
       [-T <content-type>] [-j method]
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Nagios check_http checking private IP

Post by jdalrymple »

Sorry, I was unclear: -H i s available, it's just not really used.

Code: Select all

define command {
       command_name                             check_http
       command_line                             $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
}
I can't be certain that this is what your command looks like, but it is likely. This is what Nagios actually *does* to check your http server.
$HOSTADDRESS$ expands to the IP of the host you're checking
$ARG1$ expands as everything between the 1st and 2nd "!" symbol in your check_command

Based upon the initial service definitions you provided...
For host 1 the actual command being ran to check your host is:

Code: Select all

/somepath/check_http -I <host1-some-IP> -H <host1-pub-IP> -p 9080 -u http://host1publicIP:9080/login/auth -w 5 -c 10
For host 2 the actual command being ran to check your host is:

Code: Select all

/somepath/check_http -I <host2-some-IP> -H <host2-pub-IP> -p 8080 -u http://host2publicIP:8080/login/auth -w 5 -c 10
Perhaps you would get more predictable results based upon your command definitions if you removed the "-I $HOSTADDRESS$" portion of the command definition.
Locked