Created
May 16, 2022 00:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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