Comments (1)
hey,
It would be better when the dns_name is set and the description is something like autodiscovered or you can decide by you own with relation you want.
i changed it in my fork but only for the nmap option and itΒ΄s also hard coded. I guess for the class NetXMS it could be similar.
I extended the tuple for the possibility to add a word (i used the unknown value) as the description.
nmap.py class Nmap
import os
import xml.etree.ElementTree as ET
class Nmap(object):
def __init__(self, path, unknown):
self.unknown = unknown
self.path = path
self.hosts = list()
def run(self):
for f in os.listdir(self.path):
if not f.endswith('.xml'):
continue
abspath = os.path.join(self.path, f)
tree = ET.parse(abspath)
root = tree.getroot()
for host in root.findall('host'):
try:
self.hosts.append((
host.find('address').attrib['addr'],
host.find('hostnames').find('hostname').attrib['name'],
self.unknown
))
except AttributeError:
self.hosts.append((
host.find('address').attrib['addr'],
self.unknown
))
init.py function sync_host
def sync_host(self, host):
'''Syncs a single host to NetBox
host: a tuple like ('10.0.0.1','Gateway')
returns: True if syncing is good or False for errors
'''
try:
nbhost = self.netbox.ipam.ip_addresses.get(address=host[0])
except ValueError:
logging.error(f'duplicated: {host[0]}/32')
self.stats['errors'] += 1
return False
try:
hostindex=host[2]
except IndexError:
hostindex=host[1]
if nbhost:
if (self.tag in nbhost.tags):
if (host[1] != nbhost.description):
aux = nbhost.description
nbhost.description = hostindex
nbhost.dns_name=host[1]
nbhost.save()
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
else:
self.netbox.ipam.ip_addresses.create(
address=host[0],
tags=[{"name": self.tag}],
dns_name=host[1],
description=hostindex
)
logging.info(f'created: {host[0]}/32 "{host[1]}"')
self.stats['created'] += 1
return True
that's my result
@lopes
I can change it for more individual Option for the nmap function, but I should extend the netbox-scanner.conf with new values for a clean style that's it also works with netxms.
from netbox-scanner.
Related Issues (20)
- Version 2.0 HOT 1
- nmap: duplicated entries detected that I cannot explain HOT 3
- Compatibility to netbox 2.9 HOT 16
- KeyError HOT 2
- Netbox-scanner fails to run with error "TypeError: __init__() got an unexpected keyword argument 'ssl_verify'"
- Misleading error message HOT 1
- Traceback error on netbox 2.10.1 HOT 1
- Mistake in NetBoxScanner class
- netbox-scanner.py creates IP Addresses, does not show up in Netbox HOT 1
- nmap scan not iterating through subnets HOT 1
- pip install not working HOT 1
- error when executing nmap-scan.sh HOT 1
- Could not open requirements file HOT 2
- No hosts.. wrong path? HOT 3
- No hosts being imported into Netbox while running nmap-scan HOT 3
- requirements mismatch: urllib3==1.26.5 vs requests==2.23.0 HOT 1
- nothing is imported into netbox HOT 12
- Wrong file in Instructions.
- Wrong file in Instructions.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from netbox-scanner.