trouble setting check_http

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
cbastos
Posts: 3
Joined: Wed Aug 07, 2013 11:03 am

trouble setting check_http

Post by cbastos »

Hi.

Iḿ trying to use the plugin check_http to verify the result of an access to one URL to check if the responses of the server are ok.

This is the URL I want to check :

Code: Select all

http://172.31.0.28:81/odbc/odbc_mapper_table.php?tb=ura_saldo&pr=%20WHERE%20'$runparam'%20=%20'1805,8419195204000,1,2121729026'
and it gives this response:

Code: Select all

<documento>
   <dados>
     <linha>
       <Saldo>000</Saldo>
       <Pagtomin>000</Pagtomin>
       <CC>84</CC>
       <cartao>8419195204000</cartao>
       <param>8419195204000</param>
       <NroOrigem>ANA LUCIA DE LIMA COSTA</NroOrigem>
     </linha>
   </dados>
 </documento>
First I tested the access to this URL with links and I had to make slight modification in order to get it working (just encoding and scaping some chars). So i got this command line working like on the browser:

Code: Select all

# links "http://172.31.0.28:81/odbc/odbc_mapper_table.php?tb=ura_saldo&pr=%20WHERE%20%27\$runparam%27%20=%20%271805,8419195204000,1,2121729026%27"
This is the output of the links command:

Code: Select all

<?xml version = "1.0" encoding = "ISO-8859-1"?>
<documento>
<dados>
    <linha>
         <Saldo>000</Saldo>
         <Pagtomin>000</Pagtomin>
         <CC>84</CC>
         <cartao>8419195204000</cartao>
         <param>8419195204000</param>
         <NroOrigem>ANA LUCIA DE LIMA COSTA</NroOrigem>
    </linha>
</dados>
</documento>
When I tested the URL with the check_http command everything worked like a charm:

Code: Select all

# /usr/libexec/nagios/check_http -H 172.31.0.28 -p81 -s "ANA LUCIA DE LIMA COSTA" -u "/odbc/odbc_mapper_table.php?tb=ura_saldo&pr=%20WHERE%20%27\$runparam%27%20=%20%271805,8419195204000,1,2121729026%27"
HTTP OK: HTTP/1.1 200 OK - 522 bytes in 2.953 second response time |time=2.952692s;;;0.000000 size=522B;;;0
Then I created the following command on the Nagios configuration:

Code: Select all

define service{
        use prioritary-service
        host_name               servidor-ura
        service_description     WEBTX-ura
        check_command           check_http_ip!$HOSTADDRESS$!-p81 -s "ANA LUCIA DE LIMA COSTA" -u "/odbc/odbc_mapper_table.php?tb=ura_saldo&pr=%20WHERE%20%27\$runparam%27%20=%20%271805,8419195204000,1,2121729026%27"
        contact_groups          cpd,support
        }
Although the command worked by hand, it do not work under the Nagios process. It keeps giving the following error:

Code: Select all

HTTP CRITICAL: HTTP/1.1 200 OK - string 'ANA LUCIA DE LIMA COSTA' not found on 'http://172.31.0.28:81/odbc/odbc_mapper_table.php?tb=ura_saldo&pr=%20WHERE%20%27%27%20=%20%271805,8419195204000,1,2121729026%27$' - 422 bytes in 2.105 second response time 
When the command is executed by the Nagios, you can notice an extra "$" at the end of the request on the error message.

Also if the command definition is changed to:

Code: Select all

define service{
        use prioritary-service
        host_name               servidor-ura
        service_description     WEBTX-ura
        check_command           check_http_ip!$HOSTADDRESS$!-p81 -u "/odbc/odbc_mapper_table.php?tb=ura_saldo&pr=%20WHERE%20%27\$runparam%27%20=%20%271805,8419195204000,1,2121729026%27" -s "ANA LUCIA DE LIMA COSTA"
        contact_groups          cpd,support
        }
The error message change to:

Code: Select all

HTTP CRITICAL: HTTP/1.1 200 OK - string 'ANA LUCIA DE LIMA COSTA$' not found on 'http://172.31.0.28:81/odbc/odbc_mapper_table.php?tb=ura_saldo&pr=%20WHERE%20%27%27%20=%20%271805,8419195204000,1,2121729026%27' - 421 bytes in 2.029 second response time 
With an extra "$" appended to the search string, making me believe the Nagios process is adding this "$" at the end of the check_http command.

