-
Notifications
You must be signed in to change notification settings - Fork 251
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
JSON output support with --json/-J option #160
base: develop
Are you sure you want to change the base?
Conversation
Thanks for the patch! I will need some time to review it / integrate it, but I just wanted to already say that it's much appreciated :-) |
Considering that the JSON output is going to be an interface and we won‘t be able to change it later, we should make sure that the schema is how we want to keep it long term. Seeing the current output:
I see a couple of issues:
How the output could look like:
Let me know what you think. I can also work on making these changes. |
Good point. I think it best if we were to always include every possible field and {
"summary": {
"dns.google.com": {
"addr": "2001:4860:4860::8844",
"host": "dns.google.com",
"xmt": 3,
"rcv": 3,
"outage": null,
"min": 3.32,
"avg": 3.32,
"max": 3.33,
"rtt": null
}
}
} or {
"summary": {
"2001:4860:4860::8844": {
"addr": "2001:4860:4860::8844",
"host": null,
"xmt": null,
"rcv": null,
"outage": null,
"min": null,
"avg": null,
"max": null,
"rtt": [
3.32,
3.32,
3.33
]
}
}
} OTOH this is kind of wasteful since we can easily do the summary calculations even if we print all rtts anyway. Opinions?
I'll add an
Technically most keys are redundant as long as we include the rtts. I'll throw out
Will do.
No worries, I'll take care of it. Edit: Do you want me to squash my commits? Edit 2: Another thing I noticed is the issue of duplicate keys. Suppose a user runs |
Reperator, thanks for picking this back up! I'm encouraged to see others found value in the original suggestion. I've been using fping 4.2 with my original patch suggestions, but I look forward to your fix-ups and enhancements! |
Any news about this? It will be really awesome to have json output! |
My two cents is that the schema needs work. The point about the schema changing is good, but in my opinion the "null" suggestion is not quite right. Json consuming code that has to distinguish between a field being null and a field not being present is almost always going to have bugs. " We probably should use a consistent schema independently of what options are used, and just fill what is relevant." is a good approach, and allows for additions to the schema in the future while preserving backwards compatibility with any JSON consumer that is not going to be confused by new keys (Another good practice IMHO) |
I'm sorry, I completely forgot about this. I'll start working on it today; I hope I can get it finished soon-ish.
Agreed, I'll keep the schema consistent across options. |
What about using numeric keys instead of IP address as a key? This should eliminate the issue with repeated IPs? |
In that case we can just use JSON arrays. My main gripe with that is that the API for JSON objects is much nicer than the API for JSON arrays in many languages (hashtables vs. lists). |
I think this should not be an issue. Every JSON consumer can work with arrays with ease. And all the API's that I know about are using json arrays in their json responses. |
Not a big deal, I am already running fping and parsing the string results into json and passing them further along to other software... This would apply to yaml or xml too, I do the conversion on more of a line by line basis and emit a stream of json documents. If this were of interest, https://en.wikipedia.org/wiki/JSON_streaming has some suggestions on outputting multiple json objects over a stream. I can share an example as a different straw man to beat on.
|
I think showing the "progress" per IP per ping is a must! Either by adding this into the final response or outputting it while running. Right now the proposed implementation will imply the |
IMHO though I could be over-complicating, flags would allow you to choose between multiple json document output like I suggested, or a single json output with all the results, possibly including progress.
But it could be more complex:
|
I'm a bit busy at work at the moment so it might take some time until I can get back to this PR, sorry. :( |
Thank you, @Reperator, this is really useful feature for us, talking from Zabbix perspective! I'd agree with @bkuker that it makes more sense to not list tags that have no values. OK here are my 2 cents. I have grouped the output in targets, within those there is data for each packet and summary. Also, I have added some ideas about error handling:
|
anyone still working on this or it was forgotten? |
I'm not working on it anymore, I left my old company a year ago and don't have the time to look into this again. |
I'll convert this to a "draft" since it does not apply currently, and work on it has stopped. |
This PR revamps #141 and fixes all the complaints. It adds support for outputting pretty-printed JSON with variable indentation (
--json=n
), outputting compact non-pretty-printed JSON (--json=0
) and outputting the--vcount
and--outage
options' results in JSON format.Unfortunately choosing a custom indentation or disabling pretty-printing with-J 4
or-J 0
does not work, because the parser can't tell the difference between an option'soptarg
and a non-option argument (e.g. an IP address).Seems like the parser accepts
-J4
or-J0
.