diff --git a/nbs/__init__.py b/nbs/__init__.py index d297ae6..973b5f7 100644 --- a/nbs/__init__.py +++ b/nbs/__init__.py @@ -4,9 +4,9 @@ from pynetbox import api class NetBoxScanner(object): - - def __init__(self, address, token, tls_verify, tag, cleanup): - self.netbox = api(address, token, ssl_verify=tls_verify) + + def __init__(self, address, token, tag, cleanup): + self.netbox = api(address, token) self.tag = tag self.cleanup = cleanup self.stats = { @@ -36,17 +36,18 @@ class NetBoxScanner(object): aux = nbhost.description nbhost.description = host[1] nbhost.save() - logging.info(f'updated: {host[0]}/32 "{aux}" -> "{host[1]}"') + logging.info( + f'updated: {host[0]}/32 "{aux}" -> "{host[1]}"') self.stats['updated'] += 1 else: logging.info(f'unchanged: {host[0]}/32 "{host[1]}"') self.stats['unchanged'] += 1 else: - logging.info(f'unchanged: {host[0]}/32 "{host[1]}"') - self.stats['unchanged'] += 1 + logging.info(f'unchanged: {host[0]}/32 "{host[1]}"') + self.stats['unchanged'] += 1 else: self.netbox.ipam.ip_addresses.create( - address=host[0], + address=host[0], tags=[self.tag], description=host[1] ) @@ -54,7 +55,7 @@ class NetBoxScanner(object): self.stats['created'] += 1 return True - + def garbage_collector(self, hosts): '''Removes records from NetBox not found in last sync''' nbhosts = self.netbox.ipam.ip_addresses.filter(tag=self.tag) @@ -83,7 +84,7 @@ class NetBoxScanner(object): self.stats['unchanged'], self.stats['created'], self.stats['updated'], - self.stats['deleted'], + self.stats['deleted'], self.stats['errors'] )) diff --git a/nbs/nmap.py b/nbs/nmap.py index 0d7d413..e1615bb 100644 --- a/nbs/nmap.py +++ b/nbs/nmap.py @@ -28,4 +28,3 @@ class Nmap(object): host.find('address').attrib['addr'], self.unknown )) - \ No newline at end of file diff --git a/netbox-scanner.conf b/netbox-scanner.conf index a3fe8b3..5e96598 100644 --- a/netbox-scanner.conf +++ b/netbox-scanner.conf @@ -1,29 +1,26 @@ [NETBOX] -address = https://netbox.domain -token = -tls_verify = no -logs = . +address = +token = +logs = logs/ [NMAP] -path = samples/nmap +path = ./ unknown = autodiscovered:netbox-scanner tag = nmap cleanup = yes -[NETXMS] -address = https://netxms.domain -username = -password = -tls_verify = no -unknown = autodiscovered:netbox-scanner -tag = netxms -cleanup = yes +# [NETXMS] +# address = https://netxms.domain +# username = +# password = +# unknown = autodiscovered:netbox-scanner +# tag = netxms +# cleanup = yes -[PRIME] -address = https://prime.domain/webacs/api/v4 -username = -password = -tls_verify = no -unknown = autodiscovered:netbox-scanner -tag = prime -cleanup = yes +# [PRIME] +# address = https://prime.domain/webacs/api/v4 +# username = +# password = +# unknown = autodiscovered:netbox-scanner +# tag = prime +# cleanup = yes diff --git a/netbox-scanner.py b/netbox-scanner.py index 70aa3a3..c0aec4d 100644 --- a/netbox-scanner.py +++ b/netbox-scanner.py @@ -28,15 +28,15 @@ else: netbox = config['NETBOX'] nmap = config['NMAP'] -netxms = config['NETXMS'] -prime = config['PRIME'] +#netxms = config['NETXMS'] +#prime = config['PRIME'] parser = ArgumentParser(description='netbox-scanner') subparsers = parser.add_subparsers(title='Commands', dest='command') subparsers.required = True argsp = subparsers.add_parser('nmap', help='Nmap module') -argsp = subparsers.add_parser('netxms', help='NetXMS module') -argsp = subparsers.add_parser('prime', help='Cisco Prime module') +#argsp = subparsers.add_parser('netxms', help='NetXMS module') +#argsp = subparsers.add_parser('prime', help='Cisco Prime module') args = parser.parse_args() logfile = '{}/netbox-scanner-{}.log'.format( @@ -44,8 +44,8 @@ logfile = '{}/netbox-scanner-{}.log'.format( datetime.now().isoformat() ) logging.basicConfig( - filename=logfile, - level=logging.INFO, + filename=logfile, + level=logging.INFO, format='%(asctime)s\tnetbox-scanner\t%(levelname)s\t%(message)s' ) logging.getLogger().addHandler(logging.StreamHandler()) @@ -58,6 +58,7 @@ def cmd_nmap(s): # nmap handler h.run() s.sync(h.hosts) + def cmd_netxms(s): # netxms handler h = NetXMS( netxms['address'], @@ -69,12 +70,13 @@ def cmd_netxms(s): # netxms handler h.run() s.sync(h.hosts) + def cmd_prime(s): # prime handler h = Prime( prime['address'], prime['username'], prime['password'], - prime.getboolean('tls_verify'), + prime.getboolean('tls_verify'), prime['unknown'] ) h.run() # set access_point=True to process APs @@ -85,8 +87,7 @@ if __name__ == '__main__': scanner = NetBoxScanner( netbox['address'], netbox['token'], - netbox.getboolean('tls_verify'), - nmap['tag'], + nmap['tag'], nmap.getboolean('cleanup') ) diff --git a/samples/nmap-1.xml b/samples/nmap-1.xml deleted file mode 100644 index df7ecb0..0000000 --- a/samples/nmap-1.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - -
- - - - - - - - - - - - cpe:/a:openbsd:openssh:5.3p1 - cpe:/o:linux:kernel - -