Integrating Mikrotik RouterOS into Netbox

2,653 views
Skip to first unread message

Barry Awure

unread,
Oct 21, 2020, 4:18:56 PM10/21/20
to NetBox
Hi all,
Can you help me on how I can get my mikrotik routerOS devices into Netbox automatically.
I have installed Napalm-ros into the Netbox server. I am able to get the devices automatically through the python shell of the server. 
I cannot seem to get how to get the devices automatically into Netbox. 

Can you please help out. If possible a good guide or  working script will be nice. 

Brian Candler

unread,
Oct 22, 2020, 2:49:54 AM10/22/20
to NetBox
Netbox is a manually-curated source-of-truth database.  It does not auto-discover devices, or add anything automatically.  The Napalm integration is only for the LLDP and Config tabs under the device view.

If you want a tool which shows you an auto-discovered view of what is running in your network, then a different tool may suit you better (LibreNMS, Netdisco, Netdot, ...).  Of course, such tools can only show you a logical view of your network: they cannot work out the underlying physical details, such as what rack position a device is in, or how cables are routed via patch panels, or how the power and console cables are connected.

Regards,

Brian.

Barry Awure

unread,
Oct 22, 2020, 3:51:39 AM10/22/20
to Brian Candler, NetBox
Hi Brain,
Thanks for the response.
What I really want to accomplish is to set up a system that can help me automate my network, handle IP and VLAN allocation, and dynamic configuration to my end devices, reducing human involvement in client provisioning.
I have looked into ansible for autoconfiguration,
I need an application that can work with ansible to allocate IPs and VLANs to clients automatically and also discover my present network for already allocated IPs so we don't have duplicate IPs. I felt Netbox could do it guess I was wrong.

Kindly point me in the right direction to the systems I can put together to deliver this. I have majorly Mikrotik RouterOs devices, ubuquiti, and cambium devices in my network.

I really appreciate your support.

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/77921c44-5f59-4c3f-b6e4-5869bd950332o%40googlegroups.com.

Christopher Mills

unread,
Oct 22, 2020, 4:37:19 AM10/22/20
to NetBox, Brian Candler, Barry Awure

NetBox can’t automatically configure your devices, but it absolutely can help by providing a source of truth about the devices you want to configure should look. As Brian says, the information in NetBox is manually curated so you need to fill in all the information that you want in advance then use NetBox to help you plan your rack and IP layout and other tools, such as Ansible, to pull any interesting bits of of NetBox (via the API) to help you configure them.

There aren’t a great deal of tools designed to automatically populate NetBox and personally I would avoid them anyway - the point being that if you can’t explain in your head what your rack and IP space should look like, having a suite of automation tools isn’t going to help you configure them.

Depending on the device types you have, a good place to start is to make sure you have all of those ready in the Device Type library. Getting these right is, for me, the most time consuming part. You can import pre-written device definitions from YAML files held in Github https://github.com/netbox-community/devicetype-library, but they are community sourced and you will no doubt have some differences on the ground. When you create a device in NetBox, you copy the device type template to the device, it isn’t linked. So, for example, if all of your devices have dual power supplies, but the device type you create doesn’t have any, you will need to manually add two power supplies to each device when you get around to documenting the connections - it’s a laborious process if you have lots of devices. So best advice is get your templates as close as you can first.

HTH

Brian Candler

unread,
Oct 22, 2020, 4:54:44 AM10/22/20
to NetBox
On Thursday, 22 October 2020 08:51:39 UTC+1, Barry Awure wrote:
What I really want to accomplish is to set up a system that can help me automate my network, handle IP and VLAN allocation, and dynamic configuration to my end devices, reducing human involvement in client provisioning.

It sounds like you are provisioning "outbound": pushing configs to new devices.  If so, a source-of-truth database would be a very good core for that.  The database tells you how the devices *should* be configured, and then you push that configuration outwards torwards the devices.

That's different to documenting the configuration as-is.  That would involve pulling the configuration *from* the devices and recording it.  And a device-discovery tool is no good for provisioning fresh devices, since all it can tell you is the blank configuration the device has, not the configuration it *should* have.
 
I have looked into ansible for autoconfiguration,
I need an application that can work with ansible to allocate IPs and VLANs to clients automatically

You can use the Netbox API to request IPs to allocate to devices.  Your workflow could then be something like:

- add a device (which you can do via the API too)
- call the API to allocate an IP address
- generate a configuration and push it out to the device

That's the workflow you have to write yourself, because it's very specific to your own organization and processes.  You can use Netbox as the underlying source-of-truth database, and also as the GUI that people use to view and update that data.

and also discover my present network for already allocated IPs so we don't have duplicate IPs.

