-
-
Notifications
You must be signed in to change notification settings - Fork 412
upsstats: Add JSON output mode via ?json parameter #3171
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
upsstats: Add JSON output mode via ?json parameter #3171
Conversation
|
Dist and Docs NUT-tarballs-PR-3171.zip are available for commit 0d8aa8b |
|
❌ Build nut 2.8.4.3746-master failed (commit b43be68d6f by @atanas-vladimirov) |
|
@atanas-vladimirov : Cool, thanks! I've long wondered if it would make sense to offer two JSON format queries for this, with flat sort of JSON for NUT data points (passing dot-separated names as such), or splitting those names by dots into an object, e.g.: but now seeing it written out, I understood I have little idea if this split brings any value and/or how to handle items like In updated man page, I am not sure there's a double-asterisk in asciidoc markup. In NEWS.adoc, you can add links to this PR and to the issues (#2524?) that it addresses. Per CI logs, there are a few C code issues: There was also a lingering idea about adding a JSON output mode to Are both methods your original code, or is there some attribution that makes sense ("inspired by this URL on Stack Overflow", etc.?) |
|
Just for cross-linking, it is also worth noting some other issues here (later iterations of this code might grow into these areas):
|
89b0419 to
324ee0f
Compare
|
Hey Jim, Thanks for your comment.
I've build the docs and the html and man pages looks good to me:
and the man:
Of course, I can change that if you wish :)
Done.
Thanks. I tried to fix that but it looks that the jobs failed again, not sure if the same errors were hit. By the way, I'm building on OpenBSD and I do not see those issues there, not sure why :).
To be honest, I used an AI to help me with this particular code :) About your other thoughts - re json splitting names by dots, I don't think it will "look" good for the end, i.e. it will be more confusing. Of course, the idea of the JSON is not to be read by a user, but a "machine" .... and
This sounds like a bigger task for me and not sure that I can handle it at the moment, but who knows what will happen in the near future :) |
bdd5d19 to
8dc58ba
Compare
|
I believe I found the last build error and also fixed the double-asterisk in the doc :) |
|
The spellcheck error (wanted to replace |
When the ?json (or &json) parameter is added to the URL, upsstats.cgi will now bypass all HTML template processing. Instead, it returns a "Content-Type: application/json" response containing the full data for the requested UPS(es), including all variables, raw status, and parsed status. This provides a modern API for external monitoring tools without affecting the existing HTML template functionality. Signed-off-by: Atanas Vladimirov <vladimirov.atanas@gmail.com>
8dc58ba to
135499b
Compare
|
Hi, I have replaced the |
Signed-off-by: Atanas Vladimirov <vladimirov.atanas@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
|
❌ Build nut 2.8.4.3752-master failed (commit e6930c3bb7 by @jimklimov) |
|
Took a little swing at generalizing the code to print out JSON, so it can be used by more clients or even NUT server (given a special query), but indeed it is not trivial and worth a separate PR (that I started but not quickly sure how to finish, if at all). Posted issue #3172 to track the idea at least, and https://github.com/jimklimov/nut/tree/issue-3172 with (incomplete currently) PoC of structural code changes. Although looking at it, and how |
…etworkupstools#3171] Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…etworkupstools#3171] Avoid `comparison is always true due to limited range of data type` warning. Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…l data as JSON docs [networkupstools#3171] Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…l data as JSON docs [networkupstools#3171] Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>


When the ?json (or &json) parameter is added to the URL, upsstats.cgi will now bypass all HTML template processing.
Instead, it returns a "Content-Type: application/json" response containing the full data for the requested UPS(es), including all variables, raw status, and parsed status.
This provides a modern API for external monitoring tools without affecting the existing HTML template functionality.
Here is an example output:
Signed-off-by: Atanas Vladimirov vladimirov.atanas@gmail.com