Last active
January 3, 2016 09:59
-
-
Save alexclifford/8446461 to your computer and use it in GitHub Desktop.
Hack for some dodgy DHCP leasing by dhcpd on an OpenBSD install.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
###################################################################### | |
# Check how many unique leases are defined in /var/db/dhcpd.leases | |
# If there are more leases than a specified number send an email | |
###################################################################### | |
# Estimate how many IP address leases there are | |
NUM_LEASES=$(grep ^lease /var/db/dhcpd.leases | sort -rn | uniq | wc -l | tr -d ' ') | |
# Print out help/usage if there aren't enough parameters supplied | |
if [ $# -ne 2 ] | |
then | |
echo "Usage: check_ip_leases.sh num email" | |
echo "num - The number of leases you want to check for. If there are found to be more leases than the specified num then an alert is triggered." | |
echo "email - Email address to send an alert to" | |
echo "(There are currently $NUM_LEASES leases in use)" | |
exit 0 | |
fi | |
# Set the variables for the supplied parameters | |
CHECK_NUM=$1 | |
EMAIL=$2 | |
# Check if there are more leases than the specified parameter | |
if [[ $CHECK_NUM -lt $NUM_LEASES ]] | |
then | |
# Too many leases so send an email alert | |
echo "/var/db/dhcpd.leases has reached the IP leases threshold of $CHECK_NUM. There are currently $NUM_LEASES leases.\n\nTo fix this stop the DHCPD server, move /var/db/dhcpd.leases and then start the DHCPD server again." | mail -s "/var/db/dhcpd.leases IP leases limit reached!" $EMAIL | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment