Package: nesbi
nesbiNesbi (Network Scan, Build and Import data) is a python-library which gives the possibility to scan defined network-ranges for network-devices, read out facts of them, build structured data and import them to a cmdb. At the moment the only supported cmdb is nsot.
The heart of nesbi is a config-file which makes it very flexible and generic.How it worksNesbi is based onnapalmnsotnelsnmpThe following procedure is running with multiple threads per given network/locationnetwork-range gets scanned with multiple threads for opened ports (=nesbi_port_scan variable)reachable devices get scanned with nelsnmp to find out the device OSnapalm scans the device to get factsdictionary/data for nsot-import gets builtdata gets imported into nsotSupported napalm-factsAll facts that are collected by the following napalm-functions are supported (napalm documentation):get_facts()get_interfaces()get_interfaces_ip()get_snmp_information()Installing nesbi$ pip install nesbiRequirementsRequirements are defined in:requirements.txt.
Nesbi needs at least python 3.6 and doesn't support earlier versions.Configuring nesbiDefining the configThe very first step is defining the config file. The file contains of different parts.cmdb-attributesattribute-namepurposenetworkscontains name, range and static key/value pairs which should be added to cmdbtypesmap device-model dependent variables to cmdb attributes. Given model-name has to match the model-fact which gets read out by napalm.attr_functionsmap return-values of functions to cmdb attributesnapalmmap napalm variables to cmdb attributesattr_functions have to be: defined in config + python code and given as function argument when calling Nesbi().If you need to exclude addresses (e.g. when using HSRP for high availability of gateway addresses) you can set theexcludeattribute. It has to contain a list of IPv4 addresses. Network- and broadcast-addresses are excluded by default (for networks greater than /31).
It is possible to scan a single IP when defining the network-range with a/32subnet-mask.application-attributesApplication-attributes can be given in the config file, as environment-variables (UPPER-CASE) or as function-arguments when calling nesbi(). Only attributes which have no default value and are required for nesbi to work correctly are marked as required.The variables get overwritten in the following order: Nesbi() > config > ENV > default.attribute-namerequireddefaultdescriptionnsot_urlyesnot defined/nsot_emailyes/nonot definedrequired when using nsot_secret_key as nsot auth methodnsot_secret_keyyes/nonot definedrequired when using nsot_secret_key as nsot auth methodnsot_auth_headeryes/noX-NSoT-Emailrequired when using auth_header as nsot auth methodnsot_site_idno1/nsot_delete_objectsnoFalseif set to True existing nsot-objects will be deleted before adding themnesbi_network_drivernonot definedoverwrites the network driver detected by nelsnmpnesbi_usernameyesnot definedusername for napalmnesbi_passwordyesnot definedpassword for napalmnesbi_snmp_versionyes2conly v2c is supported at the momentnesbi_snmp_communityyesnot definedsnmp community with read rightsnesbi_scan_portsno[22]tcp-ports which should be scanned to get reachable network devicesnesbi_dry_runnoFalseif set to True nothing will be changed in the cmdbnesbi_logging_levelnoinfovalid log-levels arenotset, debug, info, warning, error, criticalnesbi_logging_filenonesbi.logcustom log file name. If set to False no log file will be generatednesbi_logging_to_stdoutnoFalse/nesbi_thread_limitno5limits maximum parallel running threadsconfig exampleconfig.ymlUsing nesbinesbi is a library which has to be used in pure python. As soon as your config-file is ready you can do something like:nesbi-example.pyand execute it:python3 nesbi-example.pyLoggingNesbi uses thelogging-moduleof the python standard-library. By defaultnesbi_logging_fileis set tonesbi.logand thenesbi_logging_levelis set toinfo. This will generate the log-file in the directory from where you run the python-script.Sample Output2018-04-13 21:34:55,463 -        nesbi.core.scanner -     INFO - Start port-scan for network/location mylocation
2018-04-13 21:34:55,504 -        nesbi.core.scanner -     INFO - 192.168.0.131 reachable at tcp-port 22
2018-04-13 21:34:55,505 -        nesbi.core.scanner -     INFO - 192.168.0.132 reachable at tcp-port 22
2018-04-13 21:34:55,505 -        nesbi.core.scanner -     INFO - 192.168.0.133 reachable at tcp-port 22
2018-04-13 21:34:58,520 -        nesbi.core.scanner -     INFO - Start device-scan for network/location mylocation
2018-04-13 21:35:05,521 -        nesbi.core.scanner -     INFO - 192.168.0.131: detected os "ios"
2018-04-13 21:35:06,047 -        nesbi.core.scanner -     INFO - 192.168.0.132: detected os "ios"
2018-04-13 21:35:06,301 -        nesbi.core.scanner -     INFO - 192.168.0.133: detected os "ios"
2018-04-13 21:35:21,402 -        nesbi.core.scanner -     INFO - Switch131 scanned with napalm
2018-04-13 21:35:22,308 -        nesbi.core.scanner -     INFO - Switch132 scanned with napalm
2018-04-13 21:35:22,363 -        nesbi.core.scanner -     INFO - Switch133 scanned with napalm
2018-04-13 21:37:00,808 -           nesbi.core.nsot -     INFO - Switch131 create dry-run
2018-04-13 21:37:00,809 -           nesbi.core.nsot -     INFO - Switch132 create dry-run
2018-04-13 21:37:00,809 -           nesbi.core.nsot -     INFO - Switch133 create dry-runContributingFork and send a Pull Request. Thanks!LicenseCopyright (c) 2022 dm-drogerie markt GmbH & Co. KG,https://dm.dePermission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.