Git Product home page Git Product logo

Comments (1)

florianow avatar florianow commented on August 15, 2024

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

grafik

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.