mirror of
https://github.com/lopes/netbox-scanner.git
synced 2025-07-22 21:34:56 +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.
|
||||
|
||||
## Usage
|
||||
`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:
|
||||
`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:
|
||||
|
||||
$ 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
|
||||
`netbox-scanner` is licensed under a MIT license --read `LICENSE` file for more information.
|
||||
|
@ -1,7 +1,5 @@
|
||||
# netbox-scanner configuration file.
|
||||
|
||||
from logging import DEBUG
|
||||
|
||||
NETBOX = {
|
||||
'ADDRESS': '',
|
||||
'TOKEN': '',
|
||||
@ -9,21 +7,6 @@ NETBOX = {
|
||||
'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'
|
||||
UNKNOWN_HOSTNAME = 'UNKNOWN HOST'
|
||||
DISABLE_TLS_WARNINGS = True # stop displaying TLS/SSL warnings?
|
||||
|
@ -1,21 +1,26 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from logging import getLogger
|
||||
from logging.config import dictConfig
|
||||
import logging
|
||||
import logging.handlers as handlers
|
||||
|
||||
import config
|
||||
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'],
|
||||
config.NETBOX['TOKEN'], config.NETBOX['PORT'], config.TAG,
|
||||
config.UNKNOWN_HOSTNAME, config.DISABLE_TLS_WARNINGS)
|
||||
|
||||
logger.debug('starting')
|
||||
logger.info('starting')
|
||||
nbs.sync(config.TARGETS)
|
||||
logger.debug('finished')
|
||||
logger.info('finished')
|
||||
|
||||
exit(0)
|
||||
1975107045
|
Loading…
x
Reference in New Issue
Block a user