published

Writing code today often means interacting with API of many products. For me it means the possibility to integrate existing tools or create new functions.

Sometimes it is just a matter to create a small utility.

The Problem

Meraki Dashboard does not include a page that shows the CDP/LLDP neighbors. Can we do better than Make a Wish?

The Solution

I wrote a Python script that uses Meraki API to list LLDP and CDP information for a device.

My goal was to provide the script to a NOC to allow the operators to get the information from a simple to use CLI command.

The Details

Start enabling API in the Meraki dashboard from Organization/Settings


Then create and API Key


Save the API Key, it will not be show in clear text after the creation.

Now get the script from GitHub:

git clone https://github.com/routetonull/getMerakiNeighbor

Install the necessary module

pip3 install meraki

or upgrade the module to the latest release if already installed

pip3 install --upgrade meraki

There are two ways to provide the API key to the script.

Via the command line:

python3 getMerakiNeighbor.py -K 99999999999999999999999999999999999f88ec

or setting and environment variable

export apikey=99999999999999999999999999999999999f88ec

I’ll be using the Meraki Masters demo dashboard for the following examples

If we run the script without parameters it will list the available organizations:

python3 getMerakiNeighbor.py

ORGANIZATIONS AVAILABLE

NAME: DevNet Sandbox                            ID: 549236
NAME: Meraki Launchpad🚀                        ID: 537758

Then run the script specifying the organization, it will list all the available networks for that organization:

python3 getMerakiNeighbor.py -O 549236

NETWORKS AVAILABLE FOR ORGANIZAZION "DevNet Sandbox" with ID 549236

NETWORK: DevNet Always On Read Only                         ID: L_646829496481099586
NETWORK: test - mx65                                        ID: N_646829496481152899
NETWORK: Long Island Office                                 ID: L_646829496481103488
NETWORK: DNSMB1                                             ID: L_646829496481103758
NETWORK: DNSMB4                                             ID: L_646829496481103761
NETWORK: DNSMB2                                             ID: L_646829496481103770
NETWORK: DNSMB3                                             ID: L_646829496481103772
NETWORK: DNENT1                                             ID: L_646829496481103780
NETWORK: DNSMB5                                             ID: L_646829496481103781
NETWORK: DNENT3                                             ID: L_646829496481103784
NETWORK: DNENT2                                             ID: L_646829496481103786

Specify a network to get all the CDP or LLDP neighbors for that network:

python3 getMerakiNeighbor.py -O 549236 -N L_646829496481099586
CDP  LOCAL Q2QN-9J8L-SLPD           SOURCE-PORT wan0     REMOTE DEVICE main-sw                                  REMOTE PORT GigabitEthernet1/0/3     REMOTE IP 10.10.10.254
CDP  LOCAL Q2QN-9J8L-SLPD           SOURCE-PORT port10   REMOTE DEVICE 881544dff3af                             REMOTE PORT Port 8                   REMOTE IP 10.182.255.47
LLDP LOCAL Q2QN-9J8L-SLPD           SOURCE-PORT port10   REMOTE DEVICE Meraki MS220-8P - DevNet Always On Read  REMOTE PORT 8                        REMOTE IP 10.182.255.47

We can filter for a specific protocol, CDP:

python3 getMerakiNeighbor.py -O 549236 -N L_646829496481099586 -P cdp

CDP  LOCAL Q2QN-9J8L-SLPD           SOURCE-PORT wan0     REMOTE DEVICE main-sw                                  REMOTE PORT GigabitEthernet1/0/3     REMOTE IP 10.10.10.254
CDP  LOCAL Q2QN-9J8L-SLPD           SOURCE-PORT port10   REMOTE DEVICE 881544dff3af                             REMOTE PORT Port 8                   REMOTE IP 10.182.255.47

or LDDP:

python3 getMerakiNeighbor.py -O 549236 -N L_646829496481099586 -P lldp

LLDP LOCAL Q2QN-9J8L-SLPD           SOURCE-PORT port10   REMOTE DEVICE Meraki MS220-8P - DevNet Always On Read  REMOTE PORT 8                        REMOTE IP 10.182.255.47

In some cases we may need to print all the neighbors of a specific organization, let’s use the –all flag:

python3 getMerakiNeighbor.py -O 549236 --all

CDP  LOCAL Q2QN-9J8L-SLPD           SOURCE-PORT wan0     REMOTE DEVICE main-sw                                  REMOTE PORT GigabitEthernet1/0/3     REMOTE IP 10.10.10.254
CDP  LOCAL Q2QN-9J8L-SLPD           SOURCE-PORT port10   REMOTE DEVICE 881544dff3af                             REMOTE PORT Port 8                   REMOTE IP 10.182.255.47
LLDP LOCAL Q2QN-9J8L-SLPD           SOURCE-PORT port10   REMOTE DEVICE Meraki MS220-8P - DevNet Always On Read  REMOTE PORT 8                        REMOTE IP 10.182.255.47
LLDP LOCAL Q2MD-BHHS-5FDL           SOURCE-PORT wired0   REMOTE DEVICE Meraki MS220-8P - MS220-8P-BE67          REMOTE PORT 2                        REMOTE IP 192.168.128.19
CDP  LOCAL Q2MD-BHHS-5FDL           SOURCE-PORT wired0   REMOTE DEVICE e0553dd1be67                             REMOTE PORT Port 2                   REMOTE IP 192.168.128.19
LLDP LOCAL AP-U8Y2                  SOURCE-PORT wired0   REMOTE DEVICE Meraki MS220-8P - MS220-8P-BE67          REMOTE PORT 3                        REMOTE IP 192.168.128.19
CDP  LOCAL AP-U8Y2                  SOURCE-PORT wired0   REMOTE DEVICE e0553dd1be67                             REMOTE PORT Port 3                   REMOTE IP 192.168.128.19

Wrap up

Leveraging API to create command line tools is a great use case in my opinion. CLI is still an effective way to interact with network devices. API can enable network engineers to build their own tools with a few lines of code.

GitHub

Meraki API

Meraki API changelog