Monitor a UPS with the NUT package

If you're using a UPS to safeguard your system from power outages, you need to make sure you are monitoring its performance. Find out how the Network UPS Tools (NUT) package completes your protection.

Having a UPS (uninterruptible power supply) connected to your system is a great way to ensure uptime, but without software to monitor the status of the UPS, the benefit provided may be no benefit at all. If the battery runs out and your system still hasn't shut down, then it would be as if no UPS was connected in the first place.

One software package that works with a wide variety of UPS hardware is the NUT package, or Network UPS Tools. You can download this package from http://www.networkupstools.org/, or it may be available with your Linux distribution.

Tips in your inbox
Delivered each Tuesday, TechRepublic's free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills.
Automatically sign up today!

NUT is straightforward, and the configuration file samples are heavily commented. To begin, Nut must be installed and you need to configure your UPS using the /etc/ups/ups.conf configuration file (the location of the file may vary from distribution to distribution). Defining a USB-based APC UPS, you may have a configuration file consisting of:

    driver = hidups
    port   = /dev/usb/hiddev0
    desc   = "My UPS"

This uses the hidups (USB-based) driver with the /dev/usb/hiddev0 device; the name of the UPS is myups. The default /etc/ups/upsd.conf should be sufficient for local monitoring with its default ACLs that allow localhost connections to the daemon.

Next, you need to define a user in /etc/ups/upsd.users that has access to the upsd daemon:

    password = secret
    allowfrom = localhost
    upsmon master

This defines the user monuser with the password secret and makes it a master upsmon user. Finally, edit /etc/ups/upsmon.conf to set a MONITOR directive for the host to monitor:

MONITOR myups@localhost 1 monuser secret master

This tells the upsmon daemon to connect to the UPS myups on the localhost as the user monuser with the password secret and indicates it is a UPS master user.

Once configuration is done, you can start the UPS daemon and monitor, usually with:

# /etc/init.d/upsd start
# /etc/init.d/upsmon start

Now, upsmon will connect to upsd and obtain status information (such as whether it's online, on battery, etc.) about the UPS.

About Vincent Danen

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

Editor's Picks