...
Just my blog

Blog about everything, mostly about tech stuff I made. Here is the list of stuff I'm using at my blog. Feel free to ask me about implementations.

Soft I recommend
Py lib I recommend

I'm using these libraries so you can ask me about them.

Installing NUT - Network Ups Tool Notifications and emails

Installing NUT - Network Ups Tool Notifications and emails

Notifications and email

Just a simple work log of installing NUT and configuring email notifications from it.

 

Simple

 Go to file:

sudo vi /etc/nut/upsmon.conf
Add at the EOF:
# Email script for NOTIFYCMD
# Simple
NOTIFYCMD "/etc/nut/notifycmd.sh"

# Notification events
NOTIFYFLAG ONLINE     SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT     SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT    SYSLOG+WALL+EXEC
NOTIFYFLAG FSD        SYSLOG+WALL+EXEC
NOTIFYFLAG COMMOK     SYSLOG+WALL+EXEC
NOTIFYFLAG COMMBAD    SYSLOG+WALL+EXEC
NOTIFYFLAG SHUTDOWN   SYSLOG+WALL+EXEC
NOTIFYFLAG REPLBATT   SYSLOG+WALL+EXEC
NOTIFYFLAG NOCOMM     SYSLOG+WALL+EXEC
NOTIFYFLAG NOPARENT   SYSLOG+WALL+EXEC

 

Simple notification script

 

sudo vi /etc/nut/notifycmd.sh

 

#!/bin/bash
EMAIL='to@YOYR_EMAIL.com'
echo -e "Subject: UPS ALERT Basic: $NOTIFYTYPE\n\nUPS: $UPSNAME\r\nAlert type: $NOTIFYTYPE\n\n\nThis is a basic notification!" | msmtp $EMAIL
Exec rights
 
# Change group to nut
sudo chown :nut /etc/nut/notifycmd.sh
# Add execution
sudo chmod 774 /etc/nut/notifycmd.sh
# Restart the NUT services
sudo systemctl restart nut-server.service
sudo systemctl restart nut-driver.service
sudo systemctl restart nut-monitor.service
 

Extra notification script by Scheduler

Set signals

At the end of the conf file:
sudo vi /etc/nut/upsmon.conf

 

Add signals and script

 

# Extra notifications by scheduler
NOTIFYCMD /sbin/upssched
NOTIFYFLAG ONBATT   SYSLOG+WALL+EXEC
NOTIFYFLAG ONLINE   SYSLOG+WALL+EXEC
NOTIFYFLAG REPLBATT SYSLOG+WALL+EXEC

 

Set schedule triggers

enable CMDSCRIPT
sudo vi /etc/nut/upssched.conf

 Add or replace the line:

CMDSCRIPT /bin/upssched-cmd
Add triggers  
# Command pipe and lock-file
PIPEFN /var/run/nut/upssched.pipe
LOCKFN /var/run/nut/upssched.lock

# Send alerts immediately on change in line power
AT ONBATT * EXECUTE onbatt
AT ONLINE * EXECUTE onpower

# (Optional) Silence the beeper after 1 minute
AT ONBATT * START-TIMER mute_beeper 60
AT ONLINE * CANCEL-TIMER mute_beeper

# Shutdown after 40 minutes on battery (40 * 60 = 1200)
AT ONBATT * START-TIMER onbatt_shutdown 2400

# Cancel timer if power's restored
AT ONLINE * CANCEL-TIMER onbatt_shutdown

# Battery replacement indicated by cron'd quick test
AT REPLBATT * EXECUTE replace_batt

Set program, emails and logs

 

Emails example

 

