how to monitor APC 2200 UPS with apcupsd icinga/nagios

Download and install apcupsd-3.14.10-1.el4.i386.rpm package,
if you are using serial to usb cable you should have usbutils.i686 package.
Install also lm_sensors and net-snmp net-snmp-libs packages.
In this case, I made the physical connection with serial cable between CentOS linux box and UPS APC 2200.

[root@UPS1-2200-Linux ~]# dmesg | grep tty
console [tty0] enabled
serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
00:10: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A


[root@UPS1-2200-Linux ~]# chkconfig apcupsd on


[root@UPS1-2200-Linux ~]# /etc/init.d/apcupsd start
Starting UPS monitoring:Terminating due to configuration file errors.
[FAILED]


cat /var/log/apcupsd.events
2014-02-18 00:26:09 +1000 apcupsd FATAL ERROR in linux-usb.c at line 609
Cannot find UPS device --
For a link to detailed USB trouble shooting information,
please see <http://www.apcupsd.com/support.html>.

We have to configure right settings in **/etc/apcupsd/apcupsd.conf**


UPSNAME APC-SMART-UPS
UPSCABLE smart
UPSTYPE apcsmart
DEVICE /dev/ttyS0
LOGSTATS on


[root@UPS1-2200-Linux ~]# apcaccess
APC : 001,051,1262
DATE : 2014-02-17 16:00:58 +0200
HOSTNAME : UPS1-2200-Linux
VERSION : 3.14.10 (13 September 2011) redhat
UPSNAME : APC-SMART-UPS
CABLE : Custom Cable Smart
DRIVER : APC Smart UPS (any)
UPSMODE : Stand Alone
STARTTIME: 2014-02-17 16:00:44 +0200
MODEL : SMART-UPS 2200
STATUS : ONLINE
LINEV : 222.3 Volts
LOADPCT : 8.3 Percent Load Capacity
BCHARGE : 100.0 Percent
TIMELEFT : 144.0 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME : 0 Seconds
MAXLINEV : 223.6 Volts
MINLINEV : 221.0 Volts
OUTPUTV : 222.3 Volts
SENSE : High
DWAKE : 000 Seconds
DSHUTD : 020 Seconds
DLOWBATT : 02 Minutes
LOTRANS : 196.0 Volts
HITRANS : 253.0 Volts
RETPCT : 000.0 Percent
ITEMP : 30.6 C Internal
ALARMDEL : 5 seconds
BATTV : 55.6 Volts
LINEFREQ : 50.0 Hz
LASTXFER : Automatic or explicit self test
NUMXFERS : 0
TONBATT : 0 seconds
CUMONBATT: 0 seconds
XOFFBATT : N/A
SELFTEST : NO
STESTI : 336
STATFLAG : 0x07000008 Status Flag
DIPSW : 0x00 Dip Switch
REG1 : 0x00 Register 1
REG2 : 0x00 Register 2
REG3 : 0x00 Register 3
MANDATE : 11/28/03
SERIALNO : YS0348111512
BATTDATE : 11/28/03
NOMOUTV : 230 Volts
NOMBATTV : 48.0 Volts
EXTBATTS : 0
FIRMWARE : 80.14.I
END APC : 2014-02-17 16:00:59 +0200
[root@UPS1-2200-Linux ~]#


[root@UPS1-2200-Linux ~]# apctest

2014-02-18 01:02:57 apctest 3.14.10 (13 September 2011) redhat
Checking configuration …
Attached to driver: apcsmart
sharenet.type = Network & ShareUPS Disabled
cable.type = Custom Cable Smart
mode.type = APC Smart UPS (any)
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

 

we need to stop apcupsd service


[root@UPS1-2200-Linux ~]# service apcupsd stop

and now try again


[root@UPS1-2200-Linux ~]# apctest

2014-02-17 16:02:37 apctest 3.14.10 (13 September 2011) redhat
Checking configuration …
Attached to driver: apcsmart
sharenet.type = Network & ShareUPS Disabled
cable.type = Custom Cable Smart
mode.type = APC Smart UPS (any)
Setting up the port …
Doing prep_device() …

You are using a SMART cable type, so I’m entering SMART test mode
Hello, this is the apcupsd Cable Test program.
This part of apctest is for testing Smart UPSes.
Please select the function you want to perform.

