add ssl_verify parameter to disable ssl verification for testing

This commit is contained in:
bile0026 2020-11-10 19:45:38 -06:00
parent 8a842d3c5f
commit 8dc40a7534
5 changed files with 51 additions and 29 deletions

4
.gitignore vendored
View File

@ -106,3 +106,7 @@ venv.bak/
# trash # trash
.vscode/ .vscode/
scans/*
logs/*
test_api.py

View File

@ -1,21 +1,37 @@
import logging import logging
import requests
from pynetbox import api from pynetbox import api
class NetBoxScanner(object): class NetBoxScanner(object):
def __init__(self, address, token, tag, cleanup): def __init__(self, address, token, ssl_verify, tag, cleanup):
self.netbox = api(address, token) if (ssl_verify == 'No'):
self.tag = tag session = requests.Session()
self.cleanup = cleanup session.verify = False
self.stats = { self.netbox = api(address, token)
'unchanged': 0, self.netbox.http_session = session
'created': 0, self.tag = tag
'updated': 0, self.cleanup = cleanup
'deleted': 0, self.stats = {
'errors': 0 'unchanged': 0,
} 'created': 0,
'updated': 0,
'deleted': 0,
'errors': 0
}
else:
self.netbox = api(address, token)
self.tag = tag
self.cleanup = cleanup
self.stats = {
'unchanged': 0,
'created': 0,
'updated': 0,
'deleted': 0,
'errors': 0
}
def sync_host(self, host): def sync_host(self, host):
'''Syncs a single host to NetBox '''Syncs a single host to NetBox

View File

@ -1,26 +1,27 @@
[NETBOX] [NETBOX]
address = <server> address = <server>
token = <key> token = <token>
logs = logs/ logs = logs/
ssl_verify = No
[NMAP] [NMAP]
path = ./ path = ./
unknown = autodiscovered:netbox-scanner unknown = autodiscovered:netbox-scanner
tag = nmap tag = nmap
cleanup = yes cleanup = no
# [NETXMS] [NETXMS]
# address = https://netxms.domain address = https://netxms.domain
# username = username =
# password = password =
# unknown = autodiscovered:netbox-scanner unknown = autodiscovered:netbox-scanner
# tag = netxms tag = netxms
# cleanup = yes cleanup = yes
# [PRIME] [PRIME]
# address = https://prime.domain/webacs/api/v4 address = https://prime.domain/webacs/api/v4
# username = username =
# password = password =
# unknown = autodiscovered:netbox-scanner unknown = autodiscovered:netbox-scanner
# tag = prime tag = prime
# cleanup = yes cleanup = yes

View File

@ -87,6 +87,7 @@ if __name__ == '__main__':
scanner = NetBoxScanner( scanner = NetBoxScanner(
netbox['address'], netbox['address'],
netbox['token'], netbox['token'],
netbox['ssl_verify'],
nmap['tag'], nmap['tag'],
nmap.getboolean('cleanup') nmap.getboolean('cleanup')
) )

View File

@ -16,7 +16,7 @@
# to look for XML files. # to look for XML files.
## ##
NETWORKS="192.168.252.0/24 192.168.3.0/24" NETWORKS="192.168.3.0/24 192.168.252.0/24"
TODAY="$(date +%d.%m.%yT%H:%M:%S%Z)" TODAY="$(date +%d.%m.%yT%H:%M:%S%Z)"
for net in $NETWORKS; do for net in $NETWORKS; do
@ -25,6 +25,6 @@ for net in $NETWORKS; do
nmap "$net" -T4 -sn --host-timeout 30s -oX nmap-"$NETNAME".xml nmap "$net" -T4 -sn --host-timeout 30s -oX nmap-"$NETNAME".xml
done done
python netbox-scanner.py nmap python3 netbox-scanner.py nmap
tar -czvf scans/nmap-"$TODAY".tar.gz *.xml tar -czvf scans/nmap-"$TODAY".tar.gz *.xml
rm -rf *.xml rm -rf *.xml