echo -e "Subject: UPS ALERT: $NOTIFYTYPE Power outage, on battery\n\nUPS: $UPSNAME\r\nAlert type: $NOTIFYTYPE\n\nActions:\n\n\t - UPS will be muted in 1 min\n\n\t - Intel NUC shutdown at 90% battery\n\n\t - System shutdown after 40 min on battery run" | msmtp $EMAIL
echo -e "Subject: UPS ALERT: $NOTIFYTYPE Power restored\n\nUPS: $UPSNAME\r\nAlert type: $NOTIFYTYPE" | msmtp $EMAIL
echo -e "Subject: UPS ALERT: $NOTIFYTYPE Power outage, on battery, mute beeper\n\nUPS: $UPSNAME\r\nAlert type: $NOTIFYTYPE\n\nActions:\n\n\t - UPS will be muted in 1 min\n\n\t - Intel NUC shutdown at 90% battery\n\n\t - System shutdown after 40 min on battery run" | msmtp $EMAIL
echo -e "Subject: UPS ALERT: $NOTIFYTYPE Power outage, shutdown system after 40 minutes\n\nUPS: $UPSNAME\r\nAlert type: $NOTIFYTYPE\n\nActions:\n\n\t - System shutdown after 40 min on battery run" | msmtp $EMAIL
echo -e "Subject: UPS ALERT: $NOTIFYTYPE Quick self-test\n\nUPS: $UPSNAME\r\nAlert type: $NOTIFYTYPE" | msmtp $EMAIL

  

My addition to using emails

Now add this as new into the existing program file:

 

sudo vi /bin/upssched-cmd

 Bash

# START: User-specific settings                            
#
UPS_USERNAME="admin"
UPS_PASSWORD="<PASSWORD>"
UPS_LINK="Powercom800W@localhost"
EMAIL="to@YOUR_DOMAIN.com"
# END  

case $1 in
    onbatt)
        # make sure beeper is enabled
        upscmd -u ${UPS_USERNAME} -p ${UPS_PASSWORD} ${UPS_LINK} beeper.enable
        # alert
        echo -e "Subject: UPS ALERT: $NOTIFYTYPE Power outage, on battery\n\nUPS: $UPSNAME\r\nAlert type: $NOTIFYTYPE\n\nActions:\n\n\t - UPS will be muted in 1 min\n\n\t - Intel NUC shutdown at 90% battery\n\n\t - System shutdown if battery level low at 10-20%" | msmtp $EMAIL
        message="Power outage, on battery"
        logger -t upssched-cmd "$message"
        ;;
    onpower)
        message="Power restored"
        echo -e "Subject: UPS ALERT: $NOTIFYTYPE Power restored\n\nUPS: $UPSNAME\r\nAlert type: $NOTIFYTYPE" | msmtp $EMAIL
        logger -t upssched-cmd "$message"
        ;;
    mute_beeper)
         message="(1) minute limit exceeded, muting beeper"
         echo -e "Subject: UPS ALERT: $NOTIFYTYPE Power outage, on battery, mute beeper\n\nUPS: $UPSNAME\r\nAlert type: $NOTIFYTYPE\n\nActions:\n\n\t - UPS will be muted in 1 min\n\n\t - Intel NUC shutdown at 90% battery\n\n\t - System shutdown if battery level low at 10-20%" | msmtp $EMAIL
         upscmd -u ${UPS_USERNAME} -p ${UPS_PASSWORD} ${UPS_LINK} beeper.mute
         ;;
    onbatt_shutdown)
        message="Triggering shutdown on battery charge level 10%-20%"
        echo -e "Subject: UPS ALERT: $NOTIFYTYPE Power outage, shutdown system after 40 minutes\n\nUPS: $UPSNAME\r\nAlert type: $NOTIFYTYPE\n\nActions:\n\n\t - System shutdown if battery level low at 10-20%" | msmtp $EMAIL
        logger -t upssched-cmd "$message"
        /sbin/upsmon -c fsd
        ;;
    replace_batt)
        message="Quick self-test indicates battery requires replacement"
        echo -e "Subject: UPS ALERT: $NOTIFYTYPE Quick self-test\n\nUPS: $UPSNAME\r\nAlert type: $NOTIFYTYPE" | msmtp $EMAIL
        logger -t upssched-cmd "$message"
        ;;
    *)
        logger -t upssched-cmd "Unrecognized command: $1"
        ;;
esac

 

More options

NOTIFY FLAGS and NOTIFYMSG

 About: https://networkupstools.org/docs/man/upsmon.html

More monstrous config:
sudo vi /etc/nut/upsmon.conf

 

# Full config:
NOTIFYCMD /sbin/upssched

