Skip to content

Instantly share code, notes, and snippets.

@pulecp
Last active September 1, 2016 11:04
Show Gist options
  • Select an option

  • Save pulecp/f2a439bf7037764c5c19b53578cdfde0 to your computer and use it in GitHub Desktop.

Select an option

Save pulecp/f2a439bf7037764c5c19b53578cdfde0 to your computer and use it in GitHub Desktop.
Nagios check for IP address duplications
#!/bin/bash
# This file is managed by puppet
# ignore localhost, and addresses with subnet /32 (because of Hetzner failover IP)
ips=$(ip addr show | grep "inet\b" | awk '{print $2}' | grep -E -v '127\.0\.0\.1|\/32' | cut -d/ -f1)
interfaces=$(ip link show | grep 'state UP' | cut -d ':' -f2 | tr -d ' ' | grep -v '\-drac')
duplications=''
arping_output=''
arping=$(which arping) || { echo 'UNKNOWN - arping command not found'; exit 3; }
for ip in $ips
do
for iface in $interfaces
do
arping_output="${arping_output}\n\n$($arping -D -c 1 -I "$iface" "$ip")"
[[ $? -ne 0 ]] && duplications="${duplications}${ip} "
done
done
if [[ -z "$duplications" ]]; then
echo -e "OK - No duplicate address found.${arping_output}"
exit 0
else
echo -e "CRITICAL - Found duplicate addresses: ${duplications}!!!${arping_output}"
exit 2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment