Created
October 25, 2018 16:35
-
-
Save dgarros/acc23b4fd8d42844b8a41f695e6cb769 to your computer and use it in GitHub Desktop.
Netbox Report Duplicate IP
This file contains hidden or 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
from django.db.models import Q | |
from extras.reports import Report | |
from collections import defaultdict | |
from dcim.models import Device | |
from ipam.models import IPAddress | |
from ipam.constants import IPADDRESS_ROLE_ANYCAST, IPADDRESS_ROLE_VIP | |
class UniqueIPReport(Report): | |
description = "Validate that we don't have an IP address allocated twice in the network" | |
def test_unique_ip(self): | |
already_found = [] | |
for ip in IPAddress.objects.exclude(Q(role=IPADDRESS_ROLE_ANYCAST) | Q(role=IPADDRESS_ROLE_VIP)): | |
if ip.address in already_found: | |
continue | |
elif not ip.interface: | |
continue | |
duplicates = ip.get_duplicates() | |
real_dup = 0 | |
for duplicate in duplicates: | |
if duplicate.interface: | |
real_dup +=1 | |
if real_dup != 0: | |
already_found.append(ip.address) | |
msg = "has %s duplicate ips" % real_dup | |
self.log_failure( ip, msg ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment