Check_HTTP query

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.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Check_HTTP query

Post by tmcdonald »

Is he looking for something dynamic? I am not sure how you can make a HTTP call without a host.
Former Nagios employee
neworderfac33
Posts: 329
Joined: Fri Jul 24, 2015 11:04 am

Re: Check_HTTP query

Post by neworderfac33 »

I think so, yes - we have the ability to base a website on any one of a number of different servers, so he wants the active website, without having to point to the server that it's running on.

I thought it was a bit ambitious! :-)

Pete
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Check_HTTP query

Post by mcapra »

Assuming the Core server can resolve the hostname and the hostname is consistent, you should be able to do something like this:

Code: Select all

./check_http -H www.example.com
And put that Service check under the example.com Host, for example. This would change your command definition slightly using -H instead of -I:

Code: Select all


define command{
        command_name    check_http_url
        command_line    $USER1$/check_http -H $HOSTADDRESS$ -u $ARG1$
}
And you would have to keep in mind that any Host definitions with Service checks using this Command should use a hostname or FQDN (that can be resolved by the Core server) as the host's address .

Code: Select all

host_name                       www.example.com
address                         www.example.com
When you put it all together, you get something that looks like this (copy+pasting maybe not a good idea ;)):

Code: Select all


define command{
        command_name    check_http_url
        command_line    $USER1$/check_http -H $HOSTADDRESS$ -u $ARG1$
}
define service{
        use                     generic-service
        host_name               MyServerID
        #hostgroup_name          url011u
        service_description     URL http://MyURL + Text [Country of Residence] + Status [301] + Port [8001]
        check_command           check_http_url!MyURL -s "Country of Residence" --expect=301 -p 8001
        #register                0
        }
define host{
	host_name			www.example.com
	address			www.example.com
	max_check_attempts		5
	check_period			24x7
	contact_groups			contact_group
	notification_period		24x7
	}

Former Nagios employee
https://www.mcapra.com/
neworderfac33
Posts: 329
Joined: Fri Jul 24, 2015 11:04 am

Re: Check_HTTP query

Post by neworderfac33 »

It would appear after lots of research that what I need is something called check_url, as referenced by a possible solution to my problem at
http://stackoverflow.com/questions/9246 ... ith-nagios

but when I created check_url.pl using the code found at:

Code: Select all

https://exchange.nagios.org/directory/Plugins/Websites,-Forms-and-Transactions/check_url/details
and attempted to run it, I got:

Code: Select all

syntax error at ./check_url.pl line 49, near "= ;"
Execution of ./check_url.pl aborted due to compilation errors.
I know you don't normally provide support for plugins, but I was just wondering if I'd created this.pl file correctly by simply copying and pasting the code from the web page to VIM on my Nagios master and saving it as check_url.pl?

Thanks in advance

Pete
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Check_HTTP query

Post by rkennedy »

I don't think check_url is the solution, as all it's doing is using a different variable for -H rather then $HOSTADDRESS$. I believe what @mcapra posted above is what you are looking for, the -I variable will let you specify which server to request the hostname on.
Former Nagios Employee
bwallace
Posts: 1146
Joined: Tue Nov 17, 2015 1:57 pm

Re: Check_HTTP query

Post by bwallace »

Also, about importing a new plugin, place it in /usr/local/nagios/libexec and make sure permissions are similar to this default plugin:

Code: Select all

-rwxr-xr-x 1 nagios nagios 401800 Dec 30  2015 check_http
Be sure to check out the Knowledgebase for helpful articles and solutions!
neworderfac33
Posts: 329
Joined: Fri Jul 24, 2015 11:04 am

Re: Check_HTTP query

Post by neworderfac33 »

Apologies to mcapra - I started my last post before yours, but submitted it without noticing that you'd posted in the meantime!

I'll take a good look and let you know how I get on.

Thank you

Pete
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Check_HTTP query

Post by rkennedy »

Let us know how it goes!
Former Nagios Employee
neworderfac33
Posts: 329
Joined: Fri Jul 24, 2015 11:04 am

Re: Check_HTTP query

Post by neworderfac33 »

Good afternoon,

With your valuable help, I've now been able to remove the dependence on a Host ID, replacing it with a website and a URL thus:

Code: Select all

./check_http -H MyWebsite.com -u /MyURL/ --expect=200
It correctly reports OK when the status is 200 (and Critical when i set it to anything else) but apart from returning OK for single characters, won't report the presence of a string in the webpage content.
I have used the Fiddler tool to look at the web page content and i can see that the string I'm searching for is present, so i was wondering if there was any way in which i could capture the whole content of the webpage somewhere (either to console or maybe a file) to further examine it to see if what I THINK I'm looking at is what I'm ACTUALLY looking at.

FYI,

./check_http -H MyWebsite.com -u /MyURL/ --expect=200 -s "Cache"

returns:

HTTP CRITICAL: Status line output matched "200" - string 'Cache' not found on 'MyWebsite.com:80MyURL' - 374 bytes in 0.016 second response time |time=0.015948s;;;0.000000 size=374B;;;0
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Check_HTTP query

Post by mcapra »

Try running check_http in verbose mode with -v. This should output exactly what check_http is looking at.
Former Nagios employee
https://www.mcapra.com/
Locked