apcmon: APC UPS monitor scripts

APC Smart-UPS

Got an APC Smart-UPS and running an unsupported UNIX?

Then grab apcmon.tar.gz and don't worry about whether PowerChute supports your UNIX system.

I wrote these scripts because PowerChute was not available for NetBSD. I now use them on FreeBSD, SunOS, Solaris, HP-UX, Linux and just about every other UNIX machine I've used these UPS's for.

The current version tells the UPS to do a soft shutdown (as the host shuts itself down that is :-), the UPS will then (after the configured delay - I use 5 min) drop power to the computers, wait for the mains to come back and once the batter has reached its configured minimum capacity (or after the configured delay) fires everything back up again. This all works very nicely for lights out operation.

Thanks to some detective work by Jason Keltz and others, apcmon can now break down the UPS status byte into its constituent bits. This means we now know more reliably when the UPS is on-line or not and can report when the battery is low or needs replacing.

Note that the archive includes a couple of useful generic utilities:

setopts.sh
Hides all the mess of handling options via getopt(1). For example:
# legal options
opt_str=o:vd:
# set some defaults
opt_d=/tmp

# process command line args
. setopts.sh

# and use the result
echo opt_o=$opt_o
echo opt_v=$opt_v
echo opt_d=$opt_d
only1.sh
Used to ensure only one copy of a script runs.
gend.sh
A generic script which implements all the magic needed to provide a reliable daemon in Bourne shell. Uses both the above. apcmon and apcwatch are implemented using gend.sh.
Read apcmon(8) for more details.

NOTE: APC claim you must use the correct cable, such as the one APC ship with PowerChute (normally bundled with the UPS I think). APC's manual states that a normal RS232C cable will not work and cause damage... I've not tested this claim, but you've been warned. Having said all that, check out APC info which provides additional info on the APC protocol and indicates that you do not need APC's cable.

APC Backup-UPS

For those with a backup UPS rather than the on-line Smart-UPS, you can try Dan Fraser's backupsd.


Simon J. Gerraty <sjg@crufty.net>