Am I missing something? How can I fix this?
Please, any help will be very appreciated.
Last edited by cbastos on Thu Aug 08, 2013 11:00 am, edited 1 time in total.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: trouble setting check_http

Post by abrist »

Instead of escaping "$" with "\", try escaping with a second "$":

Code: Select all

# /usr/libexec/nagios/check_http -H 172.31.0.28 -p81 -s "ANA LUCIA DE LIMA COSTA" -u "/odbc/odbc_mapper_table.php?tb=ura_saldo&pr=%20WHERE%20%27$$runparam%27%20=%20%271805,8419195204000,1,2121729026%27"
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
cbastos
Posts: 3
Joined: Wed Aug 07, 2013 11:03 am

Re: trouble setting check_http

Post by cbastos »

Tank you very much for you quick reply.

scaping $ with another $ stopped Nagios from adding an extra $ at the end of the line, but the string could not be found.

Code: Select all

HTTP CRITICAL: HTTP/1.1 200 OK - string 'ANA LUCIA DE LIMA COSTA' not found on 'http://172.31.0.28:81/odbc/odbc_mapper_table.php?tb=ura_saldo&pr=%20WHERE%20%27%27%20=%20%271805,8419195204000,1,2121729026%27' - 421 bytes in 2.066 second response time 
The same happened with the command line, it doesn't work scaping with $
command line scaped with \:

Code: Select all

# /usr/libexec/nagios/check_http -H 172.31.0.28 -p81 -s "ANA LUCIA DE LIMA COSTA" -u "/odbc/odbc_mapper_table.php?tb=ura_saldo&pr=%20WHERE%20%27\$runparam%27%20=%20%271805,8419195204000,1,2121729026%27"
HTTP OK: HTTP/1.1 200 OK - 522 bytes in 4.045 second response time |time=4.045326s;;;0.000000 size=522B;;;0
Command line scaped with $, the char $ is changed by the number 199:

Code: Select all

# /usr/libexec/nagios/check_http -H 172.31.0.28 -p81 -s "ANA LUCIA DE LIMA COSTA" -u "/odbc/odbc_mapper_table.php?tb=ura_saldo&pr=%20WHERE%20%27$$runparam%27%20=%20%271805,8419195204000,1,2121729026%27"
HTTP CRITICAL: HTTP/1.1 200 OK - string 'ANA LUCIA DE LIMA COSTA' not found on 'http://172.31.0.28:81/odbc/odbc_mapper_table.php?tb=ura_saldo&pr=%20WHERE%20%2727199runparam%27%20=%20%271805,8419195204000,1,2121729026%27' - 279 bytes in 2.030 second response time |time=2.030369s;;;0.000000 size=279B;;;0
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: trouble setting check_http

Post by abrist »

You may want to try using "\$$". You have to try these as the full check, as testing from the cli will require different escaping than through nagios itself. Worst case scenario - depending on how the plugin handles the string, you may need to use the $USERn$ macros in the resources.cfg file.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
cbastos
Posts: 3
Joined: Wed Aug 07, 2013 11:03 am

Re: trouble setting check_http

Post by cbastos »

Hi.
Tank you very much for your suggestion, but i tryed scaping like you told but no sucess.

Scaping with \$$ made the variable runparan vanish on the request:

Code: Select all

HTTP CRITICAL: HTTP/1.1 200 OK - string 'ANA LUCIA DE LIMA COSTA' not found on 'http://172.31.0.28:81/odbc/odbc_mapper_table.php?tb=ura_saldo&pr=%20WHERE%20%27%27%20=%20%271805,8419195204000,1,2121729026%27' - 421 bytes in 2.033 second response time 
I think I'll have to figure out how to use the $USERn$ macros
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: trouble setting check_http

Post by abrist »

To make use of the user macros, edit the file: /usr/local/nagios/etc/resource.cfg
Add a new, unused macro and set your url to it, for example:

Code: Select all

$USER9$=/odbc/odbc_mapper_table.php?tb=ura_saldo&pr=%20WHERE%20%27\$runparam%27%20=%20%271805,8419195204000,1,2121729026%27
And then in the check configuration, use the macro in place of the url:

Code: Select all

check_command           check_http_ip!$HOSTADDRESS$!-p81 -u "$USER9" -s "ANA LUCIA DE LIMA COSTA"
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked