MikroTik RouterOS Automation with NAPALM

MikroTik RouterOS Automation with NAPALM

In this tutorial, we will explore using the NAPALM python module to query data from a MikroTik Router.

Before we begin, you are expected to have python3 and pip installed as well as access to a MikroTik router running RouterOS. NAPALM will attempt to connect to the router on the default API port of 8728. You will need to enable the API service which is found in IP | Services using winbox

mikrotik enable api service

This tutorial was developed as a Jupyter Notebook, it’s available on github if you want to download it and follow along. Download the Notebook

At the time of writing this article, the RouterOS NAPALM driver does not support configuration management for MikroTik routers. For now, we will look at what information can be read from the router.

DigitalOcean offers one-click deployment of popular applications such as WordPress, Django, MongoDB, Docker, and even preconfigured Kubernetes Clusters. Deploy your next app in seconds. Get $100 in cloud credits from DigitalOcean

Ad Notice I will receive a small commission that helps support this blog at no cost to you.

Here are the functions that NAPALM-ROS currently supports

According to the napalm-ros github page

  • get_arp_table
  • get_interfaces_counters
  • get_environment
  • get_facts
  • get_interfaces
  • get_interfaces_ip
  • get_ntp_servers
  • get_snmp_information
  • get_users
  • get_ipv6_neighbors_table
  • is_alive
  • ping

Create a new pipenv virtualenv and install napalm & napalm-ros

… or install with pip

If you have not idea what pipenv is, checkout my pipenv tutorial or alternatively you can install napalm & napalm-ros globally with pip.

Import NAPALM and the RouterOS driver

Provide your MikroTik Router’s IP and credentials

Configure the RouterOS driver then initialize and connect to the router

List available methods

As previously mentioned, some of these method such as .get_config() are not implemented (yet).

To begin, let’s see if we are connected to the router?

Ping from the router

To be clear, the ping() function performs an icmp ping from the router to some destination IP, not from your computer to the router.

A more advanced ping example with additional arguments

Get SNMP Configuration

Dump the Router’s Facts

Iterate over the Router Facts and print them

Iterate over the router facts interface list

Query the router’s interface counter statistics

Dump the Interfaces Stats

Dump a single interface’s stats

Iterate over an interface’s stats and print them

List users

Get all ARP Entries

Get Interface Information

Gracefully disconnect from the Router

References

Amazon AWS too complex and expensive? You will love the simplicity of DigitalOcean. Deploy your next app in seconds. Get $100 in cloud credits from DigitalOcean

Ad Notice I will receive a small commission that helps support this blog at no cost to you.

I hope you have enjoyed this python tutorial about NAPALM and RouterOS Automation. Checkout my other MikroTik tutorials and Python tutorials.

NetScout LinkRunner G2

LinkRunner G2 is the ultimate network cable test tool


CAT5 Cable Tester, Measure Cable Length,
PoE Voltage, Network Connectivity, Switch Port ID
Optional Wireless & Fiber Optics Modules
Check Price on Amazon

3 Replies to “MikroTik RouterOS Automation with NAPALM”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.