Network UPS Tools

Network UPS Tools#

NUT is a software which is able to monitor UPSs and take action when needed, such as shutting down a computer when the battery level is low.

See also

  • Network UPS Tools - ArchWiki [1]

  • nut - Debian Wiki [2]

Example for Eaton 650i USB#

  1. create the jobs directories

    mkdir -p /home/jobs/scripts/by-user/nut
    
  2. Install NUT

    apt-get install nut
    
  3. add the following to the UPS definitions file

    /etc/nut/nut.conf#
    1MODE=standalone
    
  4. add the following to the UPS configuration file

    /etc/nut/ups.conf#
    1[my_ups]
    2    pollonly
    3    driver = usbhid-ups
    4    port = auto
    5    vendorid = "0463"
    6    productid = "FFFF"
    7    pollfreq = 30
    8    desc = "Eaton UPS on my pc"
    
  5. add the following to the administrative user definitions file

    /etc/nut/upsd.users#
    1[user]
    2    password = password
    3    upsmon master
    4    actions = SET
    5    instcmds = ALL
    
  6. add the following to the configuration file for the monitoring daemon

    /etc/nut/upsmon.conf#
     1MONITOR my_ups@127.0.0.1 1 user password master
     2
     3NOTIFYFLAG ONBATT   SYSLOG+WALL+EXEC
     4NOTIFYFLAG LOWBATT  SYSLOG+WALL+EXEC
     5NOTIFYFLAG FSD      SYSLOG+WALL+EXEC
     6NOTIFYFLAG COMMOK   SYSLOG+WALL+EXEC
     7NOTIFYFLAG COMMBAD  SYSLOG+WALL+EXEC
     8NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC
     9NOTIFYFLAG REPLBATT SYSLOG+WALL+EXEC
    10NOTIFYFLAG NOCOMM   SYSLOG+WALL+EXEC
    11NOTIFYFLAG ONLINE   SYSLOG+WALL+EXEC
    12NOTIFYFLAG NOPARENT SYSLOG+WALL+EXEC
    13
    14NOTIFYCMD "/home/jobs/scripts/by-user/nut/ups_notify.sh"
    

    You can comment NOTIFYCMD or change it with a custom command. You can, for example, create a script like this script

    /home/jobs/scripts/by-user/nut/ups_notify.sh#
    1#!/usr/bin/env bash
    2
    3echo "$*" | gotify
    
  7. restart all NUT services

    systemctl restart nut-driver.service
    systemctl restart nut-server.service
    systemctl restart nut-monitor.service
    
  8. fix the permissions

    chmod 700 -R /home/jobs/scripts/by-user/nut
    chown -R nut:nut /home/jobs/scripts/by-user/nut
    
  9. remove the plug from the UPS and check if the NOTIFYCMD command is executed and if you get broadcast messages on the terminal, such as

    Broadcast message from ...
    UPS my_ups@127.0.0.1 on battery
    
  10. put the plug back in the UPS

Footnotes