8FF4E83F070F84928525761F0048C8F7 MMAE 7VBHSX f h 500x500

Intro

For some reason no rpm package for apcupsd is available for CentOS 6, it is however available for CentOS 7 from the epel repo.

These notes focus on compiling, installing and setting up apcupsd for CentOS 6.

 

Getting the source and installing (compiling) it

Go here; https://sourceforge.net/projects/apcupsd/?source=directory and download the latest version.

Go to your Downloads folder and untar the archive, then start compiling the source for your system.

cd ~/Downloads
tar -xvf apcupsd-3.14.14.tar.gz
cd apcupsd-3.14.14
./configure --enable-usb

If the above configure step fails, you may want to check that your system has the needed dev tools installed.

yum groupinstall "Development Tools"

When installed, rerun the configure.

./configure --enable-usb
make
make install

 

Connecting the UPS

If the UPS is brand-new; remove the plate at the bottom of the UPS and connect the battery; plus to plus, minus to minus, otherwise continue below. Replace the plate when done.

Shutdown your computer system and disconnect your computer power plug/s from the wall and connect it/them to the UPS using any of the four plugs marked BATTERY BACKUP + SURGE PROTECTION.

Connect the supplied RJ11-to-USB from the UPS to the computer.

Connect the UPS to the electrical outlet in the wall.

The UPS should beep a few times, blink the green LED after whoch the green LED will stay on lit if the power-up went well.

Boot your computer.

After boot, check /var/log/messages for something like the below. This indicates the computer found the usb-conencted UPS.

tail /var/log/messages
Jul 8 12:56:42 cyndane2 kernel: usb 1-3.2: new low speed USB device number 4 using ehci_hcd
Jul 8 12:56:42 cyndane2 kernel: usb 1-3.2: New USB device found, idVendor=051d, idProduct=0002
Jul 8 12:56:42 cyndane2 kernel: usb 1-3.2: New USB device strings: Mfr=3, Product=1, SerialNumber=2
Jul 8 12:56:42 cyndane2 kernel: usb 1-3.2: Product: Back-UPS ES 700G FW:871.O4 .I USB FW:O4
Jul 8 12:56:42 cyndane2 kernel: usb 1-3.2: Manufacturer: APC
Jul 8 12:56:42 cyndane2 kernel: usb 1-3.2: SerialNumber: 123456789100
Jul 8 12:56:42 cyndane2 kernel: usb 1-3.2: configuration #1 chosen from 1 choice
Jul 8 12:56:42 cyndane2 kernel: generic-usb 0003:051D:0002.0005: hiddev96,hidraw4: USB HID v1.10 Device [APC Back-UPS ES 700G FW:871.O4 .I USB FW:O4 ] on usb-0000:00:1a.7-3.2/input0

 

Configure the daemon

The config file is in /etc/apcupsd/apcupsd.conf. Edit it with eg nano.

nano /etc/apcupsd/apcupsd.conf

Change the following lines to your specification.

UPSNAME ups1
UPSCABLE usb
UPSTYPE usb
DEVICE <blank>

Please note, the DEVICE line must not be commented. It must be there but the device should be blanked.

The below lines can be left with their default settings, or changed to suit your situation.

ONBATTERYDELAY 6
BATTERYLEVEL 5
MINUTES 3
TIMEOUT 0
NETSERVER on

The NETSERVER must be on in order to check the UPS status with apcaccess. Check any of the sources below to find out what the settings do!

 

Testing the UPS

Stop the apcupsd(aemon) if started.

service apcupsd stop
apctest

The presented test functions should be fairly self-explanatory.

 

Halt scripts

Check /etc/rc.d/init.d/halt to ensure it has apcupsd setting updated at the end.

nano /etc/rc.d/init.d/halt

 

 

Enable the daemon

chkconfig --list | grep apc
apcupsd 0:off 1:off 2:off 3:off 4:off 5:off 6:off 
chkconfig apcupsd on
chkconfig --list | grep apc
apcupsd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

 

Control apcupsd

service apcupsd start
service apcupsd stop
service apcupsd restart
apcaccess status

 

See current UPS status

apcaccess

 

Web based monitoring

This part aims to present the data collected from the UPS with pretty bars and graphs on a web page using cgi.

 

Enable CGI

Earlier we just used the --enable usb parameter to tell the installer we had a USB-type UPS. If we want to also enable CGI, we need to run the below.

It doesn't matter if you already have a working apcupsd install, you can run this without breaking anything.

./configure --enable-usb --enable-cgi --with-cgi-bin=/var/www/cgi-bin/apcupsd-cgi

 

What the above does is

  • Enable USB, because we have a USB-type UPS.
  • Enable the CGI bits.
  • Tells the installer where to save the cgi-scripts. The default is /etc/apcupsd, which may not be optimal.

 

If you get this error after running ./configure..., you need to install libgd.

