Project Overview
I recently installed a UPS (Uninterruptible Power Supply) in my server rack to protect my network equipment and servers from unexpected power outages. I connected my key devices to the UPS, including my Proxmox server, Synology NAS, and desktop computer. But that wasn’t enough—I wanted a smart way to monitor the UPS status across the network and safely shut down devices before the UPS battery runs dry.
Objectives
- Connect my Synology NAS to the UPS via USB to act as the NUT (Network UPS Tools) Server.
- Set up a NUT Client on my Proxmox server to safely shut it down during a power outage.
- Monitor UPS status through a web browser using Apache2 and nut-cgi.
- Get email alerts using Uptime Robot when the UPS loses power.
The Setup
Step 1: Connecting the Synology NAS to the UPS
The first step was simple: I connected my Synology NAS to the UPS using a USB cable. Once connected, the Synology NAS recognized the UPS and was able to act as a NUT Server for my entire network. This means the NAS can relay UPS status to other devices, allowing them to take action if power is lost.
Step 2: Setting Up a NUT Client on Proxmox
With the NUT Server on my NAS configured, I needed my Proxmox server to respond to the UPS status as well. I followed a few guides to set up an LXC container on my Proxmox server. This container acts as a NUT Client, communicating with the NUT Server on the Synology NAS.
The NUT Client is configured to monitor the UPS status and automatically trigger a safe shutdown of the entire Proxmox server if power is lost for an extended period. This ensures that my VMs and containers are protected from abrupt power loss.
Step 3: Monitoring the UPS with nut-cgi and Apache2
Monitoring the status of my UPS remotely was a must. I installed the nut-cgi
module along with Apache2 on the same LXC container to create a web-based dashboard. This setup allows me to monitor the status of the UPS, including battery levels and load, through any web browser.
With a quick login to the web interface, I can see real-time UPS metrics, making it easy to keep tabs on power status from anywhere on my network.
Step 4: Email Alerts with Uptime Robot
To take things a step further, I set up Uptime Robot to monitor the UPS status page for the keyword “Online.” If the UPS loses power and that keyword disappears, Uptime Robot sends me an email alert. This ensures I’m notified immediately if my UPS switches to battery power, giving me the chance to take additional actions if needed.
Challenges and Solutions
Issue 1: NUT Client Communication with NUT Server
This one was relatively easy. I followed the documentation and the guides I found, which provided step-by-step instructions on setting up the NUT Client to communicate with the NUT Server on my Synology NAS. It worked seamlessly, and I wouldn’t even classify it as much of an issue.
Issue 2: Setting Up nut-cgi with Apache2
While setting up the nut-cgi
module with Apache2 was pretty straightforward, I decided to go a step further by passing the website through my Cloudflare tunnel. This allowed me to access the UPS status remotely from any device and browser, which was incredibly convenient.
However, a challenge arose here. By default, the status page is accessed by navigating to something like 10.1.1.1/nut-cgi/nut/upsstats.cgi
(the IP address of my LXC container). The problem is that Cloudflare tunnels don’t allow you to map URLs that contain slashes like this. Cloudflare will only map an IP address to a website URL directly, not with additional paths.
The Solution
To get around this limitation, I modified the default Apache2 configuration. I set up a redirect so that any request going to 10.1.1.1
(the IP address of my LXC container, which Cloudflare points to) would automatically redirect to the full address of the UPS status page: 10.1.1.1/nut-cgi/nut/upsstats.cgi
.
Now, when I visit subdomain.domain.com
(the subdomain configured in Cloudflare), it automatically redirects me to subdomain.domain.com/nut-cgi/nut/upsstats.cgi
, giving me easy access to monitor the UPS remotely.
Outcome and Lessons Learned
The outcome has been fantastic! I now have a reliable setup that monitors the UPS, automatically shuts down critical systems like my Proxmox server during power outages, and provides me with real-time updates and alerts via Uptime Robot.
This project was a great reminder of the importance of proper power management in a home lab. I learned a lot about NUT Server and Client configurations, as well as how to work around URL mapping limitations with Cloudflare tunnels.
Future Plans
Moving forward, I plan to extend the NUT Client setup to more devices on my network. I also want to explore additional alerting mechanisms to further automate responses during a power loss. Perhaps I’ll dive into SMS alerts or other integrations with smart home systems.
Leave a Reply