Page 2 of 5
Re: Check_HTTP query
Posted: Tue Jul 26, 2016 9:57 am
by tmcdonald
Is he looking for something dynamic? I am not sure how you can make a HTTP call without a host.
Re: Check_HTTP query
Posted: Tue Jul 26, 2016 2:12 pm
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
Re: Check_HTTP query
Posted: Wed Jul 27, 2016 9:12 am
by mcapra
Assuming the Core server can resolve the hostname and the hostname is consistent, you should be able to do something like this:
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
}
Re: Check_HTTP query
Posted: Wed Jul 27, 2016 9:55 am
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
Re: Check_HTTP query
Posted: Wed Jul 27, 2016 10:19 am
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.
Re: Check_HTTP query
Posted: Wed Jul 27, 2016 10:31 am
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
Re: Check_HTTP query
Posted: Wed Jul 27, 2016 10:39 am
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
Re: Check_HTTP query
Posted: Wed Jul 27, 2016 1:49 pm
by rkennedy
Let us know how it goes!
Re: Check_HTTP query
Posted: Fri Jul 29, 2016 7:48 am
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
Re: Check_HTTP query
Posted: Fri Jul 29, 2016 9:32 am
by mcapra
Try running check_http in verbose mode with -v. This should output exactly what check_http is looking at.