-
-
Save mlazzarotto/1c3061957ab27706088b735c5679ce02 to your computer and use it in GitHub Desktop.
Netbox Report Duplicate IP - Netbox 3.6+ compatible
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
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.choices import IPAddressRoleChoices | |
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=IPAddressRoleChoices.ROLE_ANYCAST) | Q(role=IPAddressRoleChoices.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