amerikanjunkie
various one
Registered: Aug 2000
Location:
Posts: 1731 |
Setting up APCUPSD
Setting Up APCUPSD [the laymans guide]
March 18th, 2006
http://cvcrud.jedicoder.net/?p=89
So Im sitting here staring at my “TO DO” list for the back end stuff, and my eyes fix on the “Setup APCUPSD“… “ok what the hell”, I think. Not that it isnt already setup, its just that whoever set it up before me did such a poor job and never finished. Besides, you always have a better grasp on stuff you setup yourself. So I go out, and download the documentation… send it to the printer, and realize very quickly that this little utility has more than 200 pages of documentation. There is no way some system admin under the gun is going to want to sift his way through 200 pages of docs, just to setup a monitoring utility for his UPS’s. So here we are, the laymans guide to APCUPSD.
***NOTE: We are using APC SmartUPS 2200 via Serial Cable
#### 1.0 INSTALL ####
When installing Linux specifically for this purpose, I first picked a really low grade older machine (A P-3 600MHz). No KDE, No Gnome, No X Enviroment. Only SNMP, and the base OS. You will probably want to include all the development stuff, and System Tools just to be safe. When setting up Linux for this think: “Barebone Functional Linux”. Make sure Net-SNMP-Utils is installed. We use Fedora Core 4 ’round here, so if you are running anything but a RPM based distro, some stuff my not work right off the bat.
Fedora Core 4 Setup? Easy. Just type: yum install apcupsd
Everyone else will need to visit the APSUPSD site, and manually compile the source, or install the RPM.
#### 1.1 CONFIGURATION ####
The APC configuration file is located in /etc/apcupsd/apcupsd.conf.
The config file for APCUPSD is vast, and full of a variety of options; however we are only going to be discussing the fairly basic variables, to get you up and running.
The first thing you are going to need to do, is set a UPS Name for logging purposes:
# UPSNAME xxx
# Use this to give your UPS a name in log files and such. This
# is particulary useful if you have multiple UPSes. This does not
# set the EEPROM. It should be 8 characters or less.
UPSNAME csapc01
Next you will need to define what type of serial cable is connecting the host to the APC:
# UPSCABLE
# Defines the type of cable connecting the UPS to your computer.
#
# Possible generic choices for are:
# simple, smart, ether, usb
#
# Or a specific cable model number may be used:
# 940-0119A, 940-0127A, 940-0128A, 940-0020B,
# 940-0020C, 940-0023A, 940-0024B, 940-0024C,
# 940-1524C, 940-0024G, 940-0095A, 940-0095B,
# 940-0095C, M-04-02-2000
#
UPSCABLE 940-0024C
You can find out what type of serial cable you are using by looking at the connector on the serial cable, one side should be stamped with one of the above numbers.
Next you will need to find out what the Linux device name of the serial port you are connecting the APC up with. You can do this by inspecting the dmesg:
[root@csapc01 apcupsd]# dmesg | grep tty
ttyS0 at I/O 0×3f8 (irq = 4) is a 16550A
ttyS1 at I/O 0×2f8 (irq = 3) is a 16550A
ttyS0 at I/O 0×3f8 (irq = 4) is a 16550A
ttyS1 at I/O 0×2f8 (irq = 3) is a 16550A
I know that I put mine in the first serial port, so I’m fairly certain that mine is on /dev/ttyS0. Now lets define that in the apcupsd.conf:
# To get apcupsd to work, in addition to defining the cable
# above, you must also define a UPSTYPE, which corresponds to
# the type of UPS you have (see the Description for more details).
# You must also specify a DEVICE, sometimes referred to as a port.
# For USB UPSes, please leave the DEVICE directive blank. For
# other UPS types, you must specify an appropriate port or address.
UPSTYPE apcsmart
DEVICE /dev/ttyS0
The “UPSTYPE” refers to the type of UPS (as it states above). You have 5 options: APCSMART, NET, USB, SNMP, & DUMB. APCSMART refers to the newer serial APC’s, USB refers to the USB APC. Both NET and SNMP, are more advanced stuff that we will not get into. And DUMB is the older serial APC’s.
From this point, you have done and configured just enough to have a working APC host. Now, you havent configured enough to be notified of outages, etc, but from this point, atleast we can try to start the daemon, and see if it works:
Fedora Core 4 users just type: service apcupsd start
Next type: ps fax
If you see the following, then you have successfully installed and started the APC UPS Daemon:
[root@csapc01 apcupsd]# ps fax
PID TTY STAT TIME COMMAND
1 ? S 0:01 init [3]
2 ? SN 0:00 [ksoftirqd/0]
3 ? S 0:00 [watchdog/0]
4 ? S< 0:00 [events/0]
5 ? S< 0:00 [khelper]
6 ? S< 0:00 [kthread]
2741 ? Ssl 0:00 /usr/sbin/apcupsd -f /etc/apcupsd/apcupsd.conf
If you dont see the last line above, it is probably because you have the wrong Serial Device defined in the apcupsd.conf. Re-Inspect the dmesg, and put the correct serial device name in the apcupsd.conf. Then restart the daemon. The APCUPSD documentation will tell you about seeing the child processes, etc. If you only see one instance of apcupsd running, do no worry, that is normal for 2.6.x kernels on Linux.
Next, just to be sure, lets check the /var/log/messages:
[root@csapc01 apcupsd]# tail /var/log/messages
Mar 18 13:13:36 csapc01 syslogd 1.4.1: restart.
Mar 18 13:21:12 csapc01 apcupsd[2741]: apcupsd exiting, signal 15
Mar 18 13:21:12 csapc01 apcupsd[2741]: apcupsd shutdown succeeded
Mar 18 13:21:33 csapc01 apcupsd[17256]: apcupsd 3.12.2 (18 January 2006) redhat startup succeeded
Mar 18 13:21:35 csapc01 apcupsd[17256]: NIS server startup succeeded
Now that you have the APC monitoring host and daemon up and running, its time to do some testing…
#### 1.2 TESTING ####
The APCUPSD daemon by default has the Network Information Server enabled in the config. This should be working, and can be tested by executing the apcacess command from the /etc/apcupsd directory:
[root@csapc01 apcupsd]# apcaccess status
APC : 001,052,1246
DATE : Sat Mar 18 13:26:42 CST 2006
HOSTNAME : csapc01.*****.***
RELEASE : 3.12.2
VERSION : 3.12.2 (18 January 2006) redhat
UPSNAME : csapc01
CABLE : APC Cable 940-0024C
MODEL : SMART-UPS 2200
UPSMODE : Stand Alone
STARTTIME: Sat Mar 18 13:21:19 CST 2006
STATUS : ONLINE
LINEV : 118.3 Volts
LOADPCT : 25.4 Percent Load Capacity
BCHARGE : 100.0 Percent
TIMELEFT : 62.0 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME : 0 Seconds
MAXLINEV : 118.9 Volts
MINLINEV : 117.0 Volts
OUTPUTV : 118.3 Volts
SENSE : High
….
END APC : Sat Mar 18 13:27:30 CST 2006
If you are seeing something similar to the above, then you are on the right track, and everything is working properly. Congratulations. Now onto our final subject….
#### 1.3 SETTING UP APCUPSD EMAIL NOTIFICATION ####
In order to get NON-LOCAL email notification enabled with APCUPSD you will need to edit a few scripts located in the /etc/apcupsd directory, they are: CHANGEME, COMMFAILURE, COMMOK, MASTERCONNECT, MASTERTIMEOUT, ONBATTERY, and OFFBATTERY. You will need to replace the SYSADMIN variable with a valid email address, and the APCUPSD_MAIL variable with the location of the sendmail binary:
#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when apcupsd
# loses contact with the UPS (i.e. the serial connection is not responding).
# We send an email message to root to notify him.
# root
# /bin/mail
SYSADMIN=cvcrud@blahblah.com
APCUPSD_MAIL=”/usr/sbin/sendmail”
HOSTNAME=`hostname`
MSG=”$HOSTNAME Communications with UPS lost”
#
(
echo “Subject: $MSG”
echo ” ”
echo “$MSG”
echo ” ”
/usr/sbin/apcaccess status
) | $APCUPSD_MAIL -s “$MSG” $SYSADMIN
exit 0
You can test your changes by running the script, [i.e. ./commfailure ].
If you recieve an email from root@whatever notifying you of a communications failure with your UPS, then you know you have configured and setup your APC host successfully.
#EOF
Report this post to a moderator |
IP: Logged
|