Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save yujiterada/04239fac5c61d9c9f612c65263430727 to your computer and use it in GitHub Desktop.

Select an option

Save yujiterada/04239fac5c61d9c9f612c65263430727 to your computer and use it in GitHub Desktop.
Gets all Meraki Systems Manager Devices in Organization and creates a CSV file
import os
import meraki
MERAKI_API_KEY = os.environ.get('MERAKI_API_KEY', None)
MERAKI_ORG_ID = os.environ.get('MERAKI_ORGANIZATION_ID', None)
total = 0
if MERAKI_API_KEY:
# Initialize Meraki API Client
dashboard = meraki.DashboardAPI(api_key=MERAKI_API_KEY, suppress_logging=True, output_log=False)
# Obtain all networks in organization
networks = dashboard.organizations.getOrganizationNetworks(organizationId=MERAKI_ORG_ID)
# Create CSV file to write
f = open("test.csv",'w')
f.write('networkId, networkName, deviceId, deviceName, deviceWifiMac, deviceOsName, deviceSystemModel, deviceUuid, deviceSerialNumber\n')
# Iterate through the networks and obtain SM devices
for network in networks:
print('Working on {}'.format(network['name']))
devices = dashboard.sm.getNetworkSmDevices(networkId=network['id'])
print('Found {} devices'.format(len(devices)))
for device in devices:
# Write device information into CSV file
f.write('{}, {}, {}, {}, {}, {}, {}, {}, {}\n'
.format(network['id'], network['name'], device['id'], device['name'],
device['wifiMac'], device['osName'], device['systemModel'], device['uuid'], device['serialNumber']))
total += len(devices)
f.close()
print(total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment