mirror of
https://github.com/lopes/netbox-scanner.git
synced 2025-07-06 21:44:39 +02:00
Check for IP existence in netbox before blind deletion
This commit is contained in:
parent
867652b3b2
commit
0b03893204
@ -155,20 +155,25 @@ class NetBoxScanner(object):
|
|||||||
self.logger('scanned', net=network, hosts=len(hosts))
|
self.logger('scanned', net=network, hosts=len(hosts))
|
||||||
for host in hosts:
|
for host in hosts:
|
||||||
self.sync_host(host)
|
self.sync_host(host)
|
||||||
|
|
||||||
|
ips = list()
|
||||||
|
ips.append(self.netbox.ipam.ip_addresses.all())
|
||||||
|
|
||||||
for ipv4 in IPv4Network(network): # cleanup
|
for ipv4 in IPv4Network(network): # cleanup
|
||||||
address = str(ipv4)
|
address = str(ipv4)
|
||||||
if not any(h[0]==address for h in hosts):
|
if any(ip == address for ip in ips):
|
||||||
try:
|
if not any(h[0]==address for h in hosts):
|
||||||
nbhost = self.netbox.ipam.ip_addresses.get(address=address)
|
try:
|
||||||
if self.tag in nbhost.tags:
|
nbhost = self.netbox.ipam.ip_addresses.get(address=address)
|
||||||
nbhost.delete()
|
if self.tag in nbhost.tags:
|
||||||
self.logger('deleted', address=nbhost.address,
|
nbhost.delete()
|
||||||
description=nbhost.description)
|
self.logger('deleted', address=nbhost.address,
|
||||||
else:
|
description=nbhost.description)
|
||||||
self.logger('undiscovered', address=nbhost.address,
|
else:
|
||||||
description=nbhost.description)
|
self.logger('undiscovered', address=nbhost.address,
|
||||||
except (AttributeError, ValueError):
|
description=nbhost.description)
|
||||||
pass
|
except (AttributeError, ValueError):
|
||||||
|
pass
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def sync_csv(self, csvfile):
|
def sync_csv(self, csvfile):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user