Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

check_apcupsd

Rating
10 votes
Favoured:
3
Hits
382804
Files:
FileDescription
check_apcupsd.txtThe plugin. Remove .txt extension before use.
Network Monitoring Software - Download Nagios XI
Log Management Software - Nagios Log Server - Download
Netflow Analysis Software - Nagios Network Analyzer - Download
check_apcupsd
Nagios plugin to monitor APC Smart-UPSes using apcupsd.
Monitor battery charge, internal temperature, load and time left on one or more APC Smart-UPSes. Compared to other similar plugins, this plugin allows you to specify hostname and port for apcupsd, which makes it possible to monitor UPSes connected to remote hosts and/or several UPSes connected to the local host. Look in the script for an example to get you started. Run the script without parameters to get full usage info.

Remember to check out the nice screen shot :-)

Note: The trick to monitor several local UPSes is to run several apcupsds on different ports.
Reviews (9)
byCircaLucid, January 20, 2015
Great script. I added a fix to show the serial. Here's the patch:

--- /usr/lib/nagios/plugins/check_apcupsd 2013-06-16 13:30:39.000000000 -0400
+++ /root/check_apcupsd.2 2015-01-20 12:43:31.437445687 -0500
@@ -96,7 +96,7 @@
{
echo "usage: check_apcupsd [-c critical_value] [-h hostname] [-p port]"
echo -n " [-w warning_value] "
- echo ""
+ echo ""
echo
echo "hostname and port defaults to localhost and 3551, respectively."
echo
@@ -111,6 +111,7 @@
echo " measured in minutes."
echo " linefail = Whether the line is OK or not (Back UPS only)"
echo " status = Same as 'linefail' (Back UPS ES only - maybe others)"
+ echo " serial = Shows the device serial"
echo " battstat = Whether the battery is OK or not (Back UPS only)"
exit 3
}
@@ -146,7 +147,7 @@

if [ "$ARG" != "bcharge" -a "$ARG" != "battv" -a "$ARG" != "itemp" \
-a "$ARG" != "loadpct" -a "$ARG" != "timeleft" -a "$ARG" != "linefail" \
- -a "$ARG" != "battstat" -a "$ARG" != "status" ]; then
+ -a "$ARG" != "battstat" -a "$ARG" != "status" -a "$ARG" != "serial" ]; then
usage
fi

@@ -191,7 +192,7 @@
fi

# Back UPS reports only an OK / ERR state
-if [ "$ARG" != "linefail" -a "$ARG" != "battstat" -a "$ARG" != "status" ]; then
+if [ "$ARG" != "linefail" -a "$ARG" != "battstat" -a "$ARG" != "status" -a "$ARG" != "serial" ]; then
VALUE=`$APCACCESS status $HOSTNAME:$PORT | grep -i ^$ARG | \
sed 's/.*: *\([0-9.][0-9.]*\)[^0-9.].*/\1/'`
if [ -z "$VALUE" ]; then
@@ -202,6 +203,23 @@
VALUE=`echo $VALUE | sed 's/^0*//'`
fi
ROUNDED=`echo $VALUE | sed 's/\..*//'`
+elif [ "$ARG" = "serial" ]; then
+ VALUE=`$APCACCESS status $HOSTNAME:$PORT | grep -i ^$ARG | \
+ sed 's/.*: *\([A-Z]*\).*/\1/'`
+ if [ -z "$VALUE" ]; then
+ echo "UPS does not support $ARG"
+ exit 3
+ fi
+ if [ "$VALUE" = "AS" ]; then
+ ROUNDED=1
+ else
+ ROUNDED=0
+ fi
+ VALUE=`$APCACCESS status $HOSTNAME:$PORT | grep -i ^$ARG`
+ if [ -z "$VALUE" ]; then
+ echo "UPS does not support $ARG"
+ exit 3
+ fi
else
VALUE=`$APCACCESS status $HOSTNAME:$PORT | grep -i ^$ARG | \
sed 's/.*: *\([A-Z]*\).*/\1/'`
@@ -363,6 +381,16 @@
fi
echo "${STATUS} - Time Left: $VALUE Minutes|'minutes left'=${VALUE};$WARNVAL:;$CRITVAL:;;"
;;
+serial)
+ if [ $ROUNDED -gt 0 ]; then
+ STATUS="OK"
+ EXITVALUE=0
+ else
+ STATUS="CRITICAL"
+ EXITVALUE=2
+ fi
+ echo "${STATUS} - ${VALUE}"
+ ;;
esac

exit $EXITVALUE
High. Nice script. Though I found a little bug.

When you clean leading zeros, you clean to many of them and a value of "0.0" becomes ".0" which is not detected by your script...

Here's a patch :

--- check_apcupsd.old 2013-12-02 10:20:28.395006242 -0500
+++ check_apcupsd 2013-12-02 10:20:59.751405840 -0500
@@ -158,7 +158,7 @@

VALUE=`$APCACCESS status $HOSTNAME:$PORT | grep -i ^$ARG | \
sed 's/.*: *\([0-9.][0-9.]*\)[^0-9.].*/\1/'`
-if [ "$VALUE" != "0" ]; then
+if [ "$VALUE" != "0" -a "$VALUE" != "0.0" ]; then
VALUE=`echo $VALUE | sed 's/^0*//'`
fi
ROUNDED=`echo $VALUE | sed 's/\..*//'`
Below is the exercise,which I have done on Nagios Core 3.4.3.

Command1
touch /sbin/apcaccess
chmod +x /sbin/apcaccess

Command2
./check_apcupsd -h timeleft
Output: OK - Time Left: Minutes

Command3
/check_apcupsd -h ups1 bcharge
OK - Battery Charge: %

Means, it is not showing output in % properly. It seems that there is a need to modify the plugin again.

Nishith N.Vyas
I just created a very small patch to add a few perfData information to make the script compatible with NagVis gadgets
byazteca61, June 26, 2012
How can I add ports to check_apcupsd plugin? I have apcupsd running ports 3551, 3552 and 3553 but Nagios only shows 3551.

thanks
We recently started monitoring all of our UPS's so this was extremely useful and the setup is fast and easy, BUT the only problem I have is if I have a host that has multiple UPS's and they're on different ports I am getting a null response. If i execute the same command from console i get a good response. Any suggestions? I have tried making separate services, putting them all on one host,tried adding the port option to the plugin, still nothing works.
Very handy plugin - ran into one minor problem in version 2.4 with the "status" command. check_apcupsd only looks at the first word in the STATUS: provided by apcaccess. Changing the check at line 188 from this:
VALUE=`$APCACCESS status $HOSTNAME:$PORT | grep -i ^$ARG | \
sed 's/.*: *\([A-Z]*\).*/\1/'`
to this:
VALUE=`$APCACCESS status $HOSTNAME:$PORT | grep -i ^$ARG | \
sed -e 's/^.*: *//' -e 's/ *$//'`

seemed to do the trick for me - now our brand new UPS can report "ONLINE NOBATT" and we'll notice!

Thanks!

John
bybshephard, November 28, 2010
An excellent plugin for APCUPSD but to expand it further it would be nice if it could provide performance data that can then be graphed by pnp4nagios and perhaps check a few more items reported on by apcaccess such as the mains voltage.
byBhawks_2, September 26, 2010
1 of 1 people found this review helpful
Great plugin! In the text file sample commands and services are included. Took about 15 minutes to set up and displays all UPS info nicely in nagios

Great work, thanks!