mirror of
https://github.com/lopes/netbox-scanner.git
synced 2025-07-23 13:54:48 +02:00
better documentation and log settings
This commit is contained in:
parent
18f2ff441c
commit
c8dfe5adc4
16
README.md
16
README.md
@ -9,11 +9,21 @@ A scanner util for NetBox, because certain networks can be updated automagically
|
|||||||
Note that `netbox-scanner` will require Nmap and an instance of NetBox ready to use.
|
Note that `netbox-scanner` will require Nmap and an instance of NetBox ready to use.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
`netbox-scanner` can be used both in your programs or as a script to be used in shell.
|
`netbox-scanner` can be used both in your programs or as a script to be used in shell. To use `netbox-scanner` as a script, edit `netbox-scanner/config.py` with your setup, and run the command below:
|
||||||
|
|
||||||
To use `netbox-scanner` as a script, edit `netbox-scanner/config.py` with your setup, and run the command below:
|
|
||||||
|
|
||||||
$ netbox-scanner.py
|
$ netbox-scanner.py
|
||||||
|
|
||||||
|
`netbox-scanner` will do the following tasks:
|
||||||
|
|
||||||
|
1. It will scan all networks defined in `netbox-scanner/config.py`.
|
||||||
|
2. For each discovered host it will:
|
||||||
|
1. If host is in NetBox, description is different, and tag is set as defined in `netbox-scanner/config.py/TAG`, it'll be updated.
|
||||||
|
2. If host is not in NetBox, it'll be created.
|
||||||
|
3. It will iterate through each network to find and delete hosts registered in NetBox that are not responsible to scan, and have the tag `netbox-scanner/config.py/TAG`.
|
||||||
|
|
||||||
|
This way, if some hosts in your networks that are monitored via `netbox-scanner` are eventually down, but you don't want to delete them, just make sure that it doesn't have the tag as set in `netbox-scanner/config.py/TAG`.
|
||||||
|
|
||||||
|
Of course, you can use `cron` to automatically run `netbox-scanner`.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
`netbox-scanner` is licensed under a MIT license --read `LICENSE` file for more information.
|
`netbox-scanner` is licensed under a MIT license --read `LICENSE` file for more information.
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
# netbox-scanner configuration file.
|
# netbox-scanner configuration file.
|
||||||
|
|
||||||
from logging import DEBUG
|
|
||||||
|
|
||||||
NETBOX = {
|
NETBOX = {
|
||||||
'ADDRESS': '',
|
'ADDRESS': '',
|
||||||
'TOKEN': '',
|
'TOKEN': '',
|
||||||
@ -9,21 +7,6 @@ NETBOX = {
|
|||||||
'PORT': 443,
|
'PORT': 443,
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGING_CONFIG = dict(
|
|
||||||
version = 1,
|
|
||||||
formatters = {
|
|
||||||
'f': {'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'}
|
|
||||||
},
|
|
||||||
handlers = {
|
|
||||||
'h': {
|
|
||||||
'class': 'logging.StreamHandler',
|
|
||||||
'formatter': 'f',
|
|
||||||
'level': DEBUG
|
|
||||||
}
|
|
||||||
},
|
|
||||||
root = {'handlers': ['h'], 'level': DEBUG},
|
|
||||||
)
|
|
||||||
|
|
||||||
TAG = 'auto'
|
TAG = 'auto'
|
||||||
UNKNOWN_HOSTNAME = 'UNKNOWN HOST'
|
UNKNOWN_HOSTNAME = 'UNKNOWN HOST'
|
||||||
DISABLE_TLS_WARNINGS = True # stop displaying TLS/SSL warnings?
|
DISABLE_TLS_WARNINGS = True # stop displaying TLS/SSL warnings?
|
||||||
|
@ -1,21 +1,26 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from logging import getLogger
|
import logging
|
||||||
from logging.config import dictConfig
|
import logging.handlers as handlers
|
||||||
|
|
||||||
import config
|
import config
|
||||||
from nbscan import NetBoxScanner
|
from nbscan import NetBoxScanner
|
||||||
|
|
||||||
dictConfig(config.LOGGING_CONFIG)
|
|
||||||
logger = getLogger('netbox-scanner')
|
logger = logging.getLogger('netbox-scanner')
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
formatter = logging.Formatter('%(asctime)s\t%(name)s\t%(levelname)s\t%(message)s')
|
||||||
|
loghandler = handlers.TimedRotatingFileHandler('netbox-scanner.log', when='M', interval=1, backupCount=2)
|
||||||
|
loghandler.setLevel(logging.INFO)
|
||||||
|
loghandler.setFormatter(formatter)
|
||||||
|
logger.addHandler(loghandler)
|
||||||
|
|
||||||
nbs = NetBoxScanner(config.NETBOX['ADDRESS'], config.NETBOX['TLS'],
|
nbs = NetBoxScanner(config.NETBOX['ADDRESS'], config.NETBOX['TLS'],
|
||||||
config.NETBOX['TOKEN'], config.NETBOX['PORT'], config.TAG,
|
config.NETBOX['TOKEN'], config.NETBOX['PORT'], config.TAG,
|
||||||
config.UNKNOWN_HOSTNAME, config.DISABLE_TLS_WARNINGS)
|
config.UNKNOWN_HOSTNAME, config.DISABLE_TLS_WARNINGS)
|
||||||
|
|
||||||
logger.debug('starting')
|
logger.info('starting')
|
||||||
nbs.sync(config.TARGETS)
|
nbs.sync(config.TARGETS)
|
||||||
logger.debug('finished')
|
logger.info('finished')
|
||||||
|
|
||||||
exit(0)
|
exit(0)
|
||||||
1975107045
|
|
2
setup.py
2
setup.py
@ -7,7 +7,7 @@ with open("README.md", "r") as fh:
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="netbox-scanner",
|
name="netbox-scanner",
|
||||||
version="0.0.5",
|
version="0.1.0",
|
||||||
author='José Lopes de Oliveira Jr.',
|
author='José Lopes de Oliveira Jr.',
|
||||||
author_email="jlojunior@gmail.com",
|
author_email="jlojunior@gmail.com",
|
||||||
description="A scanner util for NetBox",
|
description="A scanner util for NetBox",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user