Page 1 of 3

[SOLVED] check_http failing to compile regex

Posted: Thu Jul 02, 2015 5:20 pm
by northwood128
Hi everyone!

I'm trying to monitor a service. This service response should always be an empty JSON list like this: []

When I run it like this, it works:

Code: Select all

~/development/nagios-plugins/check_http -H HOSTADDRESS -w 3 -c 5 -t 4 -u '/url/to/service -r '\[\]' --ssl
HTTP OK: HTTP/1.1 200 OK - 258 bytes in 0.046 second response time |time=0.045796s;3.000000;5.000000;0.000000 size=258B;;;0
But one I've defined the service I get "Could Not Compile Regular Expression: Unmatched [ or [^check_http: Could not parse arguments"
This is the service definition:

Code: Select all

define service {
        use                     generic-service
        host_name               HOSTADDRESS
        service_description     DESCRIPTION
        check_command           check_https_uri_regex!3!5!/api/assort/failed!'\[\]'!
        action_url              SOME_LINK
        notes                   A_NOTE.
}
And this is the command definition:

Code: Select all

define command{
        command_name    check_https_uri_regex
        command_line    $USER1$/check_http -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -t 4 -u $ARG3$ -r $ARG4$ --ssl
        }
I've already tried a ton of ways to define the service but it doesn't take any of the different ways to express the regex. I've appreciate some help.
Thank in advance!

Re: check_http failing to compile regex

Posted: Mon Jul 06, 2015 1:22 pm
by lmiltchev
It's an escaping issue. Have you tried using this:

Code: Select all

check_command           check_https_uri_regex!3!5!/api/assort/failed!'[]'!
or this:

Code: Select all

check_command           check_https_uri_regex!3!5!/api/assort/failed!"\[\]"!

Re: check_http failing to compile regex

Posted: Mon Jul 06, 2015 1:24 pm
by jolson
In addition to what lmiltchev said, I got the following to work on my test machine:

Code: Select all

/usr/local/nagios/libexec/check_http -H $HOSTADDRESS$ -w 3 -c 5 -t 4 -u '/url/to/service' -r "\\\[\\\]"

Re: check_http failing to compile regex

Posted: Mon Jul 06, 2015 1:55 pm
by northwood128
Thanks guys!!

Actually, I've tried what lmiltchev suggested but it didn't work. I'll try the way joison proposed and I'll let you know. Thanks again for your help!

Re: check_http failing to compile regex

Posted: Mon Jul 06, 2015 2:01 pm
by jolson
No problem - looking forward to hearing back!

Re: check_http failing to compile regex

Posted: Tue Jul 07, 2015 11:48 am
by northwood128
That doesn't work either joison :(

Code: Select all

HTTP CRITICAL: HTTP/1.1 200 OK - pattern not found - 258 bytes in 0.029 second response time 
The response of the service is []

Code: Select all

$ curl -k https://hostname/url/to/service
[]

Re: check_http failing to compile regex

Posted: Tue Jul 07, 2015 11:54 am
by abrist
Can you run the checks above with the very very verbose switch (-vvv)? e.g.:

Code: Select all

/usr/local/nagios/libexec/check_http -H $HOSTADDRESS$ -vvv -w 3 -c 5 -t 4 -u '/url/to/service' -r "\\\[\\\]"

Re: check_http failing to compile regex

Posted: Tue Jul 07, 2015 12:05 pm
by ssax
In addition to abrist's post, try this:

Code: Select all

define service {
        use                     generic-service
        host_name               HOSTADDRESS
        service_description     DESCRIPTION
        check_command           check_https_uri_regex!3!5!/api/assort/failed!\\[\\]!
        action_url              SOME_LINK
        notes                   A_NOTE.
}

Code: Select all

define command{
        command_name    check_https_uri_regex
        command_line    $USER1$/check_http -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -t 4 -u $ARG3$ -r '$ARG4$' --ssl
}

Re: check_http failing to compile regex

Posted: Tue Jul 07, 2015 1:29 pm
by northwood128
Hi abrist, ssax!! Thanks for the suggestion.

I've tried that,

Code: Select all

define command{
        command_name    check_https_uri_regex
        command_line    $USER1$/check_http -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -t 4 -u $ARG3$ -r '$ARG4$' --ssl
        }
		
		
define service {
        use                     generic-service
        host_name               $HOSTNAME$
        servicegroups           SomeServiceaGroup
        service_description     Some Description
        check_command           check_https_uri_regex!3!5!/api/assort/failed!\\[\\]!
}
Same compilation error.
"Could Not Compile Regular Expression: Unmatched [ or [^check_http: Could not parse arguments "

Re: check_http failing to compile regex

Posted: Tue Jul 07, 2015 2:10 pm
by northwood128
verbose output

Code: Select all

$ /usr/local/nagios/production/libexec/check_http -H HOSTNAME -w 3 -c 5 -t 4 -S -u '/api/assort/failed' -r "\[\]" -v
GET /api/assort/failed HTTP/1.1
User-Agent: check_http/v1.4.15 (nagios-plugins 1.4.15)
Connection: close
Host: HOSTNAME


https://HOSTNAME:443/api/assort/failed is 256 characters
STATUS: HTTP/1.1 200 OK
**** HEADER ****
Server: Apache-Coyote/1.1
X-Ecoli-Encoded-Object-Class: java.util.ArrayList
X-Ecoli-Timing: DQ=0|O=8|ER=0|P=8|
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 07 Jul 2015 19:08:49 GMT
**** CONTENT ****
2
[]
0


HTTP OK: HTTP/1.1 200 OK - 256 bytes in 0.039 second response time |time=0.038579s;3.000000;5.000000;0.000000 size=256B;;;0