Header Shadow Image


UPS Monitoring: Linux apcupsd Back-UPS RS 1000G

Time to setup some APC ( Battery bacup or uninterruptible power supply – UPS ) monitoring for the home equipment.  The tool we’ll use for this is the APCUPSD daemon available in RPM format. We’ve set one up for our HTPCB server for a home redundancy / backup solution to protect against power surges and bridge the various power outages in the neighborhood that have been happening recently.

apcupsd-cgi.x86_64 : Web interface for apcupsd
apcupsd-gui.x86_64 : GUI interface for apcupsd
apcupsd.x86_64 : APC UPS Power Control Daemon for Linux

Unfortunately, when setting it up and configuring it, we got this result:

 

Sep  6 22:27:01 mbpc apcupsd[12526]: apcupsd FATAL ERROR in linux-usb.c at line 605#012Cannot open UPS device: "/dev/ttyS0" --#012For a link to detailed USB trouble shooting information,#012please see <http://www.apcupsd.com/support.html>.
Sep  6 22:27:01 mbpc apcupsd[12526]: apcupsd error shutdown completed

 

Here’s how we went about solving this one.  APC uses HID so it should be using one of the corresponding hid* devices in /dev:

# ls -al /dev/hiddev0
ls: cannot access /dev/hiddev0: No such file or directory
# ls -al /dev/usb
usb/     usbmon0  usbmon1  usbmon2  usbmon3  usbmon4  usbmon5  usbmon6  usbmon7
# ls -al /dev/usb/hiddev0
crw-rw----. 1 root root 180, 96 Sep  6 01:49 /dev/usb/hiddev0

# service apcupsd restart
Shutting down UPS monitoring:                              [FAILED]
Starting UPS monitoring:                                   [  OK  ]
# apctest
2012-09-06 22:39:32 apctest 3.14.10 (13 September 2011) redhat
Checking configuration ...
Attached to driver: usb
sharenet.type = Network & ShareUPS Disabled
cable.type = USB Cable
mode.type = USB UPS Driver
Setting up the port ...
apctest FATAL ERROR in linux-usb.c at line 605
Cannot open UPS device: "/dev/usb/hiddev0" --

For a link to detailed USB trouble shooting information,
please see <http://www.apcupsd.com/support.html>.
apctest error termination completed

Unfortunately, the only one available above, doesn’t list anything.  When trying to use /dev/ttyS0 instead, we got this:

Sep  8 00:33:03 mbpc apcupsd[16170]: apcupsd FATAL ERROR in smartsetup.c at line 70#012Cannot open UPS port : No such file or directory
Sep  8 00:33:03 mbpc apcupsd[16170]: apcupsd error shutdown completed

and

# lspci|grep -i american

doesn’t list any entries either and lsusb freezes at the command line.  The last thing we did is look at the USB messages in dmesg and /var/log/messages for any clues to the issue.  Sure enough, we found some clues that could fit into the output of USB commands above:

usb 3-4: usbfs: USBDEVFS_CONTROL failed cmd lsusb rqt 128 rq 6 len 255 ret -110
usb 3-4: usbfs: USBDEVFS_CONTROL failed cmd lsusb rqt 128 rq 6 len 255 ret -110
usb 3-4: usbfs: USBDEVFS_CONTROL failed cmd lsusb rqt 128 rq 6 len 255 ret -110
usb 3-4: usbfs: USBDEVFS_CONTROL failed cmd lsusb rqt 128 rq 6 len 10 ret -110
usb 3-4: usbfs: USBDEVFS_CONTROL failed cmd lsusb rqt 128 rq 6 len 4 ret -110
usbfs: USBDEVFS_CONTROL failed cmd lsusb rqt 128 rq 6 len 255 ret -110
usb 3-3: USB setup failed (-19).
usb 3-3: USB setup failed (-19).

usb 3-4: usbfs: USBDEVFS_CONTROL failed cmd lsusb rqt 128 rq 0 len 2 ret -108
usb 3-4: USB disconnect, device number 3

 

usb 3-3: Atheros AR9170 is registered as 'phy0'
usb 3-3: USB disconnect, device number 2
[] usb_disconnect+0xee/0x220
[] usb_unbind_interface+0x124/0x170
[] usb_disable_device+0xb0/0x2a0
[] usb_set_configuration+0x185/0x7f0
[] usb_unbind_device+0x1a/0x20
[] usb_disconnect+0xee/0x220
[] usb_unbind_interface+0x124/0x170
[] usb_disable_device+0xb0/0x2a0
[] usb_set_configuration+0x185/0x7f0
[] usb_unbind_device+0x1a/0x20
[] usb_disconnect+0xee/0x220
[] usb_unbind_interface+0x124/0x170
[] usb_disable_device+0xb0/0x2a0
[] usb_set_configuration+0x185/0x7f0
[] usb_unbind_device+0x1a/0x20
[] usb_disconnect+0xee/0x220
[] usb_unbind_interface+0x124/0x170
[] usb_disable_device+0xb0/0x2a0
[] usb_set_configuration+0x185/0x7f0
[] usb_unbind_device+0x1a/0x20
[] usb_disconnect+0xee/0x220
[] usb_unbind_interface+0x124/0x170
[] usb_disable_device+0xb0/0x2a0
[] usb_set_configuration+0x185/0x7f0
[] usb_unbind_device+0x1a/0x20

