On Nov 7, 2020, at 11:18 AM, Jason Antman <[email protected]> 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.

> 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 
<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 
<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 
<https://networkupstools.org/docs/man/upsmon.conf.html>

> 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
> [email protected]
> https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser

_______________________________________________
Nut-upsuser mailing list
[email protected]
https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser

Reply via email to