Page 2 of 3
Re: Issue with check_http
Posted: Thu Dec 07, 2017 2:09 pm
by npolovenko
@t3dus, This worked for me. Just create a new configuration file myhost.conf in /usr/local/nagios/etc/objects. And paste the following definitions inside the file. After that import this file in /usr/local/nagios/etc/nagios.cfg and restart nagios with
service nagios restart.
Code: Select all
define host {
host_name www.snapgeek.com
address www.snapgeek.com
max_check_attempts 5
check_interval 5
retry_interval 1
check_period 24x7
contacts nagiosadmin
check_command check_http_test!/meet-matt/!Iowa
notification_interval 60
notification_period 24x7
}
define command{
command_name check_http_test
command_line $USER1$/check_http -H $HOSTADDRESS$ -u $ARG1$ -R $ARGS2$ -f follow
define service{
use generic-service ; Name of service template to use
host_name www.snapgeek.com
service_description URL test
check_command check_http_test!/meet-matt/!Iowa
notifications_enabled 0
}
}
PS: You may also delete the service definition as I inserted the same http check in the host definition.
Re: Issue with check_http
Posted: Thu Dec 07, 2017 3:04 pm
by t3dus
Did some testing with your code which seems to work until I did a test where I tried to get it to fail on purpose but it doesn't.
It needs to fail when the keyword isn't present such as if the website was defaced or something.
Below is what I did..
Code: Select all
define host {
host_name snapgeek.com
address snapgeek.com
max_check_attempts 5
check_interval 5
retry_interval 1
check_period 24x7
contacts nagiosadmin
# check_command check_http_test2!/meet-matt/!Iowa
notification_interval 60
notification_period 24x7
}
define command{
command_name check_http_test2
command_line $USER1$/check_http -H $HOSTADDRESS$ -u $ARG1$ -R $ARGS2$ -f follow
}
define command{
command_name check_http_test3
command_line $USER1$/check_http -H $HOSTADDRESS$ -u $ARG1$ -R $ARGS2$ -f follow
}
define command{
command_name check_http_test4
command_line $USER1$/check_http -H $HOSTADDRESS$ -R $ARGS2$ -f follow
}
define service{
use generic-service ; Name of service template to use
host_name snapgeek.com
service_description PING
check_command check_ping!1000.0,80%!5000.0,100%
notifications_enabled 1
}
define service{
use generic-service ; Name of service template to use
host_name snapgeek.com
service_description URL good
check_command check_http_test2!/meet-matt/!Iowa
notifications_enabled 1
}
define service{
use generic-service ; Name of service template to use
host_name snapgeek.com
service_description URL fail on purpose
check_command check_http_test3!/meet-matt/!failtest
notifications_enabled 1
}
define service{
use generic-service ; Name of service template to use
host_name snapgeek.com
service_description Url Test 4
check_command check_http_test4!!2017
notifications_enabled 0
}
Only code I didn't include above is my SSL code because it's not needed for the case at hand.
Re: Issue with check_http
Posted: Thu Dec 07, 2017 9:32 pm
by t3dus
I've tried it every way I can think of.
The Only way I can get it to actually check the string and generate an error when the string is missing from the site is to setup the code like this. Every other way I try it doesn't give an error when the string doesn't match the site.
Clearly something wrong with the way nagios checks this if I can't do it any other way to make it work...
Code: Select all
define command{
command_name check_http_sg
command_line $USER1$/check_http -H snapgeek.com -u /meet-matt/ -R "2017"
}
define service{
use generic-service ; Name of service template to use
host_name snapgeek.com
service_description Keyword
check_command check_http_sg
notifications_enabled 1
}
If I use the below code then I can put ANY KEYWORD in there at all even if it doesn't exist on the site and the check will not fail! This is a huge bug on Nagios end!
Code: Select all
define command{
command_name check_http_test
command_line $USER1$/check_http -H $HOSTADDRESS$ -u $ARG1$ -R $ARGS2$
}
define service{
use generic-service ; Name of service template to use
host_name snapgeek.com
service_description URL test
check_command check_http_test!/meet-matt/!2017
notifications_enabled 1
}
Re: Issue with check_http
Posted: Thu Dec 07, 2017 10:53 pm
by tacolover101
what happens if you put your -u '/meet-matt/' in quotes?
also, why use -R when you can use -s? it doesn't appear your trying to match regex at all.
Code: Select all
-s, --string=STRING
String to expect in the content
Re: Issue with check_http
Posted: Thu Dec 07, 2017 11:01 pm
by t3dus
tacolover101 wrote:what happens if you put your -u '/meet-matt/' in quotes?
also, why use -R when you can use -s? it doesn't appear your trying to match regex at all.
Code: Select all
-s, --string=STRING
String to expect in the content
I'm not sure I even care to use the -u either anymore. I just want it to check text on the main site of my domains to see if it exists. I'll try a -s one and see where that goes.
Re: Issue with check_http
Posted: Thu Dec 07, 2017 11:15 pm
by t3dus
this works
Code: Select all
/usr/lib/nagios/plugins/check_http -H fairfieldgeeks.com --ssl -u / -s "forum"
this doesn't..
Code: Select all
/usr/lib/nagios/plugins/check_http -H fairfieldgeeks.com -u / -s "forum"
for some reason I noticed I need the --ssl for certain sites too. Perhaps I should be using it regardless since all my sites have SSL.
This one works great.. If I change "phpbb" to something that doesn't exist on the site it will error like i want..
Code: Select all
define command{
command_name check_http_ffg
command_line $USER1$/check_http -H fairfieldgeeks.com --ssl -u / -R "phpBB"
}
define service{
use generic-service ; Name of service template to use
host_name fairfieldgeeks.com
service_description Keyword
check_command check_http_ffg
notifications_enabled 1
}
This one says the site is ok. As expected if I change the "phpBB" to "thisisanerror" it will error out with: HTTP CRITICAL: HTTP/1.1 200 OK - string 'thisisanerror' not found on '
https://fairfieldgeeks.com:443/' - 40840 bytes in 2.617 second response time
Code: Select all
define command{
command_name check_http_ff
command_line $USER1$/check_http -H fairfieldgeeks.com --ssl -u / -s "phpBB"
}
define service{
use generic-service ; Name of service template to use
host_name fairfieldgeeks.com
service_description Keyword test1
check_command check_http_ff
notifications_enabled 1
}
This one errors out from the get go.. with "HTTP CRITICAL: HTTP/1.1 400 Bad Request - string '$' not found on '
https://fairfieldgeeks.com:443$' - 1383 bytes in 0.285 second response time" so yeah..
Code: Select all
define command{
command_name check_http_ff2
command_line $USER1$/check_http -H fairfieldgeeks.com --ssl -u $ARGS1$ -s $ARGS2$
}
define service{
use generic-service ; Name of service template to use
host_name fairfieldgeeks.com
service_description Keyword test2
check_command check_http_ff2!/!phpBB
notifications_enabled 1
}
Re: Issue with check_http
Posted: Fri Dec 08, 2017 10:40 am
by tmcdonald
You have a typo in your configs. It should be $ARG1$ and $ARG2$ but you have $ARGS1$ and $ARGS2$ (plural). That is why you are seeing the string '$' not found message in the output, because Core does not recognize $ARGSn$ as a valid macro, but as a literal string.
Re: Issue with check_http
Posted: Fri Dec 08, 2017 11:29 am
by t3dus
That seems to of fixed things up a bit.
My next question is how exactly does nagios go to look for strings because some strings I have used are ON the site yet it fails to find them while it can find others.
Also I seem to have to use either --ssl or -f follow otherwise these checks fail still.
Re: Issue with check_http
Posted: Fri Dec 08, 2017 11:35 am
by tmcdonald
t3dus wrote:My next question is how exactly does nagios go to look for strings because some strings I have used are ON the site yet it fails to find them while it can find others.
Usually when this happens it is because the string is populated by a Javascript call, or is otherwise not present in the raw text returned from the HTTP call.
check_http only parses the exact text, it does not have any JS engine embedded to handle dynamic page-building.
t3dus wrote:Also I seem to have to use either --ssl or -f follow otherwise these checks fail still.
-f follow is fairly common to have, particularly in pages that do a lot of routing like WordPress does. It's just telling
check_http to follow a redirect instead of treating it as a non-OK state. The
--ssl should only be needed for HTTPS sites.
Re: Issue with check_http
Posted: Fri Dec 08, 2017 11:48 am
by t3dus
tmcdonald wrote:t3dus wrote:Also I seem to have to use either --ssl or -f follow otherwise these checks fail still.
-f follow is fairly common to have, particularly in pages that do a lot of routing like WordPress does. It's just telling
check_http to follow a redirect instead of treating it as a non-OK state. The
--ssl should only be needed for HTTP sites.
Ok so I see how -f follow is important in my case. So --ssl for HTTP not HTTPS? All my websites use HTTPS