Build precise queries to find exactly what you need
Press ESC to close
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
We’ve completely redesigned the world’s largest repository of Nagios plugins and monitoring tools. Join thousands of users sharing monitoring solutions for servers, applications, and everything in between.
Due to our redesign, all existing accounts require a password reset to access your account again.
Ready to explore 6,100+ projects and contribute to the community?
Reset Password Create Account
Happy Monitoring!