# Events with battery
NOTIFYFLAG ONLINE     SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT     SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT    SYSLOG+WALL+EXEC
NOTIFYFLAG REPLBATT   SYSLOG+WALL+EXEC
NOTIFYFLAG SHUTDOWN   SYSLOG+WALL+EXEC
# Events with UPS
NOTIFYFLAG FSD        SYSLOG+WALL+EXEC
NOTIFYFLAG COMMOK     SYSLOG+WALL+EXEC
NOTIFYFLAG COMMBAD    SYSLOG+WALL+EXEC
NOTIFYFLAG NOCOMM     SYSLOG+WALL+EXEC
NOTIFYFLAG NOPARENT   SYSLOG+WALL+EXEC
# Messages with battery
NOTIFYMSG ONLINE    "UPS %s on line power"
NOTIFYMSG ONBATT    "UPS %s on battery"
NOTIFYMSG LOWBATT   "UPS %s battery is low"
NOTIFYMSG REPLBATT  "UPS %s battery needs to be replaced"
NOTIFYMSG SHUTDOWN  "Auto logout and shutdown proceeding"
# Messages with UPS
NOTIFYMSG FSD       "UPS %s: forced shutdown in progress"
NOTIFYMSG COMMOK    "Communications with UPS %s established"
NOTIFYMSG COMMBAD   "Communications with UPS %s lost"
NOTIFYMSG NOCOMM    "UPS %s is unavailable"
NOTIFYMSG NOPARENT  "upsmon parent process died - shutdown impossible"

Scheduler program

Possible error in service

Failed to connect to parent and failed to create parent: see PIPEFN/LOCKFN
  - Create a path: sudo mkdir -p /var/run/nut/
  - Make 770: sudo chmod 770 -R /var/run/nut/
  - Add user 770: sudo chown :nut -R /var/run/nut/
 

Extended program

AT <**EVENT**> * **ACTION** Do an action or cancel an action.
 
sudo vi /etc/nut/upssched.conf
 
CMDSCRIPT /etc/nut/upssched-cmd
PIPEFN /var/run/nut/upssched.pipe
LOCKFN /var/run/nut/upssched.lock
# ============================================================================
# BAD communications warnings, wait 30 seconds before send, cancel if becomes OK in 60 sec!
AT COMMBAD * START-TIMER commbad 30
AT COMMOK * CANCEL-TIMER commbad commok
AT NOCOMM * EXECUTE commbad # No communication - send warning!
# Battery power, send email update on intervals: 1 min, 15 min, 1 hour, 1,5 hours, 2 hours.
AT ONBATT * START-TIMER onbatt 60  # 1 min
AT ONBATT * START-TIMER onbatt 900 # 15 min
AT ONBATT * START-TIMER onbatt 1800 # 30 min
AT ONBATT * START-TIMER onbatt 3600 # 1 Hour
AT ONBATT * START-TIMER onbatt 4800 # 1.5 Hours
AT ONBATT * START-TIMER onbatt 7200 # 2 Hours
AT ONBATT * START-TIMER onbatt 10800 # 3 Hours
AT ONLINE * CANCEL-TIMER onbatt online
# Low batterwy warning and command execute immediately!
AT LOWBATT * EXECUTE onbatt
# When battery is bad - execute immediately!
AT REPLBATT * EXECUTE badbatt
# Shutdown at low batt execute immediately!
AT SHUTDOWN * EXECUTE powerdown
AT FSD * EXECUTE powerdownforced
# Service died:
AT NOPARENT * EXECUTE servicedown
Check statuses

Extended Program file

sudo vi /etc/nut/upssched-cmd

 

#!/bin/sh
UPS_USERNAME="admin"
UPS_PASSWORD="PASSWD"
UPS_LINK="Powercom800W@localhost"
EMAIL="it@EMAIL"

# Variables:
set_variables () {
    DATUM=`/bin/date`
    STAT=`upsc Powercom800W@localhost ups.status 2>&1 | grep -v '^Init SSL'`
    BATT=`upsc Powercom800W@localhost battery.charge 2>&1 | grep -v '^Init SSL'`
    BATT_t=`upsc Powercom800W@localhost battery.temperature 2>&1 | grep -v '^Init SSL'`
    BATT_LOW=`upsc Powercom800W@localhost battery.charge.low 2>&1 | grep -v '^Init SSL'`
    BATT_WARN=`upsc Powercom800W@localhost battery.charge.warning	 2>&1 | grep -v '^Init SSL'`
    RUNTIME=`upsc Powercom800W@localhost battery.runtime 2>&1 | grep -v '^Init SSL'`
    BEEPER=`upsc Powercom800W@localhost ups.beeper.status 2>&1 | grep -v '^Init SSL'`
    TESTRES=`upsc Powercom800W@localhost ups.test.result 2>&1 | grep -v '^Init SSL'`
    INP_FREQ=`upsc Powercom800W@localhost input.frequency 2>&1 | grep -v '^Init SSL'`
    INP_V=`upsc Powercom800W@localhost input.voltage 2>&1 | grep -v '^Init SSL'`
    INP_V_Nom=`upsc Powercom800W@localhost input.voltage.nominal 2>&1 | grep -v '^Init SSL'`
    OUT_FREQ=`upsc Powercom800W@localhost output.frequency 2>&1 | grep -v '^Init SSL'`
    OUT_V=`upsc Powercom800W@localhost output.voltage 2>&1 | grep -v '^Init SSL'`
    OUT_V_Nom=`upsc Powercom800W@localhost output.voltage.nominal 2>&1 | grep -v '^Init SSL'`
    # UPSLOG=`cat /var/log/messages | grep ups | tail -50`
    BASIC_INFO="
Date:                   $DATUM
Status:                 $STAT (OL online)
Charge level:           $BATT | Warning: $BATT_WARN Low: $BATT_LOW (shutdown at low!)
Runtime EST:            $RUNTIME

==================================================================================
##################################################################################
Input Freq:             $INP_FREQ
Input Voltage:          $INP_V
Input Voltage nominal:  $INP_V_Nom
==================================================================================
Input Freq:             $OUT_FREQ
Input Voltage:          $OUT_V
Input Voltage nominal:  $OUT_V_Nom
==================================================================================
Sound signal:           $BEEPER | (enabled\disabled)
Battery temp:           $BATT_t
Battery low:            $BATT_LOW - set at /etc/nut/ups.conf
Battery warn:           $BATT_WARN - set at /etc/nut/ups.conf
Battery test state:     $TESTRES - at CRON
"
}

disable_beep () {
    # Disable BEEP
    # But my model is beeping even on disabling, better not touch it.
    # /bin/upscmd -u ${UPS_USERNAME} -p ${UPS_PASSWORD} ${UPS_LINK} beeper.toggle
    /bin/upscmd -u ${UPS_USERNAME} -p ${UPS_PASSWORD} ${UPS_LINK} beeper.disable
}

wake_on_lan () {
    # Wake media box device:
    sudo wakeonlan -i 192.168.1.9 -p 4343 1C:69:7A:AB:54:E6
}

