Page 1 of 2

unexpected end of file

Posted: Wed Mar 30, 2016 3:35 am
by WillemDH
Trying to monitor a rather long URL again, but having some escaping issues again. Already tried to make a macro for '&', but it doesn't seem enough... I was wondering what other characters need escaping..

IN CLI everything works fine:

Code: Select all

/usr/local/nagios/libexec/check_http -H stad.gent -u '/sparql?default-graph-uri=&query=prefix+schema:+%3Chttp://schema.org/%3E%0D%0AASK+%7B%0D%0A%7B%0D%0A?loc+%3Chttp://stad.gent/data/internal/resourceId%3E+?id;%0D%0A%3Chttp://stad.gent/data/internal/resourceType%3E+?type.%0D%0A%0D%0AFILTER+(?id+=+%22%22)%0D%0A%7D%0D%0AUNION+%0D%0A%7B%0D%0A?loc+%3Chttp://stad.gent/data/internal/resourceId%3E+?id;%0D%0A%3Chttp://stad.gent/data/internal/resourceType%3E+?type.%0D%0A%0D%0AFILTER+(?type+=+%22%22)%0D%0A%7D%0D%0A%7D&format=text/html&timeout=0&debug=on' -S -s 'false' HTTP OK: HTTP/1.1 200 OK - 298 bytes in 0.021 second response time |time=0.021460s;;;0.000000 size=298B;;;0
In Nagios XI I tried many combination, single, double quotes, $USER10$=& in resources.cfg...

Code: Select all

-u "/sparql?default-graph-uri=$User10$query=prefix+schema:+%3Chttp://schema.org/%3E%0D%0AASK+%7B%0D%0A%7B%0D%0A?loc+%3Chttp://stad.gent/data/internal/resourceId%3E+?id;%0D%0A%3Chttp://stad.gent/data/internal/resourceType%3E+?type.%0D%0A%0D%0AFILTER+(?id+=+%22%22)%0D%0A%7D%0D%0AUNION+%0D%0A%7B%0D%0A?loc+%3Chttp://stad.gent/data/internal/resourceId%3E+?id;%0D%0A%3Chttp://stad.gent/data/internal/resourceType%3E+?type.%0D%0A%0D%0AFILTER+(?type+=+%22%22)%0D%0A%7D%0D%0A%7D$User10$format=text/html$User10$timeout=0$User10$debug=on" -S -s 'false'
What other characters need escaping in service arguments?

Code: Select all

-u "/sparql?default-graph-uri=&query=prefix+schema:+%3Chttp://schema.org/%3E%0D%0AASK+%7B%0D%0A%7B%0D%0A?loc+%3Chttp://stad.gent/data/internal/resourceId%3E+?id;%0D%0A%3Chttp://stad.gent/data/internal/resourceType%3E+?type.%0D%0A%0D%0AFILTER+(?id+=+%22%22)%0D%0A%7D%0D%0AUNION+%0D%0A%7B%0D%0A?loc+%3Chttp://stad.gent/data/internal/resourceId%3E+?id;%0D%0A%3Chttp://stad.gent/data/internal/resourceType%3E+?type.%0D%0A%0D%0AFILTER+(?type+=+%22%22)%0D%0A%7D%0D%0A%7D&format=text/html&timeout=0&debug=on" -S -s 'false'
The host is 'stad.gent' and externally availble if someone would like to give it a try... Thanks!!

EDIT: Went very crazy and tried escaping lots of stuff, but still having the same issue...

Code: Select all

-u '/sparql$USER11$default-graph-uri=$User10$query=prefix$USER14$schema:$USER14$%3Chttp://schema.org/%3E%0D%0AASK$USER14$%7B%0D%0A%7B%0D%0A$USER11$loc$USER14$%3Chttp://stad.gent/data/internal/resourceId%3E$USER14$$USER11$id;%0D%0A%3Chttp://stad.gent/data/internal/resourceType%3E$USER14$$USER11$type.%0D%0A%0D%0AFILTER$USER14$$USER12$$USER11$id$USER14$=$USER14$%22%22$USER13$%0D%0A%7D%0D%0AUNION$USER14$%0D%0A%7B%0D%0A$USER11$loc$USER14$%3Chttp://stad.gent/data/internal/resourceId%3E$USER14$$USER11$id;%0D%0A%3Chttp://stad.gent/data/internal/resourceType%3E$USER14$$USER11$type.%0D%0A%0D%0AFILTER$USER14$$USER12$$USER11$type$USER14$=$USER14$%22%22$USER13$%0D%0A%7D%0D%0A%7D$User10$format=text/html$User10$timeout=0$User10$debug=on' -S -s 'false'
reource.cfg:

Code: Select all

$USER10$=&
$USER11$=?
$USER12$=(
$USER13$=)
$USER14$=+
Same question as in https://support.nagios.com/forum/viewto ... +ampersand.. Why is this so hard? I would like to make a feature request to make it easier to monitor things with special chars in..

Re: unexpected end of file

Posted: Wed Mar 30, 2016 11:38 am
by tmcdonald
Are you using the Test Check Command button in the CCM, or are you saving the check and letting it run? The results between the two may differ, and the Test Check Command button is not always accurate.

Re: unexpected end of file

Posted: Wed Mar 30, 2016 1:14 pm
by WillemDH
Trevor, please. I was hoping you know I already know that. :) No Im not using this test button. Eof Result is in XI..

Re: unexpected end of file

Posted: Wed Mar 30, 2016 2:18 pm
by tgriep
That is strange. I setup a service check like below.

Code: Select all

define service {
	host_name			stad.gent
	service_description		stad.gent http
	use				generic-service
	display_name			stad.gent http
	check_command			check-host-alive-http! -u '/sparql?default-graph-uri=&query=prefix+schema:+%3Chttp://schema.org/%3E%0D%0AASK+%7B%0D%0A%7B%0D%0A?loc+%3Chttp://stad.gent/data/internal/resourceId%3E+?id;%0D%0A%3Chttp://stad.gent/data/internal/resourceType%3E+?type.%0D%0A%0D%0AFILTER+(?id+=+%22%22)%0D%0A%7D%0D%0AUNION+%0D%0A%7B%0D%0A?loc+%3Chttp://stad.gent/data/internal/resourceId%3E+?id;%0D%0A%3Chttp://stad.gent/data/internal/resourceType%3E+?type.%0D%0A%0D%0AFILTER+(?type+=+%22%22)%0D%0A%7D%0D%0A%7D&format=text/html&timeout=0&debug=on' -S -s 'false'!!!!!!!
	register			1
	}	
When I ran it, I received an OK status.

Code: Select all

HTTP OK: HTTP/1.0 302 Found - 105 bytes in 5.421 second response time
I copied exactly what you posted in the first code block that uses the single quote.
Maybe your check_http command is defined differently.

Re: unexpected end of file

Posted: Thu Mar 31, 2016 3:42 am
by WillemDH
What version of heck_http are you using? I have:

Code: Select all

/usr/local/nagios/libexec/check_http -V
check_http v2.0.3.85.gb94a (nagios-plugins 2.0.3)
This is my service definition:

Code: Select all

define service {
        host_name                       stad.gent
        service_description             URL_Content_LOD
        use                             dig-web-app-content-prio2
        servicegroups                   +all_svc_web_url_intern
        check_command                   check_xi_service_http!-u '/sparql?default-graph-uri=&query=prefix+schema:+%3Chttp://schema.org/%3E%0D%0AASK+%7B%0D%0A%7B%0D%0A?loc+%3Chttp://stad.gent/data/internal/resourceId%3E+?id;%0D%0A%3Chttp://stad.gent/data/internal/resourceType%3E+?type.%0D%0A%0D%0AFILTER+(?id+=+%22%22)%0D%0A%7D%0D%0AUNION+%0D%0A%7B%0D%0A?loc+%3Chttp://stad.gent/data/internal/resourceId%3E+?id;%0D%0A%3Chttp://stad.gent/data/internal/resourceType%3E+?type.%0D%0A%0D%0AFILTER+(?type+=+%22%22)%0D%0A%7D%0D%0A%7D&format=text/html&timeout=0&debug=on' -S -s 'false'!!!!!!!
        check_period                    xi_timeperiod_24x7
        notification_period             xi_timeperiod_24x7
        contacts                        +nagiosadmin
        contact_groups                  +cg_domein_web,cg_dummy
        _xiwizard                       websiteurl
        register                        1
        }

Code: Select all

/sparql?default-graph-uri=&query=prefix+schema:+%3Chttp://schema.org/%3E%0D%0AASK+%7B%0D%0A%7B%0D%0A?loc+%3Chttp://stad.gent/data/internal/resourceId%3E+?id;%0D%0A%3Chttp://stad.gent/data/internal/resourceType%3E+?type.%0D%0A%0D%0AFILTER+(?id+=+%22%22)%0D%0A%7D%0D%0AUNION+%0D%0A%7B%0D%0A?loc+%3Chttp://stad.gent/data/internal/resourceId%3E+?id;%0D%0A%3Chttp://stad.gent/data/internal/resourceType%3E+?type.%0D%0A%0D%0AFILTER+(?type+=+%22%22)%0D%0A%7D%0D%0A%7D&format=text/html&timeout=0&debug=on
is exactly the same. The command check-host-alive-http has no $ARG1$. Can you check this? Is it possible it works for you becasue it just check stad.gent without $ARG1$? Could you check with 'check_xi_service_http' command please?

Re: unexpected end of file

Posted: Thu Mar 31, 2016 10:10 am
by tgriep
Sorry, My command was messed up and was giving me false positives. I tried as many combinations of escaping that I could and still haven't found one that worked.

Re: unexpected end of file

Posted: Thu Mar 31, 2016 10:44 am
by tgriep
I finally got it to work.

I created an entry in the resource.cfg file like this.

Code: Select all

$USER9$='/sparql?default-graph-uri=&query=prefix+schema:+<http://schema.org/>%0D%0AASK+{%0D%0A{%0D%0A?loc+<http://stad.gent/data/internal/resourceId>+?id;%0D%0A<http://stad.gent/data/internal/resourceType>+?type.%0D%0A%0D%0AFILTER+(?id+=+"")%0D%0A}%0D%0AUNION+%0D%0A{%0D%0A?loc+<http://stad.gent/data/internal/resourceId>+?id;%0D%0A<http://stad.gent/data/internal/resourceType>+?type.%0D%0A%0D%0AFILTER+(?type+=+"")%0D%0A}%0D%0A}&format=text/html&timeout=0&debug=on'
Then I defined the command to use the $USER9$ like below.

Code: Select all

 check_http Hostaddress!-u $USER9$ -S -s 'false'
Try that out and let us know if it works.

Re: unexpected end of file

Posted: Thu Mar 31, 2016 10:54 am
by WillemDH
Thought about that but didn't have the chance to test. I'll try that tomorrow.

As we are adding web applications in an automated way, I will need to adjust our scripts so that if the URL contains a special char, a macro needs to be created. Could I also get a list of all characters which won't work in XI arguments..

It's hard to believe for me that there is no way to prevent all these escaping issues. In normal circumstances using single quotes around a string should mean that no escaping is necessary. Please make a high priority feature request to implement a way to make all character work when between single quotes? Or is this really technically impossible?

Grtz

Re: unexpected end of file

Posted: Thu Mar 31, 2016 2:14 pm
by tgriep
Here is the list characters that have to be escaped.
`~$&|'"<>

Escaping the characters is needed for Core so it can build the command correctly for it to run.

Edit:
Located in nagios.cfg:
illegal_macro_output_chars=`~$&|'"<>

If this gets changed it will give you a lot of problems, but this is where they are being set.

Re: unexpected end of file

Posted: Thu Mar 31, 2016 3:05 pm
by WillemDH
So is it me or is the only to-be-escaped 'special' char in my url an &. As I made a macro $USER10$ for that and replaced the & with $USER10$ why wasn't that working? (I'll try again tomorrow to double-check-verify this statement.) Or did you also try test it with a macro which only replaced &?
Another question => Can the macros in resource.cf be named whatever or do thay always have to be named $USERXX$?