We also refer to the apcupsd.com manual pages for some hints and confirmation if in fact APC does use HID or not.  And it does use HID.  This is important because at least we have an idea exactly where to look for or to add to the DEVICE parameter in the apcupsd.conf file.

Of course, some are due to other devices.  Ultimately, we tested the cables with a different system and OS, a Windows 7 workstation, to ensure results were the same and activity will be seen in some fashion.  True enough one cable showed activity, the other didn’t.  So we swapped the cables to the HTPC but still the results were the same as above.  Meanwhile, we tested the first cable on the Windows 7 workstation, and this time no activity was found on that cable.  So it looks like the cable might have been part of the problem though there is a bit of doubt in that Windows 7 might have simply already installed the software earlier when the second cable was plugged in first so no activity might have shown for the first cable.  Irrespective of that, we decided to do a reboot of the HTPC server to find out if that would make a difference.  And it looks like it did.  This time the devices file didn’t halt and results were written (unlike before):

# cat /proc/bus/usb/devices|grep -i american
S:  Manufacturer=American Power Conversion
#

# cat /proc/bus/usb/devices|sed -e '/./{H;$!d;}' -e 'x;/American/!d;'

T:  Bus=07 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=12   MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=051d ProdID=0002 Rev= 0.90
S:  Manufacturer=American Power Conversion
S:  Product=Back-UPS RS 1000G FW:869.L3 .D USB FW:L3
S:  SerialNumber=REDACT
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=  2mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid
E:  Ad=81(I) Atr=03(Int.) MxPS=   8 Ivl=100ms
#

# ls -altri /dev/usb/hiddev*
6241 crw-rw----. 1 root root 180, 96 Sep  8 14:27 /dev/usb/hiddev0
6270 crw-rw----. 1 root root 180, 97 Sep  8 14:27 /dev/usb/hiddev1
#

# grep -v "#" /etc/apcupsd/apcupsd.conf|sed -e "/^$/d"
UPSCABLE usb
UPSTYPE usb
DEVICE /dev/usb/hiddev1
LOCKFILE /var/lock
SCRIPTDIR /etc/apcupsd
PWRFAILDIR /etc/apcupsd
NOLOGINDIR /etc
ONBATTERYDELAY 6
BATTERYLEVEL 5
MINUTES 3
TIMEOUT 0
ANNOY 300
ANNOYDELAY 60
NOLOGON disable
KILLDELAY 0
NETSERVER on
NISIP 0.0.0.0
NISPORT 3551
EVENTSFILE /var/log/apcupsd.events
EVENTSFILEMAX 10
UPSCLASS standalone
UPSMODE disable
STATTIME 5
STATFILE /var/log/apcupsd.status
LOGSTATS on
DATATIME 1
#

And running service apcupsd restart gave us the results we’ve been looking for.

Sep  8 14:40:18 mbpc apcupsd[4881]: 000.0,000.0,000.0,27.14,00.00,18.0,00.0,000.0,000.0,120.0,100.0,1
Sep  8 14:40:20 mbpc apcupsd[4881]: 000.0,000.0,000.0,27.14,00.00,18.0,00.0,000.0,000.0,120.0,100.0,0
Sep  8 14:40:20 mbpc apcupsd[4881]: APC      : 001,036,0887
Sep  8 14:40:20 mbpc apcupsd[4881]: DATE     : 2012-09-08 14:40:19 -0400
Sep  8 14:40:20 mbpc apcupsd[4881]: HOSTNAME : mbpc
Sep  8 14:40:20 mbpc apcupsd[4881]: VERSION  : 3.14.10 (13 September 2011) redhat
Sep  8 14:40:20 mbpc apcupsd[4881]: UPSNAME  : mbpc
Sep  8 14:40:20 mbpc apcupsd[4881]: CABLE    : USB Cable
Sep  8 14:40:20 mbpc apcupsd[4881]: DRIVER   : USB UPS Driver
Sep  8 14:40:20 mbpc apcupsd[4881]: UPSMODE  : Stand Alone
Sep  8 14:40:20 mbpc apcupsd[4881]: STARTTIME: 2012-09-08 14:39:49 -0400
Sep  8 14:40:20 mbpc apcupsd[4881]: MODEL    : Back-UPS RS 1000G
Sep  8 14:40:20 mbpc apcupsd[4881]: STATUS   : ONLINE
Sep  8 14:40:20 mbpc apcupsd[4881]: LINEV    : 120.0 Volts
Sep  8 14:40:20 mbpc apcupsd[4881]: LOADPCT  :  18.0 Percent Load Capacity
Sep  8 14:40:20 mbpc apcupsd[4881]: BCHARGE  : 100.0 Percent
Sep  8 14:40:20 mbpc apcupsd[4881]: TIMELEFT :  57.9 Minutes
Sep  8 14:40:20 mbpc apcupsd[4881]: MBATTCHG : 5 Percent
Sep  8 14:40:20 mbpc apcupsd[4881]: MINTIMEL : 3 Minutes
Sep  8 14:40:20 mbpc apcupsd[4881]: MAXTIME  : 0 Seconds
Sep  8 14:40:20 mbpc apcupsd[4881]: SENSE    : Medium
Sep  8 14:40:20 mbpc apcupsd[4881]: LOTRANS  : 088.0 Volts
Sep  8 14:40:20 mbpc apcupsd[4881]: HITRANS  : 139.0 Volts
Sep  8 14:40:20 mbpc apcupsd[4881]: ALARMDEL : 30 seconds
Sep  8 14:40:20 mbpc apcupsd[4881]: BATTV    : 27.1 Volts
Sep  8 14:40:20 mbpc apcupsd[4881]: LASTXFER : Low line voltage
Sep  8 14:40:20 mbpc apcupsd[4881]: NUMXFERS : 0
Sep  8 14:40:20 mbpc apcupsd[4881]: TONBATT  : 0 seconds
Sep  8 14:40:20 mbpc apcupsd[4881]: CUMONBATT: 0 seconds
Sep  8 14:40:20 mbpc apcupsd[4881]: XOFFBATT : N/A
Sep  8 14:40:20 mbpc apcupsd[4881]: SELFTEST : NO
Sep  8 14:40:20 mbpc apcupsd[4881]: STATFLAG : 0x07000008 Status Flag
Sep  8 14:40:20 mbpc apcupsd[4881]: SERIALNO : REDACT
Sep  8 14:40:20 mbpc apcupsd[4881]: BATTDATE : 2012-03-21
Sep  8 14:40:20 mbpc apcupsd[4881]: NOMINV   : 120 Volts
Sep  8 14:40:20 mbpc apcupsd[4881]: NOMBATTV :  24.0 Volts
Sep  8 14:40:20 mbpc apcupsd[4881]: NOMPOWER : 600 Watts
Sep  8 14:40:20 mbpc apcupsd[4881]: FIRMWARE : 869.L3 .D USB FW:L3
Sep  8 14:40:20 mbpc apcupsd[4881]: END APC  : 2012-09-08 14:40:20 -0400
Sep  8 14:40:21 mbpc apcupsd[4881]: 000.0,000.0,000.0,27.14,00.00,18.0,00.0,000.0,000.0,120.0,100.0,1

And sure enough, apcaccess now worked fine:

# apcaccess
APC      : 001,036,0899
DATE     : 2012-09-08 15:00:04 -0400
HOSTNAME : mbpc
VERSION  : 3.14.10 (13 September 2011) redhat
UPSNAME  : Back-UPS.XS.1000
CABLE    : USB Cable
DRIVER   : USB UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2012-09-08 15:00:02 -0400
MODEL    : Back-UPS RS 1000G
STATUS   : ONLINE
LINEV    : 119.0 Volts
LOADPCT  :  18.0 Percent Load Capacity
BCHARGE  : 100.0 Percent
TIMELEFT :  57.9 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
SENSE    : Medium
LOTRANS  : 088.0 Volts
HITRANS  : 139.0 Volts
ALARMDEL : 30 seconds
BATTV    : 27.1 Volts
LASTXFER : Low line voltage
NUMXFERS : 0
TONBATT  : 0 seconds
CUMONBATT: 0 seconds
XOFFBATT : N/A
SELFTEST : NO
STATFLAG : 0x07000008 Status Flag
SERIALNO : REDACT
BATTDATE : 2012-03-21
NOMINV   : 120 Volts
NOMBATTV :  24.0 Volts
NOMPOWER : 600 Watts
FIRMWARE : 869.L3 .D USB FW:L3
END APC  : 2012-09-08 15:00:43 -0400
#

Here is the final config file:

# grep -v "#" /etc/apcupsd/apcupsd.conf|sed -e "/^$/d"
UPSNAME Back-UPS.XS.1000
UPSCABLE usb
UPSTYPE usb
DEVICE /dev/usb/hiddev1
LOCKFILE /var/lock
SCRIPTDIR /etc/apcupsd
PWRFAILDIR /etc/apcupsd
NOLOGINDIR /etc
ONBATTERYDELAY 6
BATTERYLEVEL 5
MINUTES 3
TIMEOUT 0
ANNOY 300
ANNOYDELAY 60
NOLOGON disable
KILLDELAY 0
NETSERVER on
NISIP 0.0.0.0
NISPORT 3551
EVENTSFILE /var/log/apcupsd.events
EVENTSFILEMAX 10
UPSCLASS standalone
UPSMODE disable
STATTIME 0
STATFILE /var/log/apcupsd.status
LOGSTATS off
DATATIME 0
[root@mbpc ~]#

APC Test command should on the other hand give this output if the daemon is running (which is fine)

# apctest
2012-09-08 15:23:01 apctest 3.14.10 (13 September 2011) redhat
Checking configuration ...
Attached to driver: usb
sharenet.type = Network & ShareUPS Disabled
cable.type = USB Cable
mode.type = USB UPS Driver
Setting up the port ...
apctest FATAL ERROR in device.c at line 71
Unable to create UPS lock file.
If apcupsd or apctest is already running,
please stop it and run this program again.
apctest error termination completed
#

And you should be good.  Notice that the default apcupsd.conf file already included a time when it would shutdown the system if the UPS power falls below a certain level or time left: 3 minutes.  For us this was fine though you may wish to tweak this for your installation.

April 13 2013

A recent power outage lasted longer then the battery life allowed resulting in an automatic shutdown of the system.  Here are some messages of how this unfolded and worked:

Apr 11 12:45:40 mbpc apcupsd[18059]: Battery charge below low limit.
Apr 11 12:45:40 mbpc apcupsd[18059]: Initiating system shutdown!
Apr 11 12:45:40 mbpc wall[28627]: wall: user root broadcasted 1 lines (79 chars)
Apr 11 12:45:40 mbpc apcupsd[18059]: User logins prohibited
Apr 11 12:45:40 mbpc wall[28631]: wall: user root broadcasted 1 lines (50 chars)

Apr 11 12:45:41 mbpc init: tty (/dev/tty2) main process (18387) killed by TERM signal
Apr 11 12:45:41 mbpc init: tty (/dev/tty3) main process (18389) killed by TERM signal
Apr 11 12:45:41 mbpc init: tty (/dev/tty4) main process (18393) killed by TERM signal
Apr 11 12:45:41 mbpc init: tty (/dev/tty5) main process (18397) killed by TERM signal
Apr 11 12:45:41 mbpc init: tty (/dev/tty6) main process (18402) killed by TERM signal
Apr 11 12:45:45 mbpc init: prefdm main process (18382) killed by KILL signal

Oct 22 2023

Using the latest Ubuntu Desktop on my G73SW, which in turn is being used as an old server replacement and rack troubleshooting station.  Plugging in a APC UPS:

# tail -f /var/log/syslog
Oct 22 13:46:02 tom-G73Sw kernel: [ 6058.934071] usb 2-1.2: new full-speed USB device number 5 using ehci-pci
Oct 22 13:46:02 tom-G73Sw kernel: [ 6059.045107] usb 2-1.2: New USB device found, idVendor=051d, idProduct=0002, bcdDevice= 0.90
Oct 22 13:46:02 tom-G73Sw kernel: [ 6059.045130] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Oct 22 13:46:02 tom-G73Sw kernel: [ 6059.045138] usb 2-1.2: Product: Back-UPS RS 1000G FW:869.L3 .D USB FW:L3
Oct 22 13:46:02 tom-G73Sw kernel: [ 6059.045143] usb 2-1.2: Manufacturer: American Power Conversion
Oct 22 13:46:02 tom-G73Sw kernel: [ 6059.045148] usb 2-1.2: SerialNumber: REDACT
Oct 22 13:46:02 tom-G73Sw kernel: [ 6059.052350] hid-generic 0003:051D:0002.0004: hiddev1,hidraw3: USB HID v1.00 Device [American Power Conversion Back-UPS RS 1000G FW:869.L3 .D USB FW:L3 ] on usb-0000:00:1d.0-1.2/input0
Oct 22 13:46:02 tom-G73Sw mtp-probe: checking bus 2, device 5: "/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2"
Oct 22 13:46:02 tom-G73Sw mtp-probe: bus: 2, device: 5 was not an MTP device
Oct 22 13:46:02 tom-G73Sw mtp-probe: checking bus 2, device 5: "/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2"

And checking with lsusb:

root@tom-G73Sw:/var/log# lsusb|grep -Ei american
Bus 002 Device 005: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
root@tom-G73Sw:/var/log#

The configuration is set as follows:

root@tom-G73Sw:/var/log# grep -v "#" /etc/apcupsd/apcupsd.conf|sed -e "/^$/d"
UPSCABLE usb
UPSTYPE usb
DEVICE /dev/ttyS0
LOCKFILE /var/lock
SCRIPTDIR /etc/apcupsd
PWRFAILDIR /etc/apcupsd
NOLOGINDIR /etc
ONBATTERYDELAY 6
BATTERYLEVEL 5
MINUTES 3
TIMEOUT 0
ANNOY 300
ANNOYDELAY 60
NOLOGON disable
KILLDELAY 0
NETSERVER on
NISIP 127.0.0.1
NISPORT 3551
EVENTSFILE /var/log/apcupsd.events
EVENTSFILEMAX 10
UPSCLASS standalone
UPSMODE disable
STATTIME 0
STATFILE /var/log/apcupsd.status
LOGSTATS off
DATATIME 0
root@tom-G73Sw:/var/log#

But should be:

root@tom-G73Sw:/var/log# grep -v "#" /etc/apcupsd/apcupsd.conf|sed -e "/^$/d"
UPSCABLE usb
UPSTYPE usb
DEVICE
LOCKFILE /var/lock
SCRIPTDIR /etc/apcupsd
PWRFAILDIR /etc/apcupsd
NOLOGINDIR /etc
ONBATTERYDELAY 6
BATTERYLEVEL 5
MINUTES 3
TIMEOUT 0
ANNOY 300
ANNOYDELAY 60
NOLOGON disable
KILLDELAY 0
NETSERVER on
NISIP 127.0.0.1
NISPORT 3551
EVENTSFILE /var/log/apcupsd.events
EVENTSFILEMAX 10
UPSCLASS standalone
UPSMODE disable
STATTIME 0
STATFILE /var/log/apcupsd.status
LOGSTATS off
DATATIME 0
root@tom-G73Sw:/var/log#
root@tom-G73Sw:/var/log#

When the UPS is plugged in using the USB to RJ45 connector we get:

root@tom-G73Sw:/var/log# systemctl status apcupsd
? apcupsd.service - UPS power management daemon
Loaded: loaded (/lib/systemd/system/apcupsd.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2023-10-22 14:15:55 EDT; 2min 38s ago
Docs: man:apcupsd(8)
Process: 51616 ExecStartPre=/lib/apcupsd/prestart (code=exited, status=0/SUCCESS)
Process: 51620 ExecStart=/sbin/apcupsd (code=exited, status=0/SUCCESS)
Main PID: 51621 (apcupsd)
Tasks: 3 (limit: 18982)
Memory: 604.0K
CPU: 51ms
CGroup: /system.slice/apcupsd.service
??51621 /sbin/apcupsd

Oct 22 14:15:55 tom-G73Sw systemd[1]: Starting UPS power management daemon...
Oct 22 14:15:55 tom-G73Sw systemd[1]: apcupsd.service: Can't open PID file /run/apcupsd.pid (yet?) after start: Operation not permitted
Oct 22 14:15:55 tom-G73Sw apcupsd[51621]: apcupsd 3.14.14 (31 May 2016) debian startup succeeded
Oct 22 14:15:55 tom-G73Sw systemd[1]: Started UPS power management daemon.
Oct 22 14:15:55 tom-G73Sw apcupsd[51621]: NIS server startup succeeded
root@tom-G73Sw:/var/log#
root@tom-G73Sw:/var/log#
root@tom-G73Sw:/var/log# apcaccess
APC : 001,036,0872
DATE : 2023-10-22 14:17:58 -0400
HOSTNAME : tom-G73Sw
VERSION : 3.14.14 (31 May 2016) debian
UPSNAME : tom-G73Sw
CABLE : USB Cable
DRIVER : USB UPS Driver
UPSMODE : Stand Alone
STARTTIME: 2023-10-22 14:15:55 -0400
MODEL : Back-UPS RS 1000G
STATUS : ONLINE LOWBATT
LINEV : 118.0 Volts
LOADPCT : 0.0 Percent
BCHARGE : 0.0 Percent
TIMELEFT : 0.0 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME : 0 Seconds
SENSE : Medium
LOTRANS : 88.0 Volts
HITRANS : 139.0 Volts
ALARMDEL : No alarm
BATTV : 22.3 Volts
LASTXFER : No transfers since turnon
NUMXFERS : 0
TONBATT : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
SELFTEST : NO
STATFLAG : 0x05000048
SERIALNO : REDACT
BATTDATE : 2012-03-21
NOMINV : 120 Volts
NOMBATTV : 24.0 Volts
NOMPOWER : 600 Watts
FIRMWARE : 869.L3 .D USB FW:L3
END APC : 2023-10-22 14:18:47 -0400
root@tom-G73Sw:/var/log#

Time to restest the battery backup unit:

root@tom-G73Sw:/var/log# systemctl stop apcupsd
root@tom-G73Sw:/var/log# apctest

2023-10-22 14:40:08 apctest 3.14.14 (31 May 2016) debian
Checking configuration ...
sharenet.type = Network & ShareUPS Disabled
cable.type = USB Cable
mode.type = USB UPS Driver
Setting up the port ...
Doing prep_device() ...

You are using a USB cable type, so I'm entering USB test mode
Hello, this is the apcupsd Cable Test program.
This part of apctest is for testing USB UPSes.

Getting UPS capabilities...SUCCESS

Please select the function you want to perform.

1) Test kill UPS power
2) Perform self-test
3) Read last self-test result
4) View/Change battery date
5) View manufacturing date
6) View/Change alarm behavior
7) View/Change sensitivity
8) View/Change low transfer voltage
9) View/Change high transfer voltage
10) Perform battery calibration
11) Test alarm
12) View/Change self-test interval
Q) Quit

Select function number: 2

This test instructs the UPS to perform a self-test
operation and reports the result when the test completes.

Clearing previous self test result...CLEARED
Initiating self test...INITIATED
Waiting for test to complete...TEST DID NOT COMPLETE

1) Test kill UPS power
2) Perform self-test
3) Read last self-test result
4) View/Change battery date
5) View manufacturing date
6) View/Change alarm behavior
7) View/Change sensitivity
8) View/Change low transfer voltage
9) View/Change high transfer voltage
10) Perform battery calibration
11) Test alarm
12) View/Change self-test interval
Q) Quit

Select function number: 11

Testing alarm...COMPLETE

1) Test kill UPS power
2) Perform self-test
3) Read last self-test result
4) View/Change battery date
5) View manufacturing date
6) View/Change alarm behavior
7) View/Change sensitivity
8) View/Change low transfer voltage
9) View/Change high transfer voltage
10) Perform battery calibration
11) Test alarm
12) View/Change self-test interval
Q) Quit

Select function number:

Appears there isn’t too many options to test a faulty battery or get an error code out.  One thing I find interesting, that even with the battery removed, the UPS shows 100% battery charge.  How does that work and how am I supposed to interpret this?

root@tom-G73Sw:~# apcaccess
APC : 001,037,0937
DATE : 2023-10-23 00:47:04 -0400
HOSTNAME : tom-G73Sw
VERSION : 3.14.14 (31 May 2016) debian
UPSNAME : tom-G73Sw
CABLE : USB Cable
DRIVER : USB UPS Driver
UPSMODE : Stand Alone
STARTTIME: 2023-10-22 14:58:48 -0400
MODEL : Back-UPS RS 1000G
STATUS : ONLINE NOBATT
LINEV : 121.0 Volts
LOADPCT : 0.0 Percent
BCHARGE : 100.0 Percent
TIMELEFT : 75.0 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME : 0 Seconds
SENSE : Medium
LOTRANS : 88.0 Volts
HITRANS : 139.0 Volts
ALARMDEL : No alarm
BATTV : 27.1 Volts
LASTXFER : No transfers since turnon
NUMXFERS : 1
XONBATT : 2023-10-22 15:53:18 -0400
TONBATT : 0 Seconds
CUMONBATT: 3 Seconds
XOFFBATT : 2023-10-22 15:53:21 -0400
SELFTEST : NO
STATFLAG : 0x01200008
SERIALNO : REDACT
BATTDATE : 2012-03-21
NOMINV : 120 Volts
NOMBATTV : 24.0 Volts
NOMPOWER : 600 Watts
FIRMWARE : 869.L3 .D USB FW:L3
END APC : 2023-10-23 00:47:05 -0400
root@tom-G73Sw:~#

That’s fine for a single UPS but let’s use NUT (Network UPS Tools) package and configure that instead:

apt-get update && apt-get install nut nut-client nut-server

Then use the NUT scanner to find the UPS’s connected:


root@tom-G73Sw:~# nut-scanner
Neon library not found. XML search disabled.
IPMI library not found. IPMI search disabled.
Scanning USB bus.
No start IP, skipping SNMP
No start IP, skipping NUT bus (old connect method)
[nutdev1]
        driver = "usbhid-ups"
        port = "auto"
        vendorid = "051D"
        productid = "0002"
        product = "Back-UPS RS 1300G FW:863.L6 .D USB FW:L6"
        serial = "REDACT"
        vendor = "American Power Conversion"
        bus = "003"
[nutdev2]
        driver = "usbhid-ups"
        port = "auto"
        vendorid = "0764"
        productid = "0501"
        product = "CP1500AVRLCDa"
        serial = "REDACT"
        vendor = "CPS"
        bus = "002"
[nutdev3]
        driver = "usbhid-ups"
        port = "auto"
        vendorid = "0764"
        productid = "0501"
        product = "LX1500GU"
        serial = "REDACT"
        vendor = "CPS"
        bus = "002"
[nutdev4]
        driver = "usbhid-ups"
        port = "auto"
        vendorid = "0764"
        productid = "0501"
        product = "CP1500AVRLCDa"
        serial = "REDACT"
        vendor = "CPS"
        bus = "002"
root@tom-G73Sw:~#

Next, setup the /etc/nut/ups.conf file according to the above output from nut-scanner.  Effectively, you can just copy in the information from nut-scanner:


root@tom-G73Sw:~# grep -v "#" /etc/nut/ups.conf

maxretry = 3

[nutdev1]
        driver = "usbhid-ups"
        port = "auto"
        vendorid = "051D"
        productid = "0002"
        product = "Back-UPS RS 1300G FW:863.L6 .D USB FW:L6"
        serial = "REDACT"
        vendor = "American Power Conversion"
        bus = "003"
[nutdev2]
        driver = "usbhid-ups"
        port = "auto"
        vendorid = "0764"
        productid = "0501"
        product = "LX1500GU"
        serial = "REDACT"
        vendor = "CPS"
        bus = "001"
[nutdev3]
        driver = "usbhid-ups"
        port = "auto"
        vendorid = "0764"
        productid = "0501"
        product = "CP1500AVRLCDa"
        serial = "REDACT"
        vendor = "CPS"
        bus = "001"
[nutdev4]
        driver = "usbhid-ups"
        port = "auto"
        vendorid = "0764"
        productid = "0501"
        product = "CP1500AVRLCDa"
        serial = "REDACT"
        vendor = "CPS"
        bus = "001"
root@tom-G73Sw:~#

Start the device:


root@tom-G73Sw:~# upsdrvctl start
Network UPS Tools - UPS driver controller 2.7.4
Network UPS Tools - Generic HID driver 0.41 (2.7.4)
USB communication driver 0.33
Using subdriver: APC HID 0.96
Network UPS Tools - Generic HID driver 0.41 (2.7.4)
USB communication driver 0.33
Using subdriver: CyberPower HID 0.4
Network UPS Tools - Generic HID driver 0.41 (2.7.4)
USB communication driver 0.33
Using subdriver: CyberPower HID 0.4
Network UPS Tools - Generic HID driver 0.41 (2.7.4)
USB communication driver 0.33
Using subdriver: CyberPower HID 0.4
root@tom-G73Sw:~#

The output above indicates that each device was successfully detected.  Check the devices:


root@tom-G73Sw:~# upsc nutdev1@192.168.0.15
Init SSL without certificate database
battery.charge: 100
battery.charge.low: 10
battery.charge.warning: 50
battery.date: 2001/09/25
battery.mfr.date: 2016/04/15
battery.runtime: 2565
battery.runtime.low: 120
battery.type: PbAc
battery.voltage: 27.2
battery.voltage.nominal: 24.0
device.mfr: American Power Conversion
device.model: Back-UPS RS 1300G
device.serial: REDACT
device.type: ups
driver.name: usbhid-ups
driver.parameter.bus: 003
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.product: Back-UPS RS 1300G FW:863.L6 .D USB FW:L6
driver.parameter.productid: 0002
driver.parameter.serial: REDACT
driver.parameter.synchronous: no
driver.parameter.vendor: American Power Conversion
driver.parameter.vendorid: 051D
driver.version: 2.7.4
driver.version.data: APC HID 0.96
driver.version.internal: 0.41
input.sensitivity: medium
input.transfer.high: 147
input.transfer.low: 88
input.transfer.reason: input voltage out of range
input.voltage: 114.0
input.voltage.nominal: 120
ups.beeper.status: enabled
ups.delay.shutdown: 20
ups.firmware: 863.L6 .D
ups.firmware.aux: L6
ups.load: 15
ups.mfr: American Power Conversion
ups.mfr.date: 2016/04/15
ups.model: Back-UPS RS 1300G
ups.productid: 0002
ups.realpower.nominal: 780
ups.serial: REDACT
ups.status: OL
ups.test.result: No test initiated
ups.timer.reboot: 0
ups.timer.shutdown: -1
ups.vendorid: 051d
root@tom-G73Sw:~#



root@tom-G73Sw:~# upsc nutdev2@192.168.0.15
Init SSL without certificate database
battery.charge: 100
battery.charge.low: 10
battery.charge.warning: 20
battery.mfr.date: CPS
battery.runtime: 3810
battery.runtime.low: 300
battery.type: PbAcid
battery.voltage: 24.0
battery.voltage.nominal: 24
device.mfr: CPS
device.model: LX1500GU
device.serial: REDACT
device.type: ups
driver.name: usbhid-ups
driver.parameter.bus: 001
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.product: LX1500GU
driver.parameter.productid: 0501
driver.parameter.serial: REDACT
driver.parameter.synchronous: no
driver.parameter.vendor: CPS
driver.parameter.vendorid: 0764
driver.version: 2.7.4
driver.version.data: CyberPower HID 0.4
driver.version.internal: 0.41
input.voltage: 117.0
input.voltage.nominal: 120
output.voltage: 141.0
ups.beeper.status: enabled
ups.delay.shutdown: 20
ups.delay.start: 30
ups.load: 16
ups.mfr: CPS
ups.model: LX1500GU
ups.productid: 0501
ups.realpower.nominal: 900
ups.serial: REDACT
ups.status: OL
ups.test.result: No test initiated
ups.timer.shutdown: -60
ups.timer.start: -60
ups.vendorid: 0764


root@tom-G73Sw:~# upsc nutdev3@192.168.0.15
Init SSL without certificate database
battery.charge: 99
battery.charge.low: 10
battery.charge.warning: 20
battery.mfr.date: CPS
battery.runtime: 1291
battery.runtime.low: 300
battery.type: PbAcid
battery.voltage: 21.3
battery.voltage.nominal: 24
device.mfr: CPS
device.model: CP1500AVRLCDa
device.serial: REDACT
device.type: ups
driver.name: usbhid-ups
driver.parameter.bus: 001
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.product: CP1500AVRLCDa
driver.parameter.productid: 0501
driver.parameter.serial: REDACT
driver.parameter.synchronous: no
driver.parameter.vendor: CPS
driver.parameter.vendorid: 0764
driver.version: 2.7.4
driver.version.data: CyberPower HID 0.4
driver.version.internal: 0.41
input.voltage: 117.0
input.voltage.nominal: 120
output.voltage: 141.0
ups.beeper.status: enabled
ups.delay.shutdown: 20
ups.delay.start: 30
ups.load: 27
ups.mfr: CPS
ups.model: CP1500AVRLCDa
ups.productid: 0501
ups.realpower.nominal: 900
ups.serial: REDACT
ups.status: OL CHRG
ups.test.result: No test initiated
ups.timer.shutdown: -60
ups.timer.start: -60
ups.vendorid: 0764



