How to Prepare Network inventory

This guide provides an overview of how to prepare and maintain Netbox inventory. The initial setup of Netbox involves a significant workload to add all our real infrastructure devices. To ensure consistency and establish Netbox as the source of truth, we need to implement an efficient pipeline. While there are paid synchronization tools available, this guide outlines a cost-effective approach to handle this task without premium subscriptions.
Overview of the Process
The design consists of two main engines: the Device Discovery Engine and the Device Configuration Check Engine.
Device Discovery Engine
The Device Discovery Engine is responsible for discovering network nodes within specific network subnets. This is achieved using the NMAP tool and the SNMP protocol. The steps involved are:
- Network Scanning: The engine scans the network subnets to identify active IP addresses.
- SNMP Response Check: For each active IP address, the engine checks if the device responds to SNMP queries.
- SysDescription Retrieval: If a device responds to SNMP, the engine retrieves the sysDescription using the MIB value
1.3.6.1.2.1.1.1.0
.
import nmap
def scan_ports(ip):
nm = nmap.PortScanner()
nm.scan(ip, '22,161', arguments='-sU')
for host in nm.all_hosts():
print(f'Scanning {host}')
for proto in nm[host].all_protocols():
lport = nm[host][proto].keys()
for port in lport:
state = nm[host][proto][port]['state']
print(f'Port {port}/{proto} is {state}')
# Example usage
scan_ports('10.60.115.132')
(.venv) mteke % snmpwalk -v3 -l authPriv -u SNMPV3User -a SHA -A ABCDEF -x AES -X ABCDEF 10.24.115.120 1.3.6.1.2.1.1.1.0
SNMPv2-MIB::sysDescr.0 = STRING: Cisco IOS Software [Cupertino], Catalyst L3 Switch Software (CAT9K_IOSXE), Version 17.9.4a, RELEASE SOFTWARE (fc3)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2023 by Cisco Systems, Inc.
Compiled Fri 20-Oct-23 10:44 by mcpre
Device Configuration Check Engine
Based on the retrieved sysDescription (device type), the appropriate Device Configuration Check Engine is selected. This engine performs the following tasks:
- Command Execution: Executes a set of predefined commands to collect detailed information from the remote node.
- Payload Preparation: Prepares the payload for adding the new device to Netbox.
- Device Addition: Adds the new device to Netbox.
Continuous Synchronization
This process runs in a loop every X hours/days to ensure that Netbox remains consistent with the real infrastructure. The continuous synchronization helps in maintaining an up-to-date inventory.
Process Algorithm
The following diagram illustrates the process algorithm:
- Start
- Network Scanning (NMAP)
- SNMP Response Check
- If SNMP responds:
- Retrieve sysDescription (MIB
1.3.6.1.2.1.1.1.0
) - Select Device Configuration Check Engine
- Execute Commands
- Prepare Payload
- Add Device to Netbox
- Retrieve sysDescription (MIB
- If SNMP does not respond:
- Skip to next IP address
- If SNMP responds:
- Wait for X hours/days
- Repeat
By following this apprach, you can efficiently prepare and maintain your Netbox inventory, ensuring it remains a reliable source of truth for your network infrastructure.