Wrapping up our presentations at Networking Field Day 21 last week, I was fortunate to spend some time discussing NetBox and its role as a robust source of truth within a network automation framework. Most people who use NetBox are familiar with its web interface and to some extent its REST API, but there are a variety of ways NetBox enables the import and export of data to support highly automated workflows. If you haven’t had a chance to check out NetBox yet, you can find the project on GitHub and the documentation here.

CSV Import/Export

NetBox supports CSV-formatted data import for most objects. This is very convenient for migrating data from spreadsheets to NetBox. All that’s needed is to ensure the required columns are present and named appropriately, and that the data is in a valid format. NetBox also provides a means to export data in CSV format for use by other applications.

CSV import form

Export Templates

While the built-in CSV export function is handy, there is often a need to provide more control over the format of exported data. This can be done using export templates, which leverage the Jinja2 templating language to render arbitrary output. For instance, you might write an export template to generate a Nagios configuration file from a set of NetBox devices. Within the NetBox UI, you can then navigate to the devices list and select your custom template under the “export” button. The generated document will be provided for direct download.

Export template form

Webhooks

Sometimes it’s necessary to automatically update related systems whenever data in NetBox changes. For example, maybe you need to update a network monitoring system every time a new device is added in NetBox. This can be accomplished by creating a webhook under NetBox’s admin UI. Simply select the type(s) of object that you’re interested in, the actions on which to trigger (creation, modification, and/or deletion), and the attributes of the remote system to be notified. When the relevant changes occur, NetBox will automatically generate an HTTP POST request to the remote system with all the details of the change and the object’s new state.

Webhooks form

To see a demonstration of webhooks in action, check out Jason Edelman’s presentation.

REST API

The most robust mechanism for exchanging data with NetBox is its REST API. The API allows for nearly the same degree of functionality as the web UI (with a few caveats) and supports the creation, retrieval, modification, and deletion of objects. All objects are represented in the API using JSON serialization. NetBox provides a human-friendly browsable version of the API locally, as well as live documentation using OpenAPI (Swagger). Client libraries such as pynetbox are available to simplify the consumption of NetBox’s API by external systems.

Browsable REST API

Custom Scripts

Custom script are a new feature in NetBox, introduced in v2.6.3, which allows an administrator to extend NetBox with arbitrary Python code. These scripts are rendered as forms in the web UI, prompting the user for data which the script processes to perform some action. Scripts can create new objects in NetBox, manipulate existing objects, import data from or send data to remote systems – anything, really. This feature is especially powerful as it allows for the extension of NetBox’s core functionality without introducing the need to maintain a custom fork of the project.

Custom script form

NetBox and Network to Code

While NetBox offers plenty of avenues for integration with other systems, we understand that actually writing the code to engage these features is often easier said than done. Fortunately, Network to Code is proud to offer commercial support for NetBox as well as assistance with custom development. Leveraging our expertise with NetBox and related network automation tools, we are uniquely positioned to deliver extremely high value solutions with quick turnaround. Let us know what we can do for you!

The full series of videos from our NFD21 presentation is posted on Tech Field Day.