Skip to content

Commit 6569da7

Browse files
authored
Merge pull request #22 from ndom91/master
README + netbox 2.9.x compatability (tagging not supported yet)
2 parents 9bca20b + 29d07e1 commit 6569da7

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@ netbox-scanner is compatible with **Python 3.7+**, and can be installed like thi
1111
$ wget https://github.com/lopes/netbox-scanner/archive/master.zip
1212
$ unzip netbox-scanner-master.zip -d netbox-scanner
1313
$ cd netbox-scanner
14+
$ python3 -m venv venv
15+
$ source venv/bin/activate
1416
$ pip install -r requirements.txt
1517
```
1618

1719
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.
1820

21+
> 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.
22+
23+
## Quick Start
24+
25+
0. Clone the repo and install the dependencies as shown above.
26+
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`.
27+
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.
1928

2029
## Basics
2130
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.

nbs/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
class NetBoxScanner(object):
7-
7+
88
def __init__(self, address, token, tls_verify, tag, cleanup):
99
self.netbox = api(address, token, ssl_verify=tls_verify)
1010
self.tag = tag
@@ -46,15 +46,15 @@ def sync_host(self, host):
4646
self.stats['unchanged'] += 1
4747
else:
4848
self.netbox.ipam.ip_addresses.create(
49-
address=host[0],
50-
tags=[self.tag],
49+
address=host[0],
50+
# tags=[self.tag],
5151
description=host[1]
5252
)
5353
logging.info(f'created: {host[0]}/32 "{host[1]}"')
5454
self.stats['created'] += 1
5555

5656
return True
57-
57+
5858
def garbage_collector(self, hosts):
5959
'''Removes records from NetBox not found in last sync'''
6060
nbhosts = self.netbox.ipam.ip_addresses.filter(tag=self.tag)
@@ -83,8 +83,9 @@ def sync(self, hosts):
8383
self.stats['unchanged'],
8484
self.stats['created'],
8585
self.stats['updated'],
86-
self.stats['deleted'],
86+
self.stats['deleted'],
8787
self.stats['errors']
8888
))
8989

9090
return True
91+

netbox-scanner.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ tls_verify = no
55
logs = .
66

77
[NMAP]
8-
path = samples/nmap
8+
path = /opt/netbox-scanner/samples/nmap
99
unknown = autodiscovered:netbox-scanner
1010
tag = nmap
1111
cleanup = yes

samples/nmap-scan.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22
#
33
# This is just an example.
44
#
@@ -16,11 +16,12 @@
1616
# to look for XML files.
1717
##
1818

19-
NETWORKS = "10.1.2.3/24 10.2.3.4/32 192.168.0.0/19"
20-
TODAY="$(date +%d.%m.%yT%H:%M:%S%Z)"
19+
NETWORKS="10.1.2.3/24 10.2.3.4/32 192.168.0.0/19"
20+
TODAY="$(date +%d%m%yT%H%M%S%Z)"
2121

2222
for net in $NETWORKS; do
23-
nmap -T4 -O -F --host-timeout 30s -oX nmap-"$net".xml
23+
rawNet="${net:0:-3}"
24+
sudo nmap -T4 -O -F --host-timeout 30s -oX nmap-"$rawNet".xml "$net"
2425
done
2526

2627
python ../netbox-scanner.py nmap

samples/nmap/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)