JR

3 minute read

I’ve stumbled on a useful plug-in from Lars Michelsen that easily monitors a single Windows Server DHCP scope for usage using SNMPv2, but found this fell short of what I needed for monitoring several scopes at once. I’ve modified Lars’ original plugin/script to accommodate 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. There is a conditional statement commented below that can report these scopes as being available, but with zero (0) free or used addresses, equaling zero (0) MAX available amount of addresses. This information isn’t really relevant, so I omitted it from being returned; however,  there is a count returned of configured and shown scopes (located at the bottom).

Feel free to use, reuse, or modify the script the suit your needs. There are other, similar plugins to accomplish the same thing, but most of these rely on NRPE, NSClient++, and netsh. If you’re looking for a straight SNMP check to monitor comprehensive DHCP scope usage then this is it.

#! /bin/bash
# ##############################################################################
# check_dhcp_all_pools.sh - Nagios plugin
#
# This script querys a MS Windows DHCP-Server via SNMP v2 to fetch informations about the given DHCP-Pool.
#
# Copyright (C) 2006, 2007 Lars Michelsen <lars@vertical-visions.de>,
#
# 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,
#
# GNU General Public License: http://www.gnu.org/licenses/gpl-2.0.txt
#
# Report bugs to: lars@vertical-visions.de
#
# 2006-07-05 Version 0.2
# 2007-10-27 Version 0.3
#
# Modified 2013-04-22 by JRM (http://liveaverage.com) to support checking all scopes
# 
#
# ##############################################################################

if [ $# -lt 2 ]; then echo “check_dhcp_all_pools” echo “Usage: $0 <host> <community> <warn> <crit>” 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

comments powered by Disqus