View Full Version : [SOLVED] nut upsstatus.cgi issuing "connection failure: connection refused" messages

February 23rd, 2011, 08:15 PM
I configured nut to monitor my UPS and control my workstation's shutdown. After I got it working, I installed the nut-cgi package for a nicer interface to check on the status of the UPS. My nut configuration was set up and working properly already. I added the information to hosts.conf so the CGI program would return the monitoring data.

When I fired up the script through my web browser, it was able to list the UPS, but where the data was supposed to be, I just got the message:

Connection failure: connection refused.

My hosts.conf file contains:

MONITOR smart-ups@myserver "smart-ups: APC Smart-UPS 1100XL on MyServer"

Here's what I get as a status page:

Network UPS Tools upsstats 2.4.3
Wed Feb 23 14:06:39 EST 2011
System Model Status Battery Input (VAC) Output (VAC) Load (%) UPS
Temp Battery
Runtime Data
smart-ups: APC Smart-UPS 1100XL on MyServer [error: Connection failure: Connection refused] [error: Connection failure: Connection refused] All data

I verified that upsd was running and responding correctly.

Can somebody tell me how to fix this so I can use the CGI script to display my UPS status?

February 23rd, 2011, 08:34 PM
After hours of pointless web searching, including the Ubuntu forums, I came up empty. But reading posts about nut-related problems gave me the idea of reviewing my configuration files and trying various changes.

The solution, it turns out, has to do with the network security implemented by nut itself. In my /etc/nut/hosts.conf file, I added the entry "smart-ups@myserver", which is the UPS on my server named "myserver". upsmon, upsd, and my web server running upsstats.cgi, are all on the same machine.

I was running nut in Standalone mode and had nothing customized in upsd.conf, so upsd was binding to the default port, as if the following entry were there:

LISTEN 3493The result was that upsd binds to a specific network interface, in this case (that is, localhost), or the loopback interface, lo. Because I specified the server name in hosts.conf, upsstats.cgi was attempting to access upsd at address, which is my Ethernet interface, eth1, on myserver.

The fix was to modify hosts.conf from "smart-ups@myserver" to "smart-ups@localhost" to direct upsstats.cgi to use the correct interface.

Now it works and I have my nice UPS status display.