[Nut-upsuser] upsd "events"

Jason Antman jason at jasonantman.com
Sat Nov 7 19:24:16 GMT 2020


On Sat, Nov 7, 2020 at 1:27 PM Charles Lepple <clepple at gmail.com> wrote:

> On Nov 7, 2020, at 11:18 AM, Jason Antman <jason at jasonantman.com> wrote:
>
>
> Hello,
>
> I'm quite new to NUT, currently setting it up on a few machines in my home
> lab because I switched from an APC UPS to a CyberPower unit. This is
> running in a home lab, and I'm trying to implement some apparently unusual
> logic around load-shedding.
>
>
> The interesting thing to me is the shift from a single server being able
> to be supplied from one or more UPSes for redundancy, to a single UPS
> powering a number of smaller systems.
>

This is my home setup; the machines are all single-PSU desktops and towers.
One that's my general-purpose desktop and two small-form-factor Dells, one
for home automation and one acting as a DVR for my security cameras. No
fancy (and loud, and hot-running) multi-power-supply systems here.


>
> I'm strongly considering writing my own custom script to replace upsmon in
> order to achieve the desired result.
>
> I see a lot of mention in the documentation on upsmon and upssched about
> "events", as in an ONBATT, LOWBATT, ONLINE, etc., however I see nothing
> about these in the Network protocol documentation.
>
>
> Can someone please confirm whether there are actual "events" being sent
> out to clients by upsd, or whether these events are
> completely derived/generated within upsmon, just based on polling upsd and
> detecting a change in something (such as ups.status)?
>
> The latter description is correct: upsmon polls the "ups.status" variable.
> When the state changes, upsmon generates the events internally. The
> majority of the mapping is in the comments here:
> https://github.com/networkupstools/nut/blob/v2.7.4/clients/upsmon.h and
> the code here:
> https://github.com/networkupstools/nut/blob/v2.7.4/clients/upsmon.c#L1466-L1489
>
> There is a lot of business logic in upsmon devoted to logging,
> reconnecting, and detecting the status changes (potentially across
> disconnects). If you didn't want to rewrite and test that code in your own
> script, you could use the EXEC flag in upsmon to start your script from
> NOTIFYCMD when the UPS goes on battery, and then poll battery level from
> there. You could then set up another section of your script for ONLINE
> (which only gets called on a transition from OB to OL, not at startup) that
> does wake-on-LAN and kills the script started for ONBATT.
>
> The key to on-battery/online is the NOTIFYTYPE environment variable:
> https://networkupstools.org/docs/man/upsmon.conf.html
>

Ok, thanks so much, Charles!

I found the "nut2" Python package (https://github.com/rshipp/python-nut2)
which is built on top of python's telnetlib. That should make most of the
logic rather simple, certainly as compared to the C implementation. It
shouldn't be too difficult to handle that reliably.


>
> Thanks so much,
> Jason Antman
>
> PS - Since someone may ask about it, given my introduction, here's the
> setup I have:
>
> * One CyberPower UPS powering everything
> * Three Linux machines, "A", "B", and "C"
> * A bunch of network devices, as well as two Raspberry Pis
>
> I'm trying to achieve the following shutdown behavior:
> * Kill host A when battery drops to 80%
> * Kill host B at 50%
> * Kill host C at 10%
> * Leave the outputs turned on always, so the network and Pis keep running
> * If the power comes back before the battery is exhausted, a script will
> turn on hosts A, B, and C via wake-on-lan.
>
> _______________________________________________
> Nut-upsuser mailing list
> Nut-upsuser at alioth-lists.debian.net
> https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/nut-upsuser/attachments/20201107/3e627d1d/attachment-0001.html>


More information about the Nut-upsuser mailing list