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.

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

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

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.

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

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


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.