1) Query the UPS for all known values
2) Perform a Battery Runtime Calibration
3) Abort Battery Calibration
4) Monitor Battery Calibration progress
5) Program EEPROM
6) Enter TTY mode communicating with UPS
Q) Quit

Select function number:

 

We can monitor our ups status through web, it is simple


yum install httpd apcupsd-cgi


[root@UPS1-2200-Linux ~]# vim +577 /etc/httpd/conf/httpd.conf

ScriptAlias /cgi-bin/ “/var/www/apcupsd/”

#
# “/var/www/cgi-bin” should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory “/var/www/apcupsd”>
AllowOverride None
Options None
Order allow,deny
Allow from all

AddHandler cgi-script .cgi

Now, you can navigate


http://192.168.0.233/cgi-bin/multimon.cgi

apc2200-1

apc2200-2

apc2200-3

monitoring with nagios


yum install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel


yum --enablerepo=epel -y install nrpe nagios-plugins-all nagios-plugins-nrpe

chkconfig nrpe on

disable selinux

[root@UPS1-2200-Linux ~]# cat /etc/selinux/config
SELINUX=disabled


vim /etc/sudoers
#Defaults requiretty
nrpe ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/


vim /etc/nagios/nrpe.cfg

server_address=192.168.0.233
nrpe_user=nrpe
nrpe_group=nrpe
allowed_hosts=127.0.0.1,192.168.0.0/23
dont_blame_nrpe=1
command_prefix=/usr/bin/sudo
debug=1

command[check_apcupsd_bcharge]=/usr/lib/nagios/plugins/check_apcupsd -h 127.0.0.1 -w 95 -c 50 bcharge
command[check_apcupsd_itemp]= /usr/lib/nagios/plugins/check_apcupsd -w 37 -c 47 itemp
command[check_apcupsd_loadpct]=/usr/lib/nagios/plugins/check_apcupsd -w 75 -c 90 loadpct
command[check_apcupsd_timeleft]=/usr/lib/nagios/plugins/check_apcupsd -w 50 -c 20 timeleft

accept nrpe daemon with iptables

[root@UPS1-2200-Linux ~]# vim /etc/sysconfig/iptables

-A INPUT -m state –state NEW -m tcp -p tcp -s 192.168.0.0/23 –dport 5666 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp -s 0/0 –dport 5666 -j REJECT


/etc/init.d/nrpe restart

Sups=icinga

APC UPS on battery

Sups=test

APC UPS battery recharging

Sups=batrecharging

let’s check the log file

[root@UPS1-2200-Linux ~]# cat /var/log/apcupsd.events
2014-02-18 12:48:35 +0200 Power failure.
2014-02-18 12:48:40 +0200 Running on UPS batteries.
2014-02-18 16:08:02 +0200 Battery charge below low limit.
2014-02-18 16:08:02 +0200 Initiating system shutdown!
2014-02-18 16:08:02 +0200 User logins prohibited
2014-02-18 16:08:04 +0200 apcupsd exiting, signal 15
2014-02-18 16:08:04 +0200 apcupsd shutdown succeeded
2014-02-18 16:12:41 +0200 apcupsd 3.14.10 (13 September 2011) redhat startup succeeded

If you want to configure mail notification, please configure

yum install mailx


[root@UPS1-2200-Linux ~]# cat /etc/apcupsd/onbattery
#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the UPS
# goes on batteries.
# We send an email message to root to notify him.
#
[email protected]
APCUPSD_MAIL="/bin/mail"

HOSTNAME=`hostname`
MSG=”$HOSTNAME Power Failure !!!”
#
(
echo “Subject: $MSG”
echo ” ”
echo “$MSG”
echo ” ”
/sbin/apcaccess status
) | $APCUPSD_MAIL -s “$MSG” $SYSADMIN
exit 0

And you will receive similar mail when power failure appears

Subject: UPS1-2200-Linux Power Failure !!!

UPS1-2200-Linux Power Failure !!!

