Full working code import meraki
import os
import pandas as pd
from datetime import datetime
"""
Script to extract the last 30 days of packet loss and latency for a Meraki Gateway device (by serial) and save to a CSV
"""
# Get environment variables API Key
API_KEY = os.getenv('MERAKI_API_KEY')
dashboard = meraki.DashboardAPI(API_KEY, output_log=False, suppress_logging=True)
serial = 'XXXX-XXXX-XXXX' #Serial of the device we need to get the information for
ip = '8.8.8.8' #P being monitored by Meraki Dashboard
#Get data for last 31 days for wan1 with 60 seconds resolution
timespan = 2678400 #period (31 days in seconds) to get the information for. Max of 31 days.
#Get packet loss and latency history at 60 seconds resolution
device_loss_latency_history = dashboard.devices.getDeviceLossAndLatencyHistory(serial, ip, timespan=timespan, resolution=60, uplink="wan1")
#Uncomment below line to print the result to console.
#print(response_loss_latency_history)
current_time_str = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
filename = f"lost-latency-history-{serial}--{current_time_str}.csv"
#Convert to DataFrame
df_loss_latency_history = pd.DataFrame(device_loss_latency_history)
#Export it to a CSV
df_loss_latency_history.to_csv(filename, index=False, header=True)
print(f"Exported [{serial}] Packet Loss History ==> {filename}")
#Now we have a CSV file with the packet loss and latency info
... View more