Re: [Nut-upsuser] APC Back-UPS 1500 RS - looking for help with strange behaviour

2020-11-07 Thread Charles Lepple
On Oct 31, 2020, at 5:40 PM, David Butler  wrote:
> 
> Hi All,
> 
> hoping someone might have some insights to what is going wrong with my NUT 
> setup and my APC Back - UPS RS 1500 (specifically a BR1500GI) using the 
> usbhid driver.
> 
> https://download.schneider-electric.com/files?p_File_Name=AHUG-9JU4RH_R0_EN.pdf_Doc_Ref=SPD_AHUG-9JU4RH_EN_enDocType=User%20guide
>   
> 
> Main issue:
> 
> NUT successfully shuts down my server when it goes on battery but when I 
> restore power, as soon as my master computer comes up the UPS goes back on 
> battery. It stays like this until it fully discharges whereby everything 
> loses power, everything restarts and again, as soon as the master computer 
> comes online then the UPS goes back on battery... this whole cycle keeps 
> repeating until I switch off the UPS from the front power button.

It seems like this has come up before for this model, but with no resolution:

https://alioth-lists.debian.net/pipermail/nut-upsuser/2018-September/011228.html
> 
> To keep things short I've tried this on pfSense, FreeNAS and Ubuntu, each 
> independently configured as a solo master and for pfSense and FreeNAS the 
> only settings I change is to select the driver as usbhid, port auto and name 
> ups. 
> 
> Curiously I tried the apcupsd package of pfSense and it seemed to work as 
> expected.

Alternatively, if you want to run apcupsd for direct UPS control, there is an 
apcupsd-ups driver in NUT that translates apcupsd network status to NUT 
protocol - useful for a NAS.
> 
> Happy to send any logs or info that might be relevant (probably best to set 
> up ubuntu again since it's easier to control the config files). I first asked 
> about this in the Netgate (pfSense) forum so the last entries under uk_dave 
> is me with some info on upsc and upsrw. 
> https://forum.netgate.com/topic/102959/nut-package/728
> 
If I read everything correctly, my best guess here is that NUT is sending a 
different shutdown command than apcupsd. (Other than this model, I haven't 
heard of an UPS staying on battery once the power has returned.)

I'd agree that testing in Ubuntu is probably the easiest to control.

If you can capture the USB traffic when apcupsd tells the UPS to shutdown, we 
can compare that to what usbhid-ups does.

https://wiki.wireshark.org/CaptureSetup/USB

I'm not sure of the debugging support in apcupsd, but if it is doing things 
correctly, maybe we can just compare PCAPs, and reference the NUT logs?

For the NUT shutdown test, I think we might need at least a debug level of 3. 
You might also want to power the machine running NUT from another outlet 
temporarily, since we need to run the driver in debug mode without the help of 
upsd/upsmon to shut down the system properly.

Stop the services (nut-server and nut-client), then run 'sudo 
/lib/nut/usbhid-ups -DDD -k -a name-of-ups | tee -a 
/tmp/usbhid-ups.BR1500GI.log'. The '-k' flag tells the UPS to shut down, so you 
might need the UPS to be on battery power at that time.


> ___
> Nut-upsuser mailing list
> Nut-upsuser@alioth-lists.debian.net
> https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser


___
Nut-upsuser mailing list
Nut-upsuser@alioth-lists.debian.net
https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser

Re: [Nut-upsuser] NUT with Geekworm x728 UPS Hat on RPi?

2020-11-07 Thread Nick Ellson
While the init scripts are python 2, the UPS is straight I2C reads, using 
Python 3 to read and decode the I2C would be easy enough, if I knew how NUT 
needed to see things. Imma NUT Newbie 

Nick Ellson - from iPhone (forgive typos)
CCIE #20018; VCIX-NV, CNSE
Network Hobbyist
"Educating Layer 8, one user at a time."

> On Nov 5, 2020, at 12:21 PM, Roger Price  wrote:
> 
> On Thu, 5 Nov 2020, Nick Ellson wrote:
> 
>> I searched the forum from the website and didn’t get any hits, so I thought 
>> I’d ask here.
>> I have an RPi 4B running Home Assistant. It has the NUT integration, and I 
>> have a Geekworm X728 UPS Hat installed.
>> It has an I2C interface for reading data.
>> https://raspberrypiwiki.com/X728-Software
>> I was wondering if NUT supports that? 
> 
> Not in its current form.  The installation script seems to be generating two 
> Python2 scripts which very approximately play the role of a driver attached 
> to NUT's upsd.  To get this to work with NUT means writing a C language X728 
> driver based on the Python2 scripts.  Whether it's possible to write a upsd 
> driver in Python3 is an open question.
> 
> Roger
> 
> Health warning. Python2 is now well past its end-of-life. No support, not 
> even security updates. It's urgent for X728 to migrate to 
> Python3.___
> Nut-upsuser mailing list
> Nut-upsuser@alioth-lists.debian.net
> https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser

___
Nut-upsuser mailing list
Nut-upsuser@alioth-lists.debian.net
https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser

Re: [Nut-upsuser] upsd "events"

2020-11-07 Thread Roger Price

On Sat, 7 Nov 2020, Jason Antman wrote:


* 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.


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.


It should be even simpler to use upsmon as a passthrough to upssched + a Bash 
script often called upssched-cmd.  Working in Python is very interesting, but a 
custom upssched.conf and Bash script for A, B and C should be quite sufficient 
for your setup.


Roger

___
Nut-upsuser mailing list
Nut-upsuser@alioth-lists.debian.net
https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser

Re: [Nut-upsuser] upsd "events"

2020-11-07 Thread Jason Antman
On Sat, Nov 7, 2020 at 1:27 PM Charles Lepple  wrote:

> On Nov 7, 2020, at 11:18 AM, Jason Antman  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@alioth-lists.debian.net
> https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser
>
>
>
___
Nut-upsuser mailing list
Nut-upsuser@alioth-lists.debian.net
https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser

Re: [Nut-upsuser] upsd "events"

2020-11-07 Thread Phil Stracchino
On 11/7/20 11:18 AM, Jason Antman wrote:
> 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.


This is actually conceptually very similar to what I've been meaning to
set up.  My scheme would be something like:
85% — command all Unix hosts to unmount NFS shares, shut down NAS, shut
down non-critical appserver (this roughly triples runtime)
20% — shut down primary application server
10% — order shutdown of remaining connected workstations, keep network
stack running as long as battery lasts

But I simply haven't had the time and energy to get to it.


-- 
  Phil Stracchino
  Babylon Communications
  ph...@caerllewys.net
  p...@co.ordinate.org
  Landline: +1.603.293.8485
  Mobile:   +1.603.998.6958

___
Nut-upsuser mailing list
Nut-upsuser@alioth-lists.debian.net
https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser

Re: [Nut-upsuser] upsd "events"

2020-11-07 Thread Charles Lepple
On Nov 7, 2020, at 11:18 AM, Jason Antman  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 
 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 


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

___
Nut-upsuser mailing list
Nut-upsuser@alioth-lists.debian.net
https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser

[Nut-upsuser] upsd "events"

2020-11-07 Thread Jason Antman
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. 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)?

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