-
-
Notifications
You must be signed in to change notification settings - Fork 366
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
Adding a dummy-ups script to examples? #2807
Comments
Sounds interesting, thanks! Some new entry under the Also a Tech-wise, it may be hard to specify |
I can probably blend the description above with the existing README from the file comments... I'll have to research the .adoc format :) (btw, where there spelling mistakes I missed?)
Yeah, the staleness was really designed to reflect the network connectivity to the API server, not the liveliness of the monitor, but that did give me a couple ideas: A. I should probably have the monitor start "before" the dummy-ups driver with a ExecStartPre mode to disable the port-file, so any pre-shutdown (and now quite stale) state isn't exposed at startup, and connectivity is "proved" before a real ups.status is made available. B. I could potentially offer a pull request for dummy-ups with a new "keyword" (TBD named, "ACTIVE_TIMEOUT"?) which would cause the driver to claim data "stale" if the modify-time wasn't changed by the stated timeout, proving an active file manager. Useful? Unrelated, I noticed that to be "net-protocol" consistent, the float numbers need to be in "POSIX" format, and running the monitor in some locales (eg da_DK) would result in incorrect radix characters; so I'm fixing that...and I should map non-POSIX radix characters retrieved from the API as well... |
Regarding "idea B", sounds interesting. I think one way for it would be to But given the dynamic nature of the driver and this use-case (with external data-source's change frequency maybe also a variable factor), a new keyword for DEV/SEQ file format could also be a correct way. Still, probably best done as a no-op hint for the In fact, both approaches can be combined, for the driver command-line argument (via A negative value (also as built-in default for the introduced C variable), would mean ignoring the file age and never becoming "Data stale" (at least not due to its non-modification). This way existing use-cases that loop over the same sample file would never be stale. Hm... while at it, another new keyword for DEV/SEQ file format, to inject and revert the staleness report can also be helpful for uses of
|
Regarding the "idea A", I suppose the "monitor" here is your script that polls the external data source and populates the NUT driver with information? I suggest you wrap it into a systemd unit of its own, for a number of reasons explored below, including:
Then also note that systemd's "Wants/Requires" in a drop-in file for the
I can't vouch at the moment that NDE would not remove the whole directory with drop-in setting tuning for a particular driver instance when it decides the unit no longer exists (ups.conf section renamed, complete unit regeneration is requested, scripting bugs) so suggest that referencing the driver unit in your script's service unit is better :) Keeping that file in a tmpfs (e.g. |
This was how it was designed to work (see INSTALL section of the README), but I've made it a bit more explicit by checking in the service template file now :) I've also added a special mode for ExecStartPre, and ordered its service "Before" the driver; the "Pre" script can either be run to just "set nocomms", or as a "one-shot" to update the driver values before the driver starts. The main ExecStart then just runs in "monitor" mode and keeps the driver updated (and will auto-restart on failure)
The service unit does reference the driver directly in [Install]WantedBy=, but that needs to be "enabled" to take effect. I'll have to check on what NDE does when someone removes/re-adds the ups.conf section to see if the [email protected]/ directory is removed...
I considered using /run when first writing the script, but there's enough configuration in the "port file" (battery.charge.low, battery.voltage.high etc) that I didn't want to lose that state on reboot... The ExecStartPre mode (above) should take care of the "staleness" problem though... |
I like the idea of a default with a keyword override... (just MAXFILEAGE to be consistent?) This would add a new "mode" for dummy-ups to operate in, as it currently just "exits" when the port file is removed to indicate staleness, whereas this new mode would allow it to remain running after calling the appropriate dstate_datastale() function -- which would have the further benefit of allowing the dummy driver to recover from a "nocomms" state much faster (currently it's delayed until systemd restarts the dummy-ups driver service)
Yes, that's an excellent idea... but that also might suggest another "WATCH_TIMER " like keyword to enable a "watchdog" timer that wait unless the file was modified, so
would result in staleness if the file wasn't updated... (TIMER could be updated to do this, but that would change current behavior). Either option would work, and could even co-exist... |
The
for a DEV/SEQ keyword, yes :) CLI/ups.conf options are (mostly?) lower-case
I'd expect it (for drop-ins) and systemd (for dependencies) to mostly manipulate individual units' directories, e.g. [email protected]/ or [email protected]/ directory names. Likewise, dependencies declared from the monitoring script's unit would have to spell out the unit name for the driver. It defaults to quoting the section name from ups.conf, but if that string is invalid for the framework (systemd/SMF) it would use MD5 hash of that. I think the scripts (nut-driver-enumerator and upsdrvsvcctl) expose enough ways to check the mapping of driver sections vs. unit instances. But that would help in active (re-)set-up of dependencies for your monitor unit (manually or scripted via e.g. drop-in files), but not as something systemd could call and evaluate on the fly, I suppose. |
One more idea comes to mind: expose the timestamp of latest data refresh. Not sure if it is a security issue to show that server info though. Maybe the time since driver start is better in this regard (some value changing or not), or making it a global/device driver option. I'll think about a centralized solution for this idea (posted as #2810), but in the meanwhile your script could populate an |
I wonder... do we have any precedents for extended POSIX numbers like |
net-protocol.txt defines the number format pretty clearly:
|
Yeah, I first (a few days ago while commuting) read your comment as that the documentation was not consistent, so went digging into code to look up actual formatting string patterns used :) FWIW also updated the spec in |
…to convey date/time [networkupstools#2807] Signed-off-by: Jim Klimov <[email protected]>
… in NUT reported variables [networkupstools#2807] Signed-off-by: Jim Klimov <[email protected]>
…om "%g" to "%f" to match NUT naming spec [networkupstools#2807] Signed-off-by: Jim Klimov <[email protected]>
I tested this... it appears that the [Install]WantedBy= is effectively "owned" by the [email protected] instance, and not affected by any "disable/enable" on the [email protected] instances. Therefore, editing ups.conf and triggering NDE doesn't impact the dependency (which is nice :) |
Submitted a draft PR #2813 with a new directory scripts/external_apis and the enphase script/README etc in a subdirectory. Looking for comments:
I figured I'd checkin the current script as is, and if we add the new "stale file" features to dummy-ups, then I'll submit those additions in a later version as an option :) |
PR looks good, I've posted some comments and updates there, and generally hope to merge soon (as it passes CI). Makes sense to add new features holistically as different change sets striking in all relevant areas (driver, docs, maybe config parsing bindings) as one PR. |
I wrote a bash script to integrate my local Enphase's Envoy API (a simple JSON based local web API) with a dummy-ups driver's port file. I've just published it (GPLv3) at https://github.com/sshambar/enphase-monitor
The script is simple to use, and provides information on "grid" online/offline status, battery SOC, and several other details (like "load" and "runtime") from the Enphase system. I use it to integrate with current UPS + ATS (automatic transfer switch) to treat my house battery system as 2nd UPS. I didn't feel it merited writing a full driver as I'm not using it for FSD, outlet control or anything "interactive", I just didn't want my servers shutting down when my UPS failed (don't ask) and the house still had backup power. Plus it's nice to have another way to monitor the Enphase system using the NUT cgi programs...
The script is probably something others could use as an basis for integrating with similar web APIs using the dummy-ups as a hook to the NUT system, so I thought perhaps it made sense to add as an "example" script someplace in the source?
The script has nice features such as:
I would have rather created a pull request against NUT, but I honestly don't know where I would add the file here... perhaps someone can suggest a directory if you think it might be useful.
In any case, anyone wanting to add Enphase local API support to NUT can use it as is.
PS. yes I know there's a "external" Enphase API, but it's request limits are severely restricted without paying a high fee...
The text was updated successfully, but these errors were encountered: