mirror of
https://github.com/lopes/netbox-scanner.git
synced 2025-07-24 06:14:42 +02:00
Merge pull request #22 from ndom91/master
README + netbox 2.9.x compatability (tagging not supported yet)
This commit is contained in:
commit
6569da7cb8
@ -11,11 +11,20 @@ netbox-scanner is compatible with **Python 3.7+**, and can be installed like thi
|
||||
$ wget https://github.com/lopes/netbox-scanner/archive/master.zip
|
||||
$ unzip netbox-scanner-master.zip -d netbox-scanner
|
||||
$ cd netbox-scanner
|
||||
$ python3 -m venv venv
|
||||
$ source venv/bin/activate
|
||||
$ pip install -r requirements.txt
|
||||
```
|
||||
|
||||
After installation, use the `netbox-scanner.conf` file as an example to create your own and put this file in `/opt/netbox` or prepend its name with a dot and put it in your home directory --`~/.netbox-scanner.conf`. Keep reading to learn more about configuration.
|
||||
|
||||
> Starting with Netbox **v2.9.0** there are changes to the way tags are created. You must go into the web UI and explicity create a tag for each module you are planning to use here. So for example, if you want to use the nmap module, you have to create a Netbox tag called 'nmap' before you can successfully use it.
|
||||
|
||||
## Quick Start
|
||||
|
||||
0. Clone the repo and install the dependencies as shown above.
|
||||
1. Move the `netbox-scanner.conf` file to your Netbox directory (`/opt/netbox`) and fill out the variables according to your setup. Don't forget to change the path to match where you put this repo under `[NMAP].path`.
|
||||
2. Go to the `samples` subdirectory of this repo and execute `./nmap-scan.sh` to get a first look at the behavior of this project.
|
||||
|
||||
## Basics
|
||||
netbox-scanner reads a user-defined source to discover IP addresses and descriptions, and insert them into NetBox. To control what was previously inserted, netbox-scanner adds tags to each record, so it will know that that item can be handled. In order to guarantee the integrity of manual inputs, records without such tags will not be updated or removed.
|
||||
|
@ -4,7 +4,7 @@ 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)
|
||||
self.tag = tag
|
||||
@ -46,15 +46,15 @@ class NetBoxScanner(object):
|
||||
self.stats['unchanged'] += 1
|
||||
else:
|
||||
self.netbox.ipam.ip_addresses.create(
|
||||
address=host[0],
|
||||
tags=[self.tag],
|
||||
address=host[0],
|
||||
# tags=[self.tag],
|
||||
description=host[1]
|
||||
)
|
||||
logging.info(f'created: {host[0]}/32 "{host[1]}"')
|
||||
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,8 +83,9 @@ class NetBoxScanner(object):
|
||||
self.stats['unchanged'],
|
||||
self.stats['created'],
|
||||
self.stats['updated'],
|
||||
self.stats['deleted'],
|
||||
self.stats['deleted'],
|
||||
self.stats['errors']
|
||||
))
|
||||
|
||||
return True
|
||||
|
||||
|
@ -5,7 +5,7 @@ tls_verify = no
|
||||
logs = .
|
||||
|
||||
[NMAP]
|
||||
path = samples/nmap
|
||||
path = /opt/netbox-scanner/samples/nmap
|
||||
unknown = autodiscovered:netbox-scanner
|
||||
tag = nmap
|
||||
cleanup = yes
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# This is just an example.
|
||||
#
|
||||
@ -16,11 +16,12 @@
|
||||
# to look for XML files.
|
||||
##
|
||||
|
||||
NETWORKS = "10.1.2.3/24 10.2.3.4/32 192.168.0.0/19"
|
||||
TODAY="$(date +%d.%m.%yT%H:%M:%S%Z)"
|
||||
NETWORKS="10.1.2.3/24 10.2.3.4/32 192.168.0.0/19"
|
||||
TODAY="$(date +%d%m%yT%H%M%S%Z)"
|
||||
|
||||
for net in $NETWORKS; do
|
||||
nmap -T4 -O -F --host-timeout 30s -oX nmap-"$net".xml
|
||||
rawNet="${net:0:-3}"
|
||||
sudo nmap -T4 -O -F --host-timeout 30s -oX nmap-"$rawNet".xml "$net"
|
||||
done
|
||||
|
||||
python ../netbox-scanner.py nmap
|
||||
|
0
samples/nmap/.gitkeep
Normal file
0
samples/nmap/.gitkeep
Normal file
Loading…
x
Reference in New Issue
Block a user