root@tom-G73Sw:~# upsc nutdev4@192.168.0.15
Init SSL without certificate database
battery.charge: 100
battery.charge.low: 10
battery.charge.warning: 20
battery.mfr.date: CPS
battery.runtime: 3783
battery.runtime.low: 300
battery.type: PbAcid
battery.voltage: 22.2
battery.voltage.nominal: 24
device.mfr: CPS
device.model: CP1500AVRLCDa
device.serial: REDACT
device.type: ups
driver.name: usbhid-ups
driver.parameter.bus: 001
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.product: CP1500AVRLCDa
driver.parameter.productid: 0501
driver.parameter.serial: REDACT
driver.parameter.synchronous: no
driver.parameter.vendor: CPS
driver.parameter.vendorid: 0764
driver.version: 2.7.4
driver.version.data: CyberPower HID 0.4
driver.version.internal: 0.41
input.voltage: 113.0
input.voltage.nominal: 120
output.voltage: 137.0
ups.beeper.status: disabled
ups.delay.shutdown: 20
ups.delay.start: 30
ups.load: 13
ups.mfr: CPS
ups.model: CP1500AVRLCDa
ups.productid: 0501
ups.realpower.nominal: 900
ups.serial: REDACT
ups.status: OL
ups.test.result: No test initiated
ups.timer.shutdown: -60
ups.timer.start: -60
ups.vendorid: 0764
root@tom-G73Sw:~#

Note that netdev1-4 can be changed to something meaningful, however to identify each device, the correct bus, productid and vendorid must be provided as in the above configuration.  If defaults are given without specifying a bus only the first unit out of all the UPS’s will ever show up.  Next challenge is persistent naming on reboot.  Persistent naming requires persistent and static entries on the OS so they remain as defined across reboots.  Let’s follow the steps and generate a set of connections and configure everything else needed to get proper monitoring running for our UPS’s:


  1 #!/bin/bash -x
  2
  3 echo "CAUTION: This file will overwrite the NUT configuration you currently have.  Are you absolutely certain?"
  4 read CONFNUT;
  5 if [[ -z $CONFNUT ]]; then
  6         echo "Exiting. Bye!"
  7         exit 0;
  8 fi
  9
 10 # If missing, install pwgen.
 11 sudo apt install pwgen
 12
 13 export UPSMPASS=$(pwgen -snc -B 6 | awk '{ print $1 }')
 14
 15 # Stop the upsdrvctl service, regardless if running with correct UPS devices.
 16 upsdrvctl stop
 17 systemctl stop nut-server
 18
 19 # Build the /etc/nut/ups.conf file.
 20 echo -e "maxretry = 3\npollinterval = 5\n" > /etc/nut/ups.conf;
 21 nut-scanner -UNq >> /etc/nut/ups.conf;
 22
 23 # Start the upsdrvctl service.
 24 upsdrvctl start
 25
 26 # DANGEROUS:  Shuts down all UPS's
 27 # upsdrvctl shutdown              shutdown all UPS drivers in ups.conf
 28
 29
 30 # Set password in upsd.users
 31 echo -e "\n[monitor]\n\tpassword = $UPSMPASS\n\tupsmon master\n" > /etc/nut/upsd.users
 32
 33 # Setup monitor links in the /etc/nut/upsmon.conf file.
 34 for upsdevice in $(awk '{ if ( $1 ~ /nutdev/ ) { gsub(/\[|\]/, "", $1); print $1; } }'< /etc/nut/ups.conf); do 35 echo -e "$upsdevice@localhost 1 monitor $UPSMPASS master\n"; 36 done > /etc/nut/upsmon.conf
 37
 38 # Clear pass var
 39 unset UPSMPASS
 40
 41 # Set MAXAGE
 42 if [[ $(grep MAXAGE /etc/nut/upsd.conf) != "" ]]; then
 43         echo "MAXAGE 60" >> /etc/nut/upsd.conf
 44 fi
 45
 46 # Restart the nut-server
 47 systemctl restart nut-server
 48
 49 # List the UPS units connected.  Example output
 50 # upsc -l
 51 # Init SSL without certificate database
 52 # nutdev1
 53 # nutdev2
 54 # nutdev3
 55 #
 56 upsc -l

Next, let’s configure netdata.  This is a very compact Linux metrics utility that has one of the simplest installations I’ve seen.  Use the following setup to configure it on a remote port of your server, giving us the option to view the results remotely:


root@tom-G73Sw:~# grep -v "#" /etc/netdata/netdata.conf
[global]
        run as user = netdata
        web files owner = root
        web files group = root
        bind socket to IP = 0.0.0.0
root@tom-G73Sw:~#

Restart the service:

# systemctl status netdata && systemctl restart netdata && systemctl restart netdata

And enjoy the metrics data:

https://i0.wp.com/www.microdevsys.com/WordPressImages/UPS-Setup-NetData-Monitoring-NUT-Network-UPS-Tools.PNG?resize=2529%2C1354&ssl=1

Cheers,

Leave a Reply

You must be logged in to post a comment.


     
  Copyright © 2003 - 2013 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License