Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected end of JSON input on q.parse() #6

Closed
ianrapha opened this issue Sep 22, 2016 · 5 comments
Closed

unexpected end of JSON input on q.parse() #6

ianrapha opened this issue Sep 22, 2016 · 5 comments

Comments

@ianrapha
Copy link

ianrapha commented Sep 22, 2016

Hi,

I'm trying to use the lib but i'm getting an error. I dumped the buf.Bytes() content and the JSON is ending with a comma not the enclosing bracket.

But when i tested with unixcat (line below) using the statement, the file generation ran successfully with a 2.3MB size.

/path/to/unixcat < services /path/to//live >> services.csv

The statement generated by q.buildCmd() is below.

GET services
Columns: host_alias display_name last_check last_check host_address description execution_time state
ResponseHeader: fixed16
OutputFormat: json

I didn't find any coding issue and I'm asking for help.

Thanks,
Ian Raphael

@vbatoufflet
Copy link
Owner

Hi @ianrapha,

Any chance you can provide me with the services.csv file (if not that sensitive)?

Which version of MKLivestatus are you using?

@ianrapha
Copy link
Author

Hello @vbatoufflet

Sorry, I cannot provide the content right now. I'll try to remove the sensitive parts and attach here. The file size is 106496 bytes and 915 lines.

I tested with all tables and the problem occurred only on services table.

The MKLs version is 1.2.8.

@ianrapha
Copy link
Author

Probably something is happening with OutputFormat: json.
After commenting this line the extraction worked well.

@jleavers
Copy link

jleavers commented Jan 8, 2017

I have also noticed this problem when retrieving larger numbers of services.

Filtering for state = 0 with approx 800 results works. On a larger Nagios installation with approx 1800 results, I get "Error: unexpected end of JSON input".

Looking at the Exec() function in query.go, data is created with a length of 1024 and there is then a check for new line:

if data[n-1] == byte('\n') {
   break
}

If I temporarily change this:

if data[n-1] == byte('\n') {
   fmt.Printf("New line found: %d\n", n)
}

I then see the new line being found several times before reaching the end of the data, which is why a larger set of results is truncated, but a smaller set is okay.

New line found: 1024
New line found: 1024
New line found: 147

So as a quick workaround I changed the length of data to 10240.

@vbatoufflet
Copy link
Owner

Hi all,

Sorry for the huge delay on this. I didn't took the time to maintain this project a lot this year.

The issue is now fixed. After some additional debugging, the fact is that the problem was triggered by having \n exactly as the 1024th character in the middle of a Livestatus response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants