desertwitch / NUT-unRAID

A refactored, modernized version of the original NUT plugin with a focus on frequent updates.
GNU General Public License v2.0
5 stars 2 forks source link

fix: Improve UPS compatiblity #3

Closed edusteinhorst closed 1 month ago

edusteinhorst commented 1 month ago

The UPS "SMS Pro" (driver sms_ser) usually goes back from ONBATT to BYPASS instead of ONLINE when AC is back, which the script would ignore and not cancel the shutdown. Additionally, it's battery.charge value is returned by the driver as a float (e.g. "100.00"), which would break the script that was expecting a integer.

This might also make it more compatible with other models/manufactures.

edusteinhorst commented 1 month ago

Doing a bit more testing

edusteinhorst commented 1 month ago

Done

desertwitch commented 1 month ago

Hello, thanks for the pull request and I apologize for the delay as I've not received an e-mail notification and just saw this tonight. I've left some comments on the code parts not related to BYPASS and I really like the floating-point conversion, which I'll happily include in the code and attribute to you.

Unfortunately I'm not really confident about treating BYPASS as a "back online" state, in particular at the same level with ONLINE, although I understand why this is important to you on your specific device. I must also say I've never personally seen this on any of my various UPS or with the multitude of users I have helped with theirs, so perhaps it is somehow UPS driver related.

But, anyway, generally speaking BYPASS is considered a rather critical state throughout the NUT software package (not just this plugin), this is because usually when BYPASS is seen the UPS is either severely malfunctioning (and cannot fulfil its tasks) or deliberately cut out of the power supply for maintenance reasons (in a controlled environment).

If we were to treat BYPASS as ONLINE one could picture a scenario where a UPS switches to battery mode (OB) due to the input power being degraded and the UPS needing to condition that input power in order to protect its connected devices. If the UPS were to malfunction at this point, it may switch to BYPASS and start supplying the "dirty" input power back to the connected devices. In such a situation we would not want a shutdown to be cancelled despite formally being back on mains power (for the wrong reasons), after all we don't want an endless supply of perhaps unsteady, "dirty" power pumped back into them.

Treating BYPASS as ONLINE would be counter-productive in this case, as one example, and not something the end-user would likely expect NUT to do. So I'm reluctant to put a "hotfix" for a specific range of UPS into effect for all other unaffected users (that would likely consider BYPASS an unwanted state of their UPS, basically where it cannot perform what it is meant to do).

But this doesn't mean that you can't set this up yourself, which is the beauty of NUT, so in order to put your own notification script into action you'd just need to change the NOTIFYCMD in upsmon.conf to an executable script of your choice (perhaps just a copy of the default script with the sections of this PR patched in) and then also add NOTIFYFLAG BYPASS SYSLOG+EXEC into your upsmon.conf (as you already proposed in this PR).

I hope you see where I am coming from, and I really appreciate the time you've put into this. If you have the feeling that the UPS itself is in an ONLINE state and just the UPS driver is reporting it as BYPASS, it may also be an option to open an issue in the NUT software package repository, perhaps that UPS driver needs further looking at: https://github.com/networkupstools/nut/issues

edusteinhorst commented 1 month ago

@desertwitch thanks for the detailed information, much appreciated! Your reasoning makes sense to me, and to be honest I'm suspicious that my UPS might be misbehaving/defective. I have no real prior experience with UPSes, and since this unit is brand new, I thought it might be some idiosyncratic behavior. But from your comment on never having seen this as normal behavior before, it's probably not the case. I don't know if it's a driver issue, because I do hear the relay clicking when it switches modes (although I suppose it could be a state mapping issue). I'm experimenting with setting the output voltage to 220V (same as my mains), and it hasn't gone into bypass yet. If it keeps switching I might try the warranty :)

Thanks the tips and great work with the plugin!

edusteinhorst commented 1 month ago

I've been researching a bit on UPSes, and it seems that at least some consumer-grade UPSes do operate in BYPASS under normal conditions as a way to be more energy efficient. I'll collect some references here as I find them.

https://www.cyberpowersystems.com/feature_focus/greenpower-ups-technology-bypass-design/