That's a question of setting Netbox to the current state of your network.  You can populate that through the API too if you wish, but it's up to you to collect and sanitise the data; Netbox doesn't know what data is good (things as they should be) and what data is bad (things on your network that shouldn't be there).

You might want to do more than just recording IPs to avoid duplicates.  You may want to associate IPs to devices and virtual machines.  To do that in Netbox, you have to create the associations:

Device ----------< Interface ----< IP Address
VirtualMachine --< VMInterface --< IP Address

But you don't have to; you can use Netbox as an IPAM and nothing else, if you choose.

Brian Candler

unread,
Oct 22, 2020, 5:04:49 AM10/22/20
to NetBox
On Thursday, 22 October 2020 09:37:19 UTC+1, Christopher Mills wrote:
When you create a device in NetBox, you copy the device type template to the device, it isn’t linked. So, for example, if all of your devices have dual power supplies, but the device type you create doesn’t have any, you will need to manually add two power supplies to each device when you get around to documenting the connections - it’s a laborious process if you have lots of devices. So best advice is get your templates as close as you can first.


Once upon a time, I wrote a report which identifies devices with missing components:

and a script which updates all devices, by adding all missing components from the device type:

I never updated the latter to a "custom script" that could be run via the GUI, or so that you could run it against a single device.  If anyone wants to do this, please feel free.

Matthew Yauch

unread,
Oct 22, 2020, 6:55:00 PM10/22/20
to NetBox
I have had quite a bit of experience with MikroTiks, at my previous position they were our primary gateway device for client NAT networks and I managed a fleet of > 340 of them (CCR 1036s and RB1100s). There are Python modules for interacting with the RouterOS API. I have used https://github.com/socialwifi/RouterOS-api to great effect, and it looks like there is even a newer option released since I left that company https://github.com/luqasz/librouteros

What I did, and what I recommend, is setup NetBox as your backend database. Write Python scripts that can poll your MikroTiks for interfaces and whatever data you wish to populate into NetBox. Use the RouterOS API module to pull data, and the pynetbox module to push data to NetBox. This should be a one-off deal just to get the information in there, and make sure you are auditing the information for correctness as you do this.

Then write yourself some scripts or a Flask/Django web interface (or add custom scripts into NetBox) that simultaneously perform automated network configuration tasks on the MikroTik (using RouterOS API) and update documentation (using pynetbox).

Christopher Mills

unread,
Oct 23, 2020, 3:19:58 AM10/23/20
to Brian Candler, NetBox
I’ve seen your port checking report before Brian and it inspired me to create something similar - I can’t remember why right now but yours out of the box didn’t work for me. One improvement might be to use port labels rather than names as port names change, especially when stacking switches/using virtual chassis.

I hadn’t seen your script to correct the devices though and it feels like a plug-in with this functionality would be awesome - perhaps presenting the differences as a rock list and allowing the user to choose which to apply to cope with the situation above or where a user has deliberately removed a PSU or something?

Sent from my iPhone

On 22 Oct 2020, at 10:04, Brian Candler <b.ca...@pobox.com> wrote:


--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.

Brian Candler

unread,
Oct 23, 2020, 4:12:48 AM10/23/20
to NetBox
On Friday, 23 October 2020 08:19:58 UTC+1, Christopher Mills wrote:
I can’t remember why right now but yours out of the box didn’t work for me.

The accessors on the models have changed their names.  I've pushed an update to those gists now.

Barry Awure

unread,
Nov 3, 2020, 12:52:46 AM11/3/20
to Brian Candler, NetBox
Hi guys,
Thanks so much for all your response and suggestions.

These are my thoughts and plan of action.
I intend using SolarWinds to monitor my network use the result of SolarWinds to populate Netbox for my present network. Netbox will then be used as inventory for ansible tower.

I hope my thought is good enough. 

Be the way side, has anyone been able to install netdot. I have tried several ways to get it up all to no avail. If anyone can help out I will appreciate it.

Regards

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.

Brian Candler

unread,
Nov 3, 2020, 3:21:31 AM11/3/20
to NetBox
On Tuesday, 3 November 2020 05:52:46 UTC, Barry Awure wrote:
Be the way side, has anyone been able to install netdot. I have tried several ways to get it up all to no avail. If anyone can help out I will appreciate it.


Netdot is dead, because Perl Class::DBI which Netdot heavily depends on is abandonware, and mod_perl is buggy as hell - although I did hear a rumour someone is considering rewriting Netdot in a real programming language.

However, I was able to get it to work under Ubuntu 16.04 with some patching to Class::DBI:

I haven't tried 18.04 or 20.04, but someone has reported success with 18.04:

You probably also need
[mysqld]
max_allowed_packet = 16M
in mysql.conf

Barry Awure

unread,
Nov 3, 2020, 9:28:06 AM11/3/20
to Brian Candler, NetBox
Thanks Brain. 


--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages