cancel
Showing results for 
Search instead for 
Did you mean: 

API - LLDP / CDP for every port for every device

SOLVED
Highlighted
Getting noticed

API - LLDP / CDP for every port for every device

Hi there , 

 

I'm currently trying to something to get every switch port configuration and every LLDP / CDP device on every switch port.

 

The issue I'm looking at , is that I have to do a call for every device we have. 

 

ex: 

GET /networks/[networkId]/devices/[serial]/lldp_cdp

and : 

GET /devices/[serial]/switchPorts

 

I have to identify every single AP that is misconfigured ( like an AP seen on access port. 

 

We have over 2500 device so I really need to script that. 

 

Anyone done something similar ? 

 

Thanks a lot.

1 ACCEPTED SOLUTION

Accepted Solutions
Kind of a big deal

Re: API - LLDP / CDP for every port for every device

Not unless you're using multithreading or some other concurrent processing method. Meraki API calls take 2-5 seconds to return usually. One script running sequentially will never be able to exceed the 5calls/second limit. 

6 REPLIES 6
Kind of a big deal

Re: API - LLDP / CDP for every port for every device

I would probably attack this using the Org Inventory call, and then iterate though those results to get LLDP/CDP and switchport info for every device whose model starts with MS

 

So something like this in pseudocode:

 

devices = get /organizations/[id]/inventory

for dev in devices
    if dev[model] starts with "MS"
        cdp-lldp = get /networks/dev[networkId]/devices/dev[serial]/lldp_cdp
        lastport = dev[model[6:] #slice the model number to get number of ports
        for portnumber in range(0 to lastport)
            switchport[portnumber] = get /devices/[serial]/switchPorts/[portnumber]

print cdp-lldp
print switchport

 

A model citizen

Re: API - LLDP / CDP for every port for every device

I've been working on an easy way to pull CDP info, esp since the API seems like the only way to get it out of an MX. My goal was to be able to pick an org, pull its network list, then granularly work network->device category->device (or whole hog) to get specific info. 

 

I'm doing this in Python. I convert the dictionaries into objects using classes, because I find it easier than trying to dig into some of the weirdly formatted JSON.
 
I don't have anything that's not weirdly broken to share, unfortunately.
 
Final product is a CSV or xlsx containing:
 
Org name (if multiple orgs), network name, device name, all switchports (in your use case), all results of CDP/LLDP
 
Pseudocode:    
Pull org list
 
for org in orgList:
    get networkList from org
 
        for network in networkList:
            get deviceList from network
 
                for device in DeviceList:
                    if the first two letters in the device.name == MS:
                        get switchports
                        get CDP/LLDP information for that device
                        do some magic to ensure switchports are correlated to CDP/LLDP info
                        output switchports and CDP/LLDP info into a CSV or Excel spreadsheet
 
If all of your APs are Meraki APs, you could instead check device.name == MR, then get CDP/LLDP info off the AP itself.
Getting noticed

Re: API - LLDP / CDP for every port for every device

Thanks for the pseudo code. I'm almost done , but I have one last concern. 

 

Since I will have to retrieve info from over 2500 devices , it looks like I'm going to be bottlenecked by the 5 calls / sec limit , ain't that right ?

 

 

 

- Raphael

Kind of a big deal

Re: API - LLDP / CDP for every port for every device

Not unless you're using multithreading or some other concurrent processing method. Meraki API calls take 2-5 seconds to return usually. One script running sequentially will never be able to exceed the 5calls/second limit. 

Kind of a big deal

Re: API - LLDP / CDP for every port for every device


Since I will have to retrieve info from over 2500 devices , it looks like I'm going to be bottlenecked by the 5 calls / sec limit , ain't that right ?


Correct.  But even if you only do 1 device a second you'll be done in an hour - so no big deal.  Even if it takes 8 hours you can just leave it running over night and you'll have your answers in the morning when you come into work.

Getting noticed

Re: API - LLDP / CDP for every port for every device

So I'm done with my script ! I can now identify any device via LLDP that as AP in it's name and identify if it's port is either in access or trunk. If it is in access , it is flagged as misconfigured.

 

If you guys need it I can share my code ( only have to adapt your key ,orgID,  and the output messages ( currently in french ) 

 

 

Last question :  I'm looking for the equivalent of : 

GET /devices/[serial]/switchPorts

but for MX ( not MS ). I don't see anything. I would like to be able to identify misused ports on MX. 

 

Going to make a wish if this feature is not already there.

 

Thanks a lot 

Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.