Home Directory

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

Directory

Goldie2009

Reviews(1)
check_dhcp_all_pools.sh
Some customizing für usage with a Windows Server 2008 R2 (SNMP feature installed):


if [ $# -lt 2 ]; then
echo "check_dhcp_all_pools"
echo "Usage: $0 "
echo "Example: WARN at 50 & CRIT at 30 will WARN you when the percentage of free DHCP addresses"
echo "is less than or equal to 50% of available addresses and alarm CRITICAL whe the percentage"
echo "of free addresses is less than or equal to 30% of available addresses."
exit 3
fi

IP="$1"
COMMUNITY="$2"
WARN="$3"
CRIT="$4"
RET=0
RETW=0
RETC=0
Z=0
STAT=( )
i=0
RESULT=""

if [ ${#WARN} -lt 1 ]
then
WARN=20
fi

if [ ${#CRIT} -lt 1 ]
then
CRIT=10
fi

#Get the list of all scopes/subnets from the server:
TEMP=($( snmpwalk -v2c -c $COMMUNITY $IP .1.3.6.1.4.1.311.1.3.2.1.1.1 | cut -d " " -f4 ))

#Traverse array and get usage information per scope:
for i in ${!TEMP[*]};do
POOL=${TEMP[$i]}
FREEOID=".1.3.6.1.4.1.311.1.3.2.1.1.3.$POOL"
USEDOID=".1.3.6.1.4.1.311.1.3.2.1.1.2.$POOL"
SNMP_RESULT=`snmpget -v 2c -c $COMMUNITY $IP $FREEOID`
FREE=`echo $SNMP_RESULT|cut -d " " -f4`
SNMP_RESULT=`snmpget -v 2c -c $COMMUNITY $IP $USEDOID`
USED=`echo $SNMP_RESULT|cut -d " " -f4`
MAX=`echo "$FREE+$USED" |bc`
if [ "$MAX" -ne 0 ]; then
PERCFREE=`echo "$FREE*100/$MAX" |bc`
PERCUSED=`echo "$USED*100/$MAX" |bc`
#Debug: echo "FREE: $FREE USED: $USED MAX: $MAX PERC: $PERCFREE,$PERCUSED"
if [ "$PERCFREE" -le "$WARN" -a "$PERCFREE" -gt "$CRIT" ]; then
let "RETW += 1"
STAT=( "${STAT[@]}" "Warning: $POOL - $PERCFREE% free - $PERCUSED% used - $USED/$MAX - Threshold is $WARN% free\n" )
elif [ "$PERCFREE" -le "$CRIT" ]; then
let "RETC += 1"
STAT=( "${STAT[@]}" "Critical: $POOL - $PERCFREE% free - $PERCUSED% used - $USED/$MAX - Threshold is $CRIT% free\n" )
else
STAT=( "${STAT[@]}" "OK: $POOL - $PERCUSED% used - $USED/$MAX\n" )
fi
# elif [ "$MAX" -eq 0 ]; then
#Debug for detecting 100% excluded ranges (reservations only):
# STAT=( "${STAT[@]}" "OK: $POOL Nothing used, could be excluded" )
fi

# Performance-Data
PERFDATA="${PERFDATA} | 'Scope Usage' $POOL=$PERCUSED%;$WARN;$CRIT;0;$MAX"
# PERFDATA="${PERFDATA} | $POOL OK - Usage: $PERCUSED% ($FREE Addresses of $MAX in pool free) \n"

done

#Evaluate return code:

if [ "$RETC" -eq 0 -a "$RETW" -eq 0 ]; then
RET=0
RESULT="${RESULT} OK: All scopes fine\n\n"
elif [ "$RETW" -ne 0 -a "$RETC" -eq 0 ]; then
RET=1
RESULT="${RESULT} Warning: One or more scopes is nearing capacity\n\n"
elif [ "$RETC" -ne 0 ]; then
RET=2
RESULT="${RESULT} Critical: One or more scopes is nearing capacity\n\n"
fi

###### Second loop for long service output:

for i in ${!STAT[*]};do
RESULT="${RESULT} ${STAT[$i]}"
done

#Echo the total amount of scopes available vs those shown:
RESULT="${RESULT} \nShowing ${#STAT[@]} of ${#TEMP[@]} configured scopes"

echo "$RESULT|$PERFDATA"

exit $RET