NetBox

repository·main·Indexed 12 days ago

https://github.com/netbox-community/netbox

A specialized IPAM (IP Address Management) and DCIM (Data Center Infrastructure Management) solution serving as a single source of truth for network infrastructure. It provides a structured data model, programmable APIs, and support for Jinja2 templates to enable network automation. NetBox is extensible via custom fields, tags, and plugins, and supports various authentication methods including Local, LDAP, Google OAuth2, Microsoft Entra ID, and Okta.

Tokens
161.5K
Snippets
382
Records
883
Agent score
96%

What's inside NetBox

  1. Overview of NetBox Form Classes

    main

    NetBox provides specialized base form classes for plugin development to ensure consistency with the core UI and data models. Depending on your use case, you should choose one of the following:

    • NetBoxModelForm: Used for creating or editing individual objects. Supports tags and custom fields.
    • NetBoxModelImportForm: Used for bulk importing objects from CSV, JSON, or YAML data.
    • NetBoxModelBulkEditForm: Used for editing multiple objects simultaneously. Fields are generally required=False.
    • NetBoxModelFilterSetForm: Used to render filtering forms within list views.

    Additionally, NetBox provides model-specific subclasses for these classes based on the model type (PrimaryModel, OrganizationalModel, or NestedGroupModel).

  2. Use Global Search to query the NetBox data model

    main

    NetBox provides a global search engine that indexes relevant fields across the data model. Results are returned based on field precedence, and the index is updated in real-time when objects are created or modified.

    Key search behaviors:

    • Lookup Types: Users can specify lookup types such as exact match or partial match.
    • Partial Matches: When a partial match occurs, the matching portion of the field value is highlighted in the results to show relevance.
    • Custom Fields: Administrators can include custom fields in search results by configuring a search weight for them.
    • Plugins: NetBox plugins can register custom models to appear in global search results.

    Important Limitation: NetBox does not index static choice fields. This includes custom fields of type Selection or Multiple selection.

  3. Automate actions with Event Rules

    main

    NetBox Event Rules allow you to automatically trigger specific actions in response to internal system events. When an event occurs that matches your rule's constraints, NetBox can automatically:

    • Execute a Custom Script: Run predefined Python scripts.
    • Send a Webhook: Dispatch data to external systems via HTTP.
    • Generate User Notifications: Alert users within the NetBox UI.

    To create a functional rule, you must associate it with at least one NetBox object type (e.g., Device, IP Address) and at least one event type (e.g., create, update, or delete).

  4. Use the NetBox GraphQL API for read-only queries

    main

    NetBox provides a read-only GraphQL API powered by Strawberry Django to complement the REST API. All queries are sent to the /graphql endpoint.

    For every object type, NetBox provides two query fields:

    • $OBJECT: Returns a single object. Requires a unique ID, e.g., device(id: 123).
    • $OBJECT_list: Returns a list of objects, which can be filtered using the filters argument.
    curl -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    http://netbox/graphql/ \
    --data '{"query": "query {circuit_list(filters:{status: STATUS_ACTIVE}) {cid provider {name}}}"}'
  5. Understand the NetBox Web UI code structure

    main

    Most static resources for the NetBox UI are located in netbox/project-static/. The directory structure is as follows:

    PathDescription
    dist/Destination path for installed dependencies and bundled assets
    docs/Local build path for documentation
    img/Image files
    js/Miscellaneous JavaScript resources served directly
    src/TypeScript resources (to be compiled into JS)
    styles/Sass resources (to be compiled into CSS)
  6. Identify NetBox core features and capabilities

    main

    NetBox provides a comprehensive set of features for network engineers and operators, including:

    IPAM & Layer 2/3

    • IP address management (IPAM) with full IPv4/IPv6 parity
    • Automatic provisioning of next available prefix/IP
    • VRFs with import & export route targets
    • VLANs with variably-scoped groups
    • AS number (ASN) management
    • FHRP groups (VRRP, HSRP, etc.)
    • Layer 2 VPN overlays

    Physical & Logical Infrastructure

    • Rack elevations with SVG rendering
    • Device modeling using pre-defined types
    • Virtual chassis and device contexts
    • Network, power, and console cabling with SVG traces
    • Power distribution modeling
    • Data circuit and provider tracking
    • Virtual machines & clusters
    • Flexible hierarchy for sites and locations
    • Tenant ownership assignment

    Automation & Extensibility

    • Custom fields for data model extension
    • Custom validation & protection rules
    • Custom reports & scripts executable within the UI
    • Extensive plugin framework
    • Event-driven scripts & webhooks
    • Device & VM configuration contexts for advanced configuration rendering
    • Detailed, automatic change logging
  7. Overview of NetBox extensibility and customization

    main

    NetBox is built on the Django framework and provides several mechanisms to extend its functionality and tailor the data model to specific organizational needs:

    • Data Model Customization: Use Custom fields to add metadata to existing objects.
    • Logic & Validation: Implement Custom model validation and Event rules to enforce data integrity and trigger actions.
    • Extending Functionality: Develop Plugins to add new features or Custom scripts (written in Python) to automate tasks.
    • Data Integration: Use the REST & GraphQL APIs to integrate NetBox with other tools or automation workflows.
    • Data Export: Use Export templates to define how data is extracted from the system.
  8. What is a NetBox plugin and what can it do?

    main

    A NetBox plugin is a self-contained Django app installed alongside NetBox to extend its functionality. Plugins can be enabled and configured independently within a single NetBox instance.

    Common use cases include:

    • Creating Django models to store custom data.
    • Providing custom web UI pages (views).
    • Injecting template content and navigation links.
    • Extending REST and GraphQL APIs.
    • Loading additional Django apps.
    • Adding custom request/response middleware.

    Warning: Only use officially supported components and the underlying Django framework. Any part of the NetBox codebase not documented in the official plugin API is considered internal and subject to change without notice.

  9. What is a Module Type and how is it used

    main

    A Module Type represents a specific make and model of hardware component that can be installed into a device's module bay. It is used to model field-replaceable components like line cards in a chassis-based switch or router.

    Each Module Type can act as a template for several component types, including:

    • Interfaces
    • Console ports
    • Console server ports
    • Power ports
    • Power Outlets
    • Front pass-through ports
    • Rear pass-through ports
    • Module bays

    Note: You cannot add device bays to modules.

  10. Manage Power Outlets in NetBox

    main

    Power Outlets represent the physical outlets on a Power Distribution Unit (PDU) or other power-supplying devices. They are used to model how power is distributed to dependent devices.

    Key capabilities include:

    • Mapping outlets to specific Power Ports to model power redistribution (e.g., a PDU outlet drawing from a specific upstream port).
    • Associating outlets with a Feed Leg to model three-phase power distribution (e.g., assigning outlets to Leg A, B, or C).
    • Using the Mark Connected flag to simulate a cable connection for the outlet.

    Automation Tip: Power outlets are automatically instantiated from Power Outlet Templates assigned to a Device Type whenever a new device is created.

  11. Prevent lost updates using ETags (NetBox v4.6+)

    main

    To prevent the 'lost-update' problem when multiple clients modify the same object, use the ETag header.

    1. Capture the ETag: Perform a GET, POST, PATCH, or PUT on a detail endpoint and inspect the ETag response header.
    2. Submit with If-Match: Include the captured ETag in the If-Match header of your subsequent PATCH or PUT request.

    If the object has changed since you captured the ETag, NetBox returns a 412 Precondition Failed error.

    Tip: Using If-Match: * will match any current ETag and can be used to assert that the object exists.

    # 1. Capture the ETag
    $ curl -s -i -H "Authorization: Bearer $TOKEN" http://netbox/api/dcim/sites/1/ | grep -i ^etag
    ETag: W/"2026-05-01T17:42:11.123456+00:00"
    
    # 2. Submit update with If-Match
    $ curl -s -X PATCH \
        -H "Authorization: Bearer $TOKEN" \
        -H "Content-Type: application/json" \
        -H 'If-Match: W/"2026-05-01T17:42:11.123456+00:00"' \
        http://netbox/api/dcim/sites/1/ \
        --data '{"status": "decommissioning"}'
  12. Model Virtual Chassis and Virtual Device Contexts

    main

    NetBox provides two ways to model logical groupings within physical hardware:

    1. Virtual Chassis: Used to model multiple physical devices that share a single management plane (e.g., stackable switches). One device acts as the chassis master, and the other devices are members. All components of the member devices are visible on the master device.
    2. Virtual Device Contexts (VDC): Used to model logical partitions within a single device. Each VDC operates autonomously but shares resources. Interfaces can be assigned to one or more VDCs.