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_dhcp_all_pools.sh

Current Version
1.0
Last Release Date
2013-04-22
Compatible With
  • Nagios 3.x
  • Nagios 4.x
License
GPL
Hits
28934
Files:
FileDescription
check_dhcp_all_pools[1].shcheck_dhcp_all_pools[1].sh
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
check_dhcp_all_pools.sh
Different take on Lars Michelsen's original plugin/script to accommodate monitoring of all available DHCP scopes on your monitored Windows server. You no longer need to add separate service definitions to monitor all available scopes.
It's worth noting a couple of important details:

- Nagios 3.x or above is required for the multi-line output generated by this command.
- This service check will alarm if any scope is nearing the critical or warning threshold(s) specified command call.
If you require per-scope or per-pool alarm configuration, you should use the original plugin created by Lars Michelsen.
- Performance Data has been commented out, but is available if you'd like to add it.
- Scopes that exist but are not in use (e.g. scopes exclusively used for reservations) are left out of this check.
Reviews (2)
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
byPereira, September 1, 2014
Only two correction for this, using v1:

in line: TEMP=($( snmpwalk -c $COMMUNITY $IP .1.3.6.1.4.1.311.1.3.2.1.1.1 | cut -d " " -f4 ))

To: TEMP=($( snmpwalk $IP -v1 -c $COMMUNITY .1.3.6.1.4.1.311.1.3.2.1.1.1 | cut -d " " -f4 ))

And

in line:76 an 79
From: SNMP_RESULT=`snmpget -v 2c -c $COMMUNITY $IP $USEDOID`

To:SNMP_RESULT=`snmpget -v1 -c $COMMUNITY $IP $USEDOID`



Thanks.