Page 1 of 2

character limit in API/JSON

Posted: Mon Jun 02, 2014 12:46 pm
by jssingh
is there a character limit for the APIs/JSON? We are getting a 500 internal server error if we try to get the JSON for one of our services. The only output in the error log is:

Code: Select all

[Mon Jun 02 10:21:28 2014] [error]  Premature end of script headers: statusjson.cgi, referer: http://localhost/nagios4/jsonquery.html
the output of the service is huge, 102696 characters, so I'm not sure if the size is the problem or if one of those many characters is confusing things, so I thought I'd start by asking if anyone has run into a character limit?

Re: character limit in API/JSON

Posted: Mon Jun 02, 2014 3:15 pm
by abrist
It may be a limitation of the jsonquery.html helper tool. It you curl the url does it work?

Re: character limit in API/JSON

Posted: Mon Jun 02, 2014 4:14 pm
by jssingh
This is the curl output:

Code: Select all

$ curl "http://localhost/nagios4/cgi-bin/statusjson.cgi?query=service&hostname=pleiades1&servicedescription=qstatSum"
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
 [email protected] and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apache/2.2.15 (Red Hat) Server at localhost Port 80</address>
</body></html>
$
And I see the same error:

Code: Select all

[Mon Jun 02 14:11:56 2014] [error] [client 127.0.0.1] Premature end of script headers: statusjson.cgi

Re: character limit in API/JSON

Posted: Mon Jun 02, 2014 4:33 pm
by jssingh
I just faked the output of a service to be 102697 0s and then ran the API for that. Both the query generator and curl gave me back 8191 0s. But at least it didn't crash!

Re: character limit in API/JSON

Posted: Tue Jun 03, 2014 11:00 am
by tmcdonald
Very odd. Might the output have some characters in it that would cause issues with the JSON parser? Or maybe even some malformed binary data that could be messing up the HTTP headers?

Re: character limit in API/JSON

Posted: Wed Jun 04, 2014 5:33 pm
by jssingh
I started removing special characters from the output and when I removed the %s from it, the JSON started working! However I only get 8064 bytes of the output. Does anyone else get that limit? Or something similar since I got 8191 bytes when they were 0s.

Re: character limit in API/JSON

Posted: Thu Jun 05, 2014 3:56 pm
by tmcdonald
So 127 bytes/chars less? Anything in that %s that might be significant? Would 127 characters make sense for that %s value?

I am also getting 8191, with the last character being a newline for 8192. Capping the output at 8192 makes sense since this is a compiled binary we are dealing with.

Re: character limit in API/JSON

Posted: Fri Jun 06, 2014 9:48 am
by emislivec
Are you able to see the full plugin output in web CGIs (Service Status page)?

Also, we're looking into where these data size limits are being set. Is there a maximum data size you think is needed?

Re: character limit in API/JSON

Posted: Sat Jun 07, 2014 10:59 am
by estanley
I found 2 instances where 8k buffers were used for strings in the JSON code and have converted them to use dynamically allocated buffers, so the only limitation now is the amount of RAM on the system. This update is in commit 6081644. Check it out and let us know whether it does what you need.

Re: character limit in API/JSON

Posted: Mon Jun 09, 2014 10:11 am
by abrist
I just tested this with the commit: https://github.com/NagiosEnterprises/na ... 80164c4983
Works fine now.