From: koly68 <koly68@np.lg.ua.>
Newsgroups: email
Date: Mon, 19 Dec 2005 14:31:37 +0000 (UTC)
Subject: Nagios plugin для apcupsd APC Smart-UPS
Вот модернизировал под сеть check_apc от Joe Anthony
http://www.negative1.org/check_apc/check_apc
пробуйте
#!/bin/sh
## $Id: check_apcupsd
## Nagios Plugin for apcupsd APC Smart-UPS
## Copyright (C) 2005
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
if [ ! -x $APCA ]; then
echo "$0: Error: $APCA not found!"
exit 3
fi
dishelp() {
echo "Usage: $0 <status|load|bcharge|time|temp> HOST PORT WARN_VALUE CIRT_VALUE "
echo
echo "load (%): Warn when load is > WARN_VALUE, and CRIT when load is > CRIT_VALUE"
echo "bcharge (%): Warn when charge is < WARN_VALUE, and CRIT when charge is < CRIT_VALUE"
echo "time (minutes): Warn when time is < WARN_VALUE, and CRIT when time is < CRIT_VALUE"
echo "status: Crit if not online"
echo
echo "UNKNOWN UPS State"
exit 3
}
checkargs() {
if [ "$WARN" = '' -o "$CRIT" = '' ]; then
dishelp
exit 3
fi
}
case "$1" in
load)
checkargs
LOAD=`$APCA $APCA_ARG $HOST : $PORT | grep LOAD | awk '{print $3}' | sed -e 's/.[0-9]* *$//g'`
if [ "$LOAD" -gt "$CRIT" ]; then
echo "UPS CRITICAL - Load: ${LOAD}% > ${5}%"
exit 2
fi
if [ "$LOAD" -gt "$WARN" ]; then
echo "UPS WARNING - Load: ${LOAD}% > ${4}%"
exit 1
fi
echo "UPS OK - LOAD: ${LOAD}%"
exit 0
;;
bcharge)
checkargs
CHRG=`$APCA $APCA_ARG $HOST : $PORT | grep BCHARGE | awk '{print $3}' | sed -e 's/.[0-9]* *$//g'`
if [ "$CHRG" -lt "$CRIT" ]; then
echo "UPS CRITICAL - Battery Charge: ${CHRG}% < ${5}%"
exit 2
fi
if [ "$CHRG" -lt "$WARN" ]; then
echo "UPS WARNING - Battery Charge: ${CHRG}% < ${4}%"
exit 1
fi
echo "UPS OK - Battery Charge: ${CHRG}%"
exit 0
;;
time)
checkargs
TLEFT=`$APCA $APCA_ARG $HOST : $PORT | grep TIMELEFT | awk '{print $3}' | sed -e 's/.[0-9]* *$//g'`
if [ "$TLEFT" -lt "$CRIT" ]; then
echo "UPS CRITICAL - Time left: ${TLEFT} mins < ${5} mins"
exit 2
fi
if [ "$TLEFT" -lt "$WARN" ]; then
echo "UPS WARNING - Time Left: ${TLEFT} mins < ${4} mins"
exit 1
fi
echo "UPS OK - Time Left: ${TLEFT} mins"
exit 0
;;
temp)
checkargs
TEMP=`$APCA $APCA_ARG $HOST : $PORT | grep ITEMP | awk '{print $3}' | sed -e 's/.[0-9]* *$//g'`
if [ "$TEMP" -gt "$CRIT" ]; then
echo "UPS CRITICAL - Temperature: ${TEMP} C < ${5} C"
exit 2
fi
if [ "$TEMP" -gt "$WARN" ]; then
echo "UPS WARNING - Temperature: ${TEMP} C < ${4} C"
exit 1
fi
echo "UPS OK - Temperature: ${TEMP} C "
exit 0
;;
status)
ONLINE=`$APCA $APCA_ARG $HOST : $PORT | grep STATUS | awk '{print $3,$4}'`
if [ "$ONLINE" != "$STATE1" ] && [ "$ONLINE" != "$STATE2" ]; then
echo "UPS CRITICAL - $ONLINE"
exit 2
fi
echo "UPS OK - $ONLINE"
exit 0
;;
*)
dishelp
esac