1

I would like to configure NUT UPS monitoring software under Linux to simply page me when the UPS goes onto battery power, and then when it returns to line power. For example, when I receive the following messages from upsmon in syslog:

Aug 19 05:43:27 jupsden upsmon[466]: UPS jupsden@localhost on battery
Aug 19 05:43:42 jupsden upsmon[466]: UPS jupsden@localhost on line power

And, maybe the best solution is a custom syslog rule?

But, all of the examples I have seen for NUT-specific configured notifications in /etc/nut/upssched.conf were for starting a timer when the UPS battery level reaches a certain low threshold, then passing a custom parameter to a custom script upssched-cmd, gracefully shutting down systems, etc. Using the "timer" approach, could I do something like the following in upssched.conf:

AT ONBATT * START-TIMER onbatterypower 0
AT ONLINE * CANCEL-TIMER onlinepower

...or are there some different / better NUT conf commands that would achieve what I want to do?

1 Answer 1

1

Sure you could use 0-length timers, but if you want immediate reactions, there is also the AT ... EXECUTE syntax.

If you want pages immediately whenever the power state changes, you would use the AT <notifytype> <upsname> EXECUTE <command> syntax. In other words you could do something like this in upssched.conf:

CMDSCRIPT /usr/local/sbin/custom-upssched-cmd

[...]

AT ONBATT * EXECUTE start_panicking
AT ONLINE * EXECUTE panic_over

And your /usr/local/sbin/custom-upssched-cmd script (remember to chmod a+x it!) would then contain something like this:

#!/bin/sh
case "$1" in
    start_panicking)
        logger -t custom-upssched-cmd "UPS went on battery power at this time"
        # add here a command to send a suitably alarming pager message
        ;;
    panic_over)
        logger -t custom-upssched-cmd "UPS reports power is back"
        # add here a command to send a calming pager message
        ;;
    *)
        logger -t custom-upssched-cmd "The administrator forgot to add a suitable message for upssched.conf command $1"
        ;;
esac
1
  • Thank you! I knew there was an elegantly simple solution. Will test this asap.
    – DJacobson
    Aug 29, 2021 at 23:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .