How do you easily enter individual devices into netbox?

1,282 views
Skip to first unread message

Carsten Aulbert

unread,
Sep 23, 2021, 8:50:50 AM9/23/21
to NetBox
Hi all,

we do use netbox now for a bit after entering the majority of our
devices via a script we cobbled together along with CSV files for serial
numbers and other bits and pieces - I never really appreciated hand-held
laser scanners before doing this ;-).

However, I find entering individual devices a bit of a pain, especially
as I only do it so rarely that I always end up having a hard time to get
it right through the various layers of device/interface/IP addresses
along with their types, tags, ... on my first try.

I am currently thinking about putting the variable bits into YAML/JSON
and write a small script to enter that information into netbox along
with static or derived information and then simple re-use the once
created file as a template.

But before going back practicing Python again, I wanted to at least ask
here, how people go about this? Using the built-in interfaces, uploading
CSV files or something I completely overlooked and thus making a total
fool out of myself with this question here?

Cheers and thanks a lot in advance for any insight!

Carsten

PS: Typical host I would want to add:

Device with name and location (single tenent/site), device type, serial
number, asset tag, role, custom field, tags.

Typically three to four interfaces where two may be LACP aggregated and
one is an out of band port. Usually, each logical iface will only have a
single IP address from different hierarchies.

--
Dr. Carsten Aulbert, Max Planck Institute for Gravitational Physics,
Callinstraße 38, 30167 Hannover, Germany, Phone +49 511 762 17185


Brian Candler

unread,
Sep 23, 2021, 10:01:59 AM9/23/21
to NetBox
If you're adding devices individually via the web, then a custom script may be what you want.  Here's an example which creates Virtual Machines from data collected in a form:
https://github.com/netbox-community/reports/blob/master/scripts/create_vm.py
It lets you collect all the data up-front, validate it, and then create all the necessary objects (devices, interfaces, IP addresses etc).  Of course, you still need to write that in Python.

For handling a bulk upload, then a custom script which takes a file var may be the best way to do it - and as you say, parse YAML or JSON to define the actions.

Otherwise, the options are CSV upload as you already know; standalone CLI scripts (e.g. using nbshell); and talking to the REST API, e.g. with pynetbox.

Carsten Aulbert

unread,
Sep 23, 2021, 11:02:35 AM9/23/21
to Brian Candler, NetBox
Hi Brian,

On 23.09.21 16:01, Brian Candler wrote:
> If you're adding devices individually via the web, then a custom script
> <https://netbox.readthedocs.io/en/stable/customization/custom-scripts/>
> may be what you want.  Here's an example which creates Virtual Machines
> from data collected in a form:
> https://github.com/netbox-community/reports/blob/master/scripts/create_vm.py
> It lets you collect all the data up-front, validate it, and then create
> all the necessary objects (devices, interfaces, IP addresses etc).  Of
> course, you still need to write that in Python.
indeed (I also got two more nudges to this outside the list). Somehow, I
knew about the custom scripts but somehow mixed that together with the
reports and thought this was an add-on to create reports with some user
input rather than what it really is.

Thanks everyone for this pointer, that is what I will try to make this
smoother :)

Cheers

Carsten
Reply all
Reply to author
Forward
0 new messages