Page 1 of 3

Issue with check_http

Posted: Wed Dec 06, 2017 2:52 pm
by t3dus
I have a really annoying issue with check_http that I can't figure out for the life of me.

I want to use check_http to check a string but I can't get it to work when I define the string in the host file. It only works when I define it in the commands.cfg file which is super frustrating for me.

I hope somebody can tell me what i'm doing wrong because i can't figure it out.

So this works..
commands.cfg entry

Code: Select all

define command{
        command_name    check_http_test
        command_line    $USER1$/check_http -H snapgeek.com -u /meet-matt/ -R "Iowa"
}
hostfile entry

Code: Select all

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       snapgeek.com
        service_description             check_http_test
        check_command                   check_http_test
        notifications_enabled           0
        }
This doesnt..
commands.cfg

Code: Select all

define command{
        command_name    check_http_content3
        command_line    $USER1$/check_http -H $HOSTADDRESS$ -u $ARG1$ -R $ARG1$
}
Hostfile.cfg (example 1)

Code: Select all

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       snapgeek.com
        service_description             check_http_content3
       check_command                   check_http_content3! -u /meet-matt -R Iowa
        notifications_enabled           0
        }
Hostfile.cfg (example 2)

Code: Select all

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       snapgeek.com
        service_description             check_http_content3
       check_command                   check_http_content3! -H snapgeek.com -u /meet-matt -R Iowa
        notifications_enabled           0
        }
Hostfile.cfg (example 3)

Code: Select all

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       snapgeek.com
        service_description             check_http_content3
       check_command                   check_http_content3! -H snapgeek.com -R 2017
        notifications_enabled           0
        }
Hostfile.cfg (example 4)

Code: Select all

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       snapgeek.com
        service_description             check_http_content3
       check_command                   check_http_content3! -R 2017
        notifications_enabled           0
        }
Also if I leave off the ! in "check_http_content3!" then the check config throws errors..

Re: Issue with check_http

Posted: Wed Dec 06, 2017 5:37 pm
by npolovenko
Hello, @t3dus . If you have -u -R in the command definition, you shouldn't use these characters again in the service definition.

Code: Select all

command_line    $USER1$/check_http -H $HOSTADDRESS$ -u $ARG1$ -R $ARG1$

Code: Select all

 check_command                   check_http_content3!/meet-matt/!Iowa
Or you may change the things around:

Code: Select all

command_line    $USER1$/check_http -H $HOSTADDRESS$ $ARG1$ $ARG1$

Code: Select all

check_http_content3! -u /meet-matt -R Iowa
Hope this makes sense.

Re: Issue with check_http

Posted: Wed Dec 06, 2017 6:30 pm
by t3dus
That actually makes total sense.. I was just too frustrated and blind to see it earlier.. :lol:

Re: Issue with check_http

Posted: Wed Dec 06, 2017 6:53 pm
by t3dus
Still getting an error.

Code: Select all

HTTP CRITICAL: HTTP/1.1 301 Moved Permanently - pattern not found - 247 bytes in 0.812 second response time 
I went with your 2nd example cuz i liked that I can define the switched at the host file.

Code: Select all

define command{
        command_name    check_http_content
        command_line    $USER1$/check_http -H $HOSTADDRESS$ $ARG1$ $ARG1$
}

Code: Select all

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       snapgeek.com
        service_description             URL Check
        check_command                   check_http_content! -u /meet-matt -R Iowa
        notifications_enabled           1
        }
Guess I'll try the 1st example and see if I have better luck.

Re: Issue with check_http

Posted: Wed Dec 06, 2017 10:45 pm
by t3dus
Seems the check works for static sites but not wordpress or phpbb sites.

Re: Issue with check_http

Posted: Thu Dec 07, 2017 7:25 am
by danjoh
command_line $USER1$/check_http -H $HOSTADDRESS$ $ARG1$ $ARG1$
You are aware that you have $ARG1$ two times on the command line?
The above will evaluate to:

Code: Select all

$USER1$/check_http -H snapgeek.com -u /meet-matt -R Iowa -u /meet-matt -R Iowa

Re: Issue with check_http

Posted: Thu Dec 07, 2017 11:13 am
by t3dus
What do I do if I want to use the following

Code: Select all

command_line    $USER1$/check_http -H $HOSTADDRESS$ -u $ARG1$ -R $ARG1$

Code: Select all

 check_command                   check_http_content3!/meet-matt/!Iowa
but not define the -u? like below.. I tried to just leave out the "-u $ARG1$" from the the check and the "meet-matt." but it fails to work.

Code: Select all

command_line    $USER1$/check_http -H $HOSTADDRESS$  -R $ARG1$

Code: Select all

 check_command                   check_http_content3!!Iowa
This just fails to work entirely for some unknown reason..

Code: Select all

command_line    $USER1$/check_http -H $HOSTADDRESS$ $ARG1$ $ARG1$

Code: Select all

check_http_content3! -u /meet-matt -R Iowa
but this works and I don't think it should cuz i don't think it's actually checking the string since it's not defined.

Code: Select all

command_line    $USER1$/check_http -H $HOSTADDRESS$ $ARG1$

Code: Select all

check_http_content3!!Iowa
I tried the above like this but it nets a "Usage:" error that's blank.

Code: Select all

command_line    $USER1$/check_http -H $HOSTADDRESS$ -R $ARG1$

Code: Select all

check_http_content3!!Iowa

Re: Issue with check_http

Posted: Thu Dec 07, 2017 11:19 am
by t3dus
I thought this was working

Code: Select all

command_line    $USER1$/check_http -H $HOSTADDRESS$ -u $ARG1$ -R $ARG1$

Code: Select all

check_command                   check_http_content1!/meet-matt/!Iowa
Until I did this and it still worked even though it shouldn't because that word isn't on the page!!

Code: Select all

command_line    $USER1$/check_http -H $HOSTADDRESS$ -u $ARG1$ -R $ARG1$

Code: Select all

check_command                   check_http_content1!/meet-matt/!donkey

Re: Issue with check_http

Posted: Thu Dec 07, 2017 11:24 am
by t3dus
This I believe should work but it doesn't..

Code: Select all

define command{
        command_name    check_http_test
        command_line    $USER1$/check_http -H $HOSTADDRESS$ $ARG1$
}

Code: Select all

check_command  check_http_test! -R !Global

Re: Issue with check_http

Posted: Thu Dec 07, 2017 12:00 pm
by t3dus
danjoh wrote:
command_line $USER1$/check_http -H $HOSTADDRESS$ $ARG1$ $ARG1$
You are aware that you have $ARG1$ two times on the command line?
The above will evaluate to:

Code: Select all

$USER1$/check_http -H snapgeek.com -u /meet-matt -R Iowa -u /meet-matt -R Iowa
So you are saying I should just have one arg like this?

Code: Select all

define command{
        command_name    check_http_test
        command_line    $USER1$/check_http -H $HOSTADDRESS$ $ARG1$
}

Code: Select all

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       snapgeek.com
        service_description             URL test
        check_command                   check_http_test -H snapgeek.com -u /meet-matt/ -r !Iowa
        notifications_enabled           0
        }
gives me this Nagios Check config error

Code: Select all

Error: Service check command 'check_http_test -H snapgeek.com -u /meet-matt/ -r !Iowa' specified in service 'URL test' for host 'snapgeek.com' not defined anywhere!
This fails with the error at the bottom of this page.

Code: Select all

define command{
        command_name    check_http_test
        command_line    $USER1$/check_http -H $HOSTADDRESS$ $ARG1$
}

Code: Select all

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       snapgeek.com
        service_description             URL test
        check_command                   check_http_test! -u /meet-matt/ -r !Iowa
        notifications_enabled           0
        }
However that also fails with this
fail.PNG
fail.PNG (4.79 KiB) Viewed 6095 times