networkupstools / nut

The Network UPS Tools repository. UPS management protocol Informational RFC 9271 published by IETF at https://www.rfc-editor.org/info/rfc9271 Please star NUT on GitHub, this helps with sponsorships!
https://networkupstools.org/
Other
2.07k stars 351 forks source link

Add new templates options #2524

Open mikewhippsHarvest opened 4 months ago

mikewhippsHarvest commented 4 months ago

I'd like an option to select a template at runtime when running UPSSTATS.CGI.

Something like a query string element upsstats.cgi?template=mytemplate.html, or possibly even upsstats.cgi?template=/path/to/mytemplate.html

It would be good to allow the use of json or xml as an extension instead of html, as in upsstats.cgi?template=mytemplate.json,

The specific use case is to emit data in JSON format to import into PRTG for monitoring while leaving the friendlier HTML version alone for those wanting to query NUT directly in a browser.

jimklimov commented 4 months ago

This is a really interesting point, would you endeavour to make a PR?

For the time being, especially regarding json, check the third-party projects list, IIRC some emitters were there.

But having some out of the box was backlogged for a while...

I am wary of allowing arbitrary file access (especially with paths and not a filename exactly in configured resource directory), way too many attacks happen through such vectors historically. Probably a deployment's config file should list allowed filenames for templates, if such option were added.

mikewhippsHarvest commented 4 months ago

By PR do you mean Pull Request? My skill level won't run to that, I'm afraid :( I last wrote C (not even C++) about 1984

I have a working JSON template set up as upsstats-single.html. The Content-type: header is wrong, but PRTG doesn't seem to care.

We're still evaluating so this would be nice in the future. I imagine others would find it useful, though.

neg-dean commented 1 month ago

I'm keen to understand the real timeline to this feature being added to the NUT package. Being able to retrieve the data shown on either the table or graph view of the cgi interface as JSON would be a major advantage allowing us to make a PRTG sensor to bring the data & monitoring into PRTG

jimklimov commented 1 month ago

Timeline? Rather, milestones: Somebody writes the code, posts a PR, it passes CI and works in fact and does not add regressions and errors / predictable flaws, it gets merged and eventually published as part of a release...