configure: 
error: Your system lacks the GD library which is needed for compiling the apcupsd CGI programs.
Please install libgd and re-run the ./configure script. Alternatively you can disable the CGI support.

 

For CentOS 6 it couldn't be found in the usual repos, but a Google search later revealed where to find it; https://centos.pkgs.org/6/centos-x86_64/gd-devel-2.0.35-11.el6.x86_64.rpm.html.

Therefore; 

yum install http://mirror.centos.org/centos/6/os/x86_64/Packages/gd-devel-2.0.35-11.el6.x86_64.rpm

 

Install it and re-run the ./configure as above.

On a successful run, you should now see the below

Configuration complete: Run 'make' to build apcuspd.

 

Run make and make install as earlier.

When done, you should see new contents in /var/www/cgi-bin/apcupsd-cgi.

root@cyndane2:/var/www/cgi-bin/apcupsd-cgi # ll
total 384
drwxr-xr-x 2 root root 4096 Nov 30 15:53 .
drwxr-xr-x. 3 root root 4096 Nov 30 15:39 ..
-rwxr-xr-x 1 root root 99256 Nov 30 15:53 multimon.cgi
-rwxr-xr-x 1 root root 83746 Nov 30 15:53 upsfstats.cgi
-rwxr-xr-x 1 root root 96980 Nov 30 15:53 upsimage.cgi
-rwxr-xr-x 1 root root 94399 Nov 30 15:53 upsstats.cgi

 

Present the stuff

Before we actually present the pretty graphs and bars, we need to enable them.

This is done by adding a line to /etc/apcupsd/apcupsd.conf. Find the line NETSERVER and set it to on. Save and exit.

# nano /etc/apcupsd/apcupsd.conf

NETSERVER on

 

Next we need to add a line to /etc/apcupsd/hosts.conf.

Edit /etc/apcupsd/hosts.conf and at the end, add the name of the host you want to monitor as well as a label string for them. Save and exit.

# nano /etc/apcupsd/hosts.conf
...
MONITOR 192.168.0.8 "cyndane2"


Test if it works.

$ /var/www/cgi-bin/apcupsd-cgi/multimon.cgi

Content-Type: text/html; charset=utf-8
Content-Language: en
Pragma: no-cache
...

 

If you see lots of html-code flashing by, it's working!

 

Actual testing

Browsing to 192.168.0.8/cgi-bin/multimon.cgi with a web browser got me a 404.

So...

Added /etc/httpd/conf.d/apc.conf with info from https://stackoverflow.com/questions/21698645/how-to-run-cgi-script-on-apache-server.

 

/etc/httpd/conf.d/apc.conf:

ErrorLog /var/log/httpd/apcupsd-error
CustomLog /var/log/httpd/apcups common

Alias /ups "/var/www/cgi-bin/apcupsd-cgi"
DirectoryIndex multimon.cgi

<Directory /var/www/cgi-bin>
AddHandler cgi-script .cgi
Options FollowSymLinks ExecCGI
AllowOverride None
</Directory>

 

Save and exit your editor. Restart httpd for good measure.

# service httpd restart

 

Again entering 192.168.0.8/ups/multimon.cgi in a browser produces this.

{modal images/pics/FAQ/apcupsd.Screenshot.at.2018-11-30.16-30-45.png}{/modal}

 

Woo-hoo basically!

 

Security issues and firewall settings

This part is being researched.

  • apcupsd runs as root.
  • Anyone on the network can read the UPS status. May or may not be a problem. Privileged information? Normally little risk.
  • NISPORT, default TCP/3551
  • You may wish to configure your firewall(s) to only allow connections from your local network or specifically from the masters, slaves, and servers as needed.

 

 

Sources

https://www.cyberciti.biz/faq/debian-ubuntu-centos-rhel-install-apcups/

https://www.svennd.be/install-apcupsd-on-centos-6/

https://www.svennd.be/install-apcupsd-on-centos-7/

http://www.apcupsd.org/manual/manual.html (use "http" for this link)

https://www.apc.com/shop/se/sv/products/APC-Power-Saving-Back-UPS-ES-8-Outlet-700VA-230V-CEE-7-7/P-BE700G-GR

https://sourceforge.net/p/apcupsd/mailman/message/28185650/

http://www.apcupsd.org/manual/manual.html#monitoring-and-tuning-your-ups

https://stackoverflow.com/questions/21698645/how-to-run-cgi-script-on-apache-server

 

 

 

 

 

 

 

Stop Spam Harvesters, Join Project Honey Pot

 

Get a free SSL certificate!

 

The leading nonprofit defending digital privacy, free speech, and innovation.

 

The Linux Foundation provides a neutral, trusted hub for developers and organizations to code, manage, and scale open technology projects and ecosystems.

 

Kubuntu is an operating system built by a worldwide community of developers, testers, supporters and translators.

 

 43ef5c89 CanonicalUbuntudarktext