cancel
Showing results for 
Search instead for 
Did you mean: 

Any efficient way to use meraki dashboard API call - meraki.meraki.getclients ?

Conversationalist

Any efficient way to use meraki dashboard API call - meraki.meraki.getclients ?

 

I am new to Meraki and Python APIs. I am trying to write a script to find the details of a client in my organization when I search with IP address. Below is my code:

 

from meraki import meraki

import login (API_KEY, ORG_ID) = (login.api_key, login.org_id) def find_client(client_ip, status): for device in status: serialnum = device['serial'] clientList = meraki.getclients(API_KEY,serialnum) for client in clientList: if client['ip'] == client_ip: network = find_network(device) return client, network def find_network(device) : for network in networks: if device['networkId'] == network['id']: return network status = meraki.get_device_statuses(API_KEY, ORG_ID) networks = meraki.getnetworklist(API_KEY, ORG_ID) client_ip = input('Enter client IP: ') client, network = find_client(client_ip, status)

I have a couple of questions

 

1) Is there any efficient way to do this because my current code takes so long to find the client as it checks clients in each network of my organization. (Note: In my organization, each device (Switch/Firewall/AP) is in separate network)

 

2) Furthermore, after each iteration it prints "Device Clients Operation Successful - See returned data for results" on the console/prompt. Is there a way to avoid printing this ?

7 REPLIES 7
Kind of a big deal

Re: Any efficient way to use meraki dashboard API call - meraki.meraki.getclients ?

Not sure about the first question... I'll have to think on that.

 

For #2 check the help:

 

image.png

Kind of a big deal

Re: Any efficient way to use meraki dashboard API call - meraki.meraki.getclients ?

I'm wondering if the python library rate limits the calls. I checked the source and upon first inspection it doesn't seem like it does that. Therefore I'm wondering if you're getting penalized for going over the max rate of 5 calls/s (per organization).

 

Regarding the calls themselves, I don't think there's any other more efficient way of getting to that data. Using the devices statusses call already saves you from going over each network and calling its devices one by one.

Kind of a big deal

Re: Any efficient way to use meraki dashboard API call - meraki.meraki.getclients ?

It is pretty much impossible to do more 5 calls/second using a single threaded python script.  Python is too much of a CPU sl*t to manage it.

 

 

I assuming all of your networks have unique IP subnets?  Why don't you create a static hash of subnet to network name so you can go directly to the correct network rather than having to scan every network.

Conversationalist

Re: Any efficient way to use meraki dashboard API call - meraki.meraki.getclients ?

Thank you all for your input.

 

Unfortunately, my networks don't have unique IP subnets to create a static hash of subnet to the network name.

 

I was thinking if I combine my devices (switch, firewall, and AP) under a single network for each office location, will it reduce the execution time? 

Because currently, a client connected to an AP is being tracked under the AP as well as its upstream switch and Firewall.  So, the method meraki.getclients will read that client 3 times during execution. Am I right?

Is there a way to find clients based on network ID rather than each device (serial)?

Kind of a big deal

Re: Any efficient way to use meraki dashboard API call - meraki.meraki.getclients ?

Yes networks would make your code faster.

 

You can find the general client functions here:

https://dashboard.meraki.com/api_docs#clients

Conversationalist

Re: Any efficient way to use meraki dashboard API call - meraki.meraki.getclients ?

Hi Philip,

 

I'm having some issues with get client calls and timespans myself.  

 

I'm accessing the Meraki API with a python (v3) script.  I've refered to the Meraki API documentation and source code found here: https://github.com/meraki/dashboard-api-python/blob/master/meraki.py

 

The particular call I'm using is found on line 1349 "def getclients(apikeyserialnumtimestamp=86400suppressprint=False):"

 

I want to see all the clients connected to a particular MX device over the last month.  It's the timespan piece that I don't understand.  For example:

 

networkClients = meraki.getclients(apikey, greeceNodes[node])

 

Here the networkClients is meant to be a returned list of clients and greeceNodes[node] is the serial number of an MX device in my Greek networks.   That said, I'm not sure where to put the timespan or how to format it, and the source code is not clear about it.  

 

on lines 1353 - 1355 of the source code, the timespan={2}:

 

geturl = '{0}/devices/{1}/clients?timespan={2}'.format(str(base_url),
 str(serialnum),
 str(timestamp))

 

 

I'm not sure what this timespan={2} means.

 

Any ideas on how to gather data from the monthly timespan?

Here to help

Re: Any efficient way to use meraki dashboard API call - meraki.meraki.getclients ?

meraki.getclients(apiKey, deviceId, timestamp=2592000, suppressprint=True)

 

This will return clients of a device up to a month ago.

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.