I’ve been playing with Netbox lately as a SSOT (Single Source of Truth) for some automation tasks I’m looking at. The problem is I need more data wrapped around Interfaces, ie: on anything layer 2, I’d like to know things like Storm Control settings, Portfast etc.

There’s been more than a few feature requests for this on the github site, but the devs have decided this isn’t really in the Netbox remit – which is understandable, this is their software overall.

2.8 introduced the Plugin architecture, so what I’m trying to achieve may be possible which that, but examples are fairly thin on the ground + I was more interested in how difficult this would be to apply to Interface objects.

Also note – I’m not a fan of hacking OSS to make it more difficult to then update.

*** CAVEAT *** – this is hack, not all functionality is tested and it make break many other things – use at your own risk. I am *not* responsible for any/all breakages.

So, how to do this:

Add in Custom Field functionality to Interface Objects

in netbox/dcim/models/device_components.py


from extras.models import CustomFieldModel


@extras_features('graphs', 'export_templates', 'webhooks')
class Interface(CableTermination, ComponentModel):


@extras_features('graphs', 'export_templates', 'webhooks','custom_fields')
class Interface(CableTermination, ComponentModel, CustomFieldModel):

In class Interface() add the below function:

custom_field_values = GenericRelation(

Restarting Netbox, going to the admin page now should give us:

So lets add a test one:

Add to View/Edit Fields

In: netbox/netbox/templates/dcim/interface.html
{% include 'inc/custom_fields_panel.html' with obj=interface %}
{% include 'extras/inc/tags_panel.html' with tags=interface.tags.all %}

In: netbox/netbox/templates/dcim/interface_edit.html

add the below below the ending /div for panel-default:

{% if form.custom_fields %}
        <div class="panel panel-default">
            <div class="panel-heading"><strong>Custom Fields</strong></div>
            <div class="panel-body">
                {% render_custom_fields form %}
    {% endif %}

In: /opt/netbox/netbox/dcim/forms.py

class InterfaceForm(InterfaceCommonForm, BootstrapMixin, forms.ModelForm, CustomFieldModelForm):
class InterfaceForm(InterfaceCommonForm, BootstrapMixin, CustomFieldModelForm):

After restarting Netbox, we should now be able to view/edit our custom fields:



Showing this in the API

In: /opt/netbox/netbox/dcim/api/views.py

class InterfaceViewSet(CableTraceMixin, ModelViewSet):


class InterfaceViewSet(CableTraceMixin, CustomFieldModelViewSet):

In: /opt/netbox/netbox/dcim/api/serializers.py

class InterfaceSerializer(TaggitSerializer, ConnectedEndpointSerializer)
class InterfaceSerializer(TaggitSerializer, ConnectedEndpointSerializer,CustomFieldModelSerializer):

in class meta: (under the InterfaceSerializer Class): add ‘custom_fields’ to fields = [

Now testing using the API:

*** CAVEAT *** – this is hack, not all functionality is tested and it make break many other things – use at your own risk. I am *not* responsible for any/all breakages.

It’d be nice for this to be conditional (ie: l3 interface, specific set of custom fields, but this is possible using a l2/l3 custom field…)



No responses yet

Leave a Reply

Your email address will not be published.

sixteen + twenty =

About This Site

This may be a good place to introduce yourself and your site or include some credits.