APC : 001,052,1291
DATE : 2014-02-18 16:53:55 +0200
HOSTNAME : UPS1-2200-Linux
VERSION : 3.14.10 (13 September 2011) redhat
UPSNAME : APC-SMART-UPS
CABLE : Custom Cable Smart
DRIVER : APC Smart UPS (any)
UPSMODE : Stand Alone
STARTTIME: 2014-02-18 16:12:30 +0200
MODEL : SMART-UPS 2200
STATUS : ONBATT
LINEV : 000.0 Volts
LOADPCT : 9.3 Percent Load Capacity
BCHARGE : 030.0 Percent
TIMELEFT : 37.0 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME : 0 Seconds
MAXLINEV : 000.0 Volts
MINLINEV : 000.0 Volts
OUTPUTV : 228.1 Volts
SENSE : High
DWAKE : 000 Seconds
DSHUTD : 020 Seconds
DLOWBATT : 02 Minutes
LOTRANS : 196.0 Volts
HITRANS : 253.0 Volts
RETPCT : 000.0 Percent
ITEMP : 34.2 C Internal
ALARMDEL : 5 seconds
BATTV : 53.0 Volts
LINEFREQ : 50.0 Hz
LASTXFER : Line voltage notch or spike
NUMXFERS : 1
XONBATT : 2014-02-18 16:53:50 +0200
TONBATT : 7 seconds
CUMONBATT: 7 seconds
XOFFBATT : N/A
SELFTEST : NO
STESTI : 336
STATFLAG : 0x07060010 Status Flag
DIPSW : 0x00 Dip Switch
REG1 : 0x00 Register 1
REG2 : 0x00 Register 2
REG3 : 0x00 Register 3
MANDATE : 11/28/03
SERIALNO : YS0348111512
BATTDATE : 11/28/03
NOMOUTV : 230 Volts
NOMBATTV : 48.0 Volts
EXTBATTS : 0
FIRMWARE : 80.14.I
END APC : 2014-02-18 16:53:57 +0200

configure /etc/apcupsd/offbattery , if you want to be notified when the power has returned


[root@UPS1-2200-Linux ~]# cat /etc/apcupsd/offbattery
#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the
# UPS goes back on to the mains after a power failure.
# We send an email message to root to notify him.
#
[email protected]
APCUPSD_MAIL="/bin/mail"

HOSTNAME=`hostname`
MSG=”$HOSTNAME Power has returned”
#
(
echo “Subject: $MSG”
echo ” ”
echo “$MSG”
echo ” ”
/sbin/apcaccess status
) | $APCUPSD_MAIL -s “$MSG” $SYSADMIN
exit 0

and you will receive similar message when the power has returned


Subject: UPS1-2200-Linux Power has returned

UPS1-2200-Linux Power has returned

APC : 001,052,1316
DATE : 2014-02-18 17:04:10 +0200
HOSTNAME : UPS1-2200-Linux
VERSION : 3.14.10 (13 September 2011) redhat
UPSNAME : APC-SMART-UPS
CABLE : Custom Cable Smart
DRIVER : APC Smart UPS (any)
UPSMODE : Stand Alone
STARTTIME: 2014-02-18 17:03:25 +0200
MODEL : SMART-UPS 2200
STATUS : ONLINE
LINEV : 226.2 Volts
LOADPCT : 8.3 Percent Load Capacity
BCHARGE : 046.0 Percent
TIMELEFT : 56.0 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME : 0 Seconds
MAXLINEV : 000.0 Volts
MINLINEV : 015.6 Volts
OUTPUTV : 230.4 Volts
SENSE : High
DWAKE : 000 Seconds
DSHUTD : 020 Seconds
DLOWBATT : 02 Minutes
LOTRANS : 196.0 Volts
HITRANS : 253.0 Volts
RETPCT : 000.0 Percent
ITEMP : 33.7 C Internal
ALARMDEL : 5 seconds
BATTV : 51.9 Volts
LINEFREQ : 50.0 Hz
LASTXFER : Line voltage notch or spike
NUMXFERS : 1
XONBATT : 2014-02-18 17:03:38 +0200
TONBATT : 0 seconds
CUMONBATT: 33 seconds
XOFFBATT : 2014-02-18 17:04:11 +0200
SELFTEST : NO
STESTI : 336
STATFLAG : 0x07040008 Status Flag
DIPSW : 0x00 Dip Switch
REG1 : 0x00 Register 1
REG2 : 0x00 Register 2
REG3 : 0x00 Register 3
MANDATE : 11/28/03
SERIALNO : YS0348111512
BATTDATE : 11/28/03
NOMOUTV : 230 Volts
NOMBATTV : 48.0 Volts
EXTBATTS : 0
FIRMWARE : 80.14.I
END APC : 2014-02-18 17:04:11 +0200

Leave a Reply

Your email address will not be published. Required fields are marked *