Homelab power outage? How to configure UPS SNMP shutdown in Linux
Learn how to monitor your UPS via SNMP on Linux and automate the safe shutdown of your home servers before the battery runs out.
Summary
- The SNMP protocol allows power devices to communicate battery status over the local network without dedicated serial cables
- Tools like NUT manage critical power events and trigger remote shutdown commands on connected servers
- Configuring low battery triggers prevents file system corruption and hardware damage in home server setups
- Testing power failure simulations ensures the automation responds correctly before an actual blackout occurs
- Keeping the main router and switch on the same power line prevents signal loss during the monitoring phase
Why monitor your UPS via network in a homelab
Anyone running a home server or homelab knows that utility grid power is not always reliable. Sudden outages and voltage fluctuations can corrupt databases, damage ZFS partitions, and fry sensitive power supplies. To mitigate this risk, using an uninterruptible power supply (a battery backup system that keeps equipment running during power spikes or failures) is essential. In practice, this means your servers get a few minutes of extra life to gracefully wrap up tasks instead of suffering a hard power cut.
However, simply plugging servers into battery outlets does not solve everything. If the outage lasts longer than battery capacity, the UPS will eventually shut down due to depleted charge, cutting power abruptly. To prevent this, we need a communication bridge between the power hardware and the server operating systems. This is where SNMP (Simple Network Management Protocol, a standard internet protocol used to collect and organize information about device behavior on IP networks) comes in, allowing the UPS to send critical battery level alerts directly to Linux. Building a robust infrastructure also requires planning for network resilience, a concept similar to what we discussed about how to ensure consistency in event-driven architectures when dealing with distributed failures.
The role of SNMP protocol and Network UPS Tools
SNMP acts as a universal messenger on the local network. The UPS features a network management card or agent that exposes vital metrics—such as battery charge, input voltage, and remaining runtime—in a database format known as MIB (Management Information Base, a dictionary that standardizes the name and meaning of each device data point). Your Linux server can poll this data periodically or receive immediate traps when an adverse electrical grid event occurs.
To translate these alerts into practical operating system actions, the open-source industry standard tool is NUT (Network UPS Tools). NUT is split into three main layers: the driver that talks directly to the UPS USB, serial, or SNMP card; the server that centralizes this information; and the clients that monitor status and execute safety scripts. When NUT detects that battery levels have reached a critical threshold, it initiates an automated orderly shutdown routine, gracefully stopping Docker containers, unmounting volumes, and halting services.
How to install and configure NUT for SNMP monitoring
To put this automation into practice on Linux, the first step is to install the Network UPS Tools package on your distribution of choice, such as Debian or Ubuntu. Open the terminal with administrative privileges and run the following commands to prepare the environment:
sudo apt update
sudo apt install nut nut-server nut-clientWith the binaries installed, the next step is to configure the driver file so NUT knows how to talk to your UPS via SNMP. Edit the driver configuration file located at /etc/nut/ups.conf and add the stanza defining the connection to your UPS SNMP card IP address.
[myups]
driver = snmp-ups
port = 192.168.1.50
community = public
pollinterval = 10In practice, this configuration instructs the snmp-ups driver to query the IP address 192.168.1.50 every ten seconds using the default SNMP community. Next, configure the upsd.users file to define secure access credentials and the nut.conf file to set the service operation mode as standalone or network-synced.
Setting up automatic shutdown and testing the system
The final configuration step involves the upsmon.conf file, where we determine monitor client behavior. This is where we define whether the server should merely alert users or execute a definitive shutdown command when power runs out. To ensure the process happens without human intervention, we specify action rules based on battery state.
Inside upsmon.conf, add the directive that monitors the previously configured UPS, specifying the access privilege type and the execution script. The typical format for local monitoring follows the structure below:
MONITOR myups@localhost 1 admin secure_password master
SHUTDOWNCMD "/sbin/shutdown -h now"After adjusting all parameters and restarting NUT services with the command sudo systemctl restart nut-server, your system will be ready to protect your homelab. It is recommended to perform a practical test by unplugging the UPS power cord from the wall outlet for a few moments (if your load allows) to verify that system logs record the event and the shutdown trigger responds as expected, ensuring data integrity and hardware longevity.
Final thoughts on resilience in homelabs
Integrating a UPS via SNMP in Linux turns a simple battery backup into an active, intelligent component of your home infrastructure. By automating safe shutdowns, you remove the surprise factor of power failures and protect your hardware and storage investments against destructive voltage spikes. Maintaining automated power control is just as crucial for environment health as choosing the right deployment and automation tools, where reliability and predictability prevent future maintenance headaches.