# Programms
case $1 in
    onbatt)
        disable_beep
        set_variables
        message="Power outage, on battery"
        logger -t upssched-cmd "$message"
        echo "Subject: UPS ALERT $NOTIFYTYPE power is down!\r\n\n$UPSNAME - $NOTIFYTYPE\n\n$BASIC_INFO\n\nEnd" | msmtp $EMAIL ;;
    badbatt)
        set_variables
        message="Bad battery, replace!"
        logger -t upssched-cmd "$message" 
        echo "Subject: UPS ALERT $NOTIFYTYPE bad battery!\r\n\n$UPSNAME - $NOTIFYTYPE\n\n$BASIC_INFO\n\nEnd" | msmtp $EMAIL ;;
    online)
        set_variables
        message="Power is back!"
        logger -t upssched-cmd "$message" 
        echo "Subject: UPS ALERT $NOTIFYTYPE power is back!\r\n\n$UPSNAME - $NOTIFYTYPE\n\n$BASIC_INFO\n\nEnd" | msmtp $EMAIL
        wake_on_lan ;;
    commbad)
        set_variables
        message="Communication is bad with UPS!"
        logger -t upssched-cmd "$message" 
        echo "Subject: UPS ALERT $NOTIFYTYPE communications is down!\r\n\n$UPSNAME - $NOTIFYTYPE\n\n$BASIC_INFO\n\nEnd" | msmtp $EMAIL ;;
    commok)
        set_variables
        message="Comminication with UPS restored!"
        logger -t upssched-cmd "$message" 
        echo "Subject: UPS ALERT $NOTIFYTYPE communications restored!\r\n\n$UPSNAME - $NOTIFYTYPE\n\n$BASIC_INFO\n\nEnd" | msmtp $EMAIL ;;
    powerdown)
        set_variables
        message="Shut down the system"
        logger -t upssched-cmd "$message" 
        echo "Subject: UPS ALERT $NOTIFYTYPE system shutdown initiated!\r\n\n$UPSNAME - $NOTIFYTYPE\n\n$BASIC_INFO\n\nEnd" | msmtp $EMAIL ;;
    powerdownforced)
        set_variables
        message="Shutdown the system FORCED"
        logger -t upssched-cmd "$message" 
        echo "Subject: UPS ALERT $NOTIFYTYPE forced system shutdown!\r\n\n$UPSNAME - $NOTIFYTYPE\n\n$BASIC_INFO\n\nEnd" | msmtp $EMAIL ;;
    servicedown)
        set_variables
        message="UPS Service died!"
        logger -t upssched-cmd "$message" 
        echo "Subject: UPS ALERT $NOTIFYTYPE service died, need restart!\r\n\n$UPSNAME - $NOTIFYTYPE\n\n$BASIC_INFO\n\nEnd" | msmtp $EMAIL ;;
    test_email)
        echo "Setting variables"
        set_variables
        echo "sending test email: $BASIC_INFO"
        echo "Subject: UPS ALERT $NOTIFYTYPE test email!\r\n\n$UPSNAME - $NOTIFYTYPE\n\n$BASIC_INFO\n\nEnd" | msmtp $EMAIL ;;
    *)
        echo "wrong parameter" ;;
esac

exit 0

Check permissions

 Additional fixes:

# Change group to nut
sudo chown :nut /etc/nut/upssched-cmd
# Add execution
sudo chmod 774 /etc/nut/upssched-cmd
# Restart the NUT services
sudo systemctl restart nut-server.service && sudo systemctl restart nut-monitor.service
sudo systemctl status nut-server.service && sudo systemctl status nut-monitor.service

Test script

sudo /usr/bin/upssched-cmd onbatt
sudo /usr/bin/upssched-cmd online
sudo /usr/bin/upssched-cmd badbatt
sudo /usr/bin/upssched-cmd test_email

 Check for issues

See logs: journalctl -n 200 -f | grep nut
 
See error: exec_cmd(/etc/nut/upssched-cmd onbatt) returned 2

Fix: check the program for typos and run it manually in a console.

Bad comm for this device

See: https://networkupstools.org/ddl/Powercom/RPT-600AP.html

Example for BADCOMM workaround:
#!/bin/bash
/usr/bin/logger -t NOTIFYCMD "${NOTIFYTYPE} ${UPSNAME}"
if [ "${NOTIFYTYPE}" = "COMMBAD" ]; then
  /usr/bin/logger -t NOTIFYCMD "Restarting upsdrvctl..."
  /sbin/upsdrvctl stop
  /sbin/upsdrvctl -D start
fi

Test exec

Use this template to send a test email and change the body as you want:

 

#!/bin/sh

NOTIFYTYPE='NOTIFYTYPE TEST'
UPSNAME='UPSNAME TEST'

EMAIL="it@DOMAIN.com"

# Variables:
set_variables () {
    DATUM=`/bin/date`
    STAT=`upsc Powercom800W@localhost ups.status 2>&1 | grep -v '^Init SSL'`
    BATT=`upsc Powercom800W@localhost battery.charge 2>&1 | grep -v '^Init SSL'`
    BATT_t=`upsc Powercom800W@localhost battery.temperature 2>&1 | grep -v '^Init SSL'`
    BATT_LOW=`upsc Powercom800W@localhost battery.charge.low 2>&1 | grep -v '^Init SSL'`
    BATT_WARN=`upsc Powercom800W@localhost battery.charge.warning	 2>&1 | grep -v '^Init SSL'`
    RUNTIME=`upsc Powercom800W@localhost battery.runtime 2>&1 | grep -v '^Init SSL'`
    BEEPER=`upsc Powercom800W@localhost ups.beeper.status 2>&1 | grep -v '^Init SSL'`
    TESTRES=`upsc Powercom800W@localhost ups.test.result 2>&1 | grep -v '^Init SSL'`
    INP_FREQ=`upsc Powercom800W@localhost input.frequency 2>&1 | grep -v '^Init SSL'`
    INP_V=`upsc Powercom800W@localhost input.voltage 2>&1 | grep -v '^Init SSL'`
    INP_V_Nom=`upsc Powercom800W@localhost input.voltage.nominal 2>&1 | grep -v '^Init SSL'`
    OUT_FREQ=`upsc Powercom800W@localhost output.frequency 2>&1 | grep -v '^Init SSL'`
    OUT_V=`upsc Powercom800W@localhost output.voltage 2>&1 | grep -v '^Init SSL'`
    OUT_V_Nom=`upsc Powercom800W@localhost output.voltage.nominal 2>&1 | grep -v '^Init SSL'`
    # UPSLOG=`cat /var/log/messages | grep ups | tail -50`
    BASIC_INFO="
Date:                   $DATUM
Status:                 $STAT (OL online)
Charge level:           $BATT | Warning: $BATT_WARN Low: $BATT_LOW (shutdown at low!)
Runtime EST:            $RUNTIME

==================================================================================
##################################################################################
Input Freq:             $INP_FREQ
Input Voltage:          $INP_V
Input Voltage nominal:  $INP_V_Nom
==================================================================================
Input Freq:             $OUT_FREQ
Input Voltage:          $OUT_V
Input Voltage nominal:  $OUT_V_Nom
==================================================================================
Sound signal:           $BEEPER | (enabled\disabled)
Battery temp:           $BATT_t
Battery low:            $BATT_LOW - set at /etc/nut/ups.conf
Battery warn:           $BATT_WARN - set at /etc/nut/ups.conf
Battery test state:     $TESTRES - at CRON
"
}

disable_beep () {
    # Disable BEEP
    /bin/upscmd -u ${UPS_USERNAME} -p ${UPS_PASSWORD} ${UPS_LINK} beeper.disable
}

set_variables
disable_beep
echo "Subject: UPS ALERT $NOTIFYTYPE test!\r\n\nUPS $UPSNAME - $NOTIFYTYPE\n\n$BASIC_INFO\n\nEnd" | msmtp $EMAIL

exit 0

 

Setup SSL

Use the doc from above, do not set certs in a usual Linux dir at pi, use as described in the official doc, and let it be.

Note: it finished with invalid directive CERTFILE /usr/local/ups/etc/upsd.pem - so do not bother to use this, no SSL then.

Path to open SSL: /usr/bin/openssl
openssl req -new -x509 -nodes -out upsd.crt -keyout upsd.key
...
openssl x509 -hash -noout -in upsd.crt

# Add certs
sudo mkdir -p /usr/local/ups/etc/certs
sudo chmod 0755 /usr/local/ups/etc/certs
sudo cp upsd.crt /usr/local/ups/etc/certs/f0626ddf.0

# Create the combined file for upsd
sudo cat upsd.crt upsd.key > upsd.pem
sudo chown root:nut upsd.pem
sudo chmod 0640 upsd.pem

# Server-side
sudo mv upsd.pem /usr/local/ups/etc/upsd.pem

# Add line 375+
sudo vi /etc/nut/upsmon.conf
CERTFILE /usr/local/ups/etc/upsd.pem


# Clean:
rm -f upsd.crt upsd.key

# Point upsmon at the certificates
sudo vi /etc/nut/upsmon.conf

# Path, line 373
CERTPATH /usr/local/ups/etc/certs

# Line 400+
CERTVERIFY 1
FORCESSL 1

 Restart the client and see:

sudo service nut-client restart && sudo service nut-client status
Mar 07 14:30:15 raspberrypi nut-monitor[1295564]: /etc/nut/upsmon.conf line 376: invalid directive CERTFILE /usr/local/ups/etc/upsd.pem

# OR

Mar 07 14:33:53 raspberrypi nut-monitor[1297153]: Init SSL with cerificate database located at /usr/local/ups/etc/certs
Mar 07 14:33:53 raspberrypi nut-monitor[1297153]: Can not initialize SSL context
Do not use SSL now.

 

 

Restart the NUT services

 

sudo systemctl restart nut-server.service && sudo systemctl restart nut-monitor.service
# ???
sudo systemctl restart nut-driver.service

# Check
sudo service nut-server status && sudo service nut-client status

 

Cron self-test

sudo crontab -e
 
# ┌───────────── minute (0–59)
# │ ┌───────────── hour (0–23)
# │ │ ┌───────────── day of the month (1–31)
# │ │ │ ┌───────────── month (1–12)
# │ │ │ │ ┌───────────── day of the week (0–6) (Sunday to Saturday;
# │ │ │ │ │                                   7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * <command to execute>

# Montly each 1st day at 10AM UPS self-test
0  10  1   *   *       /bin/upscmd -u admin -p PASSWD Powercom800W@localhost test.battery.start.quick

 

CMD Control

Check supported upscmd

 
Any non-listed command would return: Unexpected response from upsd: ERR CMD-NOT-SUPPORTED

 Out

Instant commands supported on UPS [Powercom800W]:

beeper.disable - Disable the UPS beeper
beeper.enable - Enable the UPS beeper
beeper.toggle - Toggle the UPS beeper
load.on - Turn on the load immediately
load.on.delay - Turn on the load with a delay (seconds)
shutdown.return - Turn off the load and return when power is back
shutdown.stayoff - Turn off the load and remain off
test.battery.start.quick - Start a quick battery test

 

Test

 

/bin/upscmd -u admin -p PASSWD Powercom800W@localhost beeper.toggle
/bin/upscmd -u admin -p PASSWD Powercom800W@localhost beeper.enable
/bin/upscmd -u admin -p PASSWD Powercom800W@localhost beeper.disable
# Will not work:
/bin/upscmd -u admin -p PASSWD Powercom800W@localhost battery.charge.low=11
# 
upsc Powercom800W@localhost ups.beeper.status 2>&1 | grep -v '^Init SSL'
upsc Powercom800W@localhost battery.charge.low 2>&1 | grep -v '^Init SSL'

 

Set variables: upsrw

 

# Show supported
/bin/upsrw -u admin -p PASSWD Powercom800W@localhost

# Should not work
/bin/upsrw -s battery.charge.low=11 -u admin -p PASSWD Powercom800W@localhost

# Supported only
/bin/upsrw -s ups.delay.shutdown=120 -u admin -p PASSWD Powercom800W@localhost

 

Listen to UPS from the local network

You can now listen to your UPS from another machine and shut it down if needed.
Usecase for windows.
 
Install, open and configure it according to your previous setup.

More

  • Logging periodical: https://networkupstools.org/docs/man/upslog.html
    • upslog is a daemon that will poll a UPS at periodic intervals, fetch the variables that interest you, format them, and write them to a file.
    • Separate dir: sudo mkdir -p /var/log/ups/
    • Access to dir: sudo chmod 776 -R /var/log/ups/
    • Access to dir: sudo chown user:user -R /var/log/ups/
    • run as user
      • upslog -s Powercom800W@localhost -f "%TIME @Y-@m-@d @H:@M:@S% -- Status: [%VAR ups.status%] | Charge: %VAR battery.charge% | Runtime: %VAR battery.runtime% sec | Load: %VAR ups.load% | t: %VAR battery.temperature% | Input V: %VAR input.voltage% Hz: %VAR input.frequency%" -l /var/log/ups/UPS_Powercom800W.log
    • Daemonize if needed
      • System daemon ADD HERE LINK TO MY SYSTEM DEAMON