I’m a network admin working on a small project at work using Cisco’s Meraki API wrapper for Python
The end goal is to have a dashboard that displays the amount of authenticated users on a single access point during the set X timeframe. I’ve been using Pandas to format the json responses and try to work with them but I’m a bit stuck since I never worked with Json, APIs or Pandas.
Dataframe 1 is a list of all access points and their necessary information, looks roughly like this:
name - serial - mac - networkID - model - IP - last updated - Firmware
I then iterate over every serial number in the dataframe to grab the corresponding time data for the serial number
for serial in df['serial']:
times =[]
times.append(dashboard.wireless.getNetworkWirelessClientCountHistory(networkID,deviceSerial=serial,timespan=3600,resolution=300))
print(times)
The API Response will be a list with 11 elements each
{'startTs': '2024-12-12T11:05:00Z',
'endTs': '2024-12-12T11:10:00Z',
'clientCount': None}
Now I’m at a loss on how to proceed in formatting the data so I can plot it into a simple graph consisting of:
X = timestamp for example 11:05:00
Y = ClientCount for example None
I’m not sure what the easiest way would be, since each API response for the times would need to be matched to the correct Access point so I can display the data for each access point individually.
The dataframe for the times looks roughly like this (per access point)
startTs endTs clientCount
0 2024-12-12T10:10:00Z 2024-12-12T10:15:00Z None
1 2024-12-12T10:15:00Z 2024-12-12T10:20:00Z None
2 2024-12-12T10:20:00Z 2024-12-12T10:25:00Z None
3 2024-12-12T10:25:00Z 2024-12-12T10:30:00Z None
The overall code I have right now:
import meraki
import pandas as pd
from datetime import datetime
API_KEY = 'API_KEY_HERE'
dashboard = meraki.DashboardAPI(API_KEY)
org_id = 'ORG_ID_HERE'
Network_ID = 'MERAKI_NETWORK_ID_HERE'
client_id = ''
#get all devices
response = dashboard.organizations.getOrganizationDevices(
org_id, total_pages='all', networkIds= NETWORK_ID_HERE
)
#filter for APs
response = list(filter(lambda x: x['productType'] == "wireless",response))
df = pd.DataFrame(response)
#drop columns
df = df.drop(['details','url','tags','notes','lng','lat','address','productType'],axis=1)
for serial in df['serial']:
times = []
times.append(dashboard.wireless.getNetworkWirelessClientCountHistory(NETWORK_ID_HERE,deviceSerial=serial,timespan=3600,resolution=300))
Not sure how to fix the formatting on that last line but you get the general idea hopefully, I’ve been watching youtube videos on pandas as a library but I’m yet to figure out how I need to solve this. Any pointer is appreciated!
3