Created
January 31, 2022 06:55
-
-
Save yujiterada/6789ccc1071a0f5840b668e06d16e901 to your computer and use it in GitHub Desktop.
Reboot Meraki MX
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 = 734417 | |
| NETWORK_TO_EXCLUDE = ['L_669347494617946220', 'L_669347494617948186', 'L_726205439913494157', 'L_726205439913494190', 'N_726205439913505421'] | |
| 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) | |
| # Iterate through the networks and check if MX exists in network | |
| for network in networks: | |
| network_id = network['id'] | |
| # If the network ID is not in the list to exclude | |
| if network_id not in NETWORK_TO_EXCLUDE: | |
| # If the network includes an MX, obtain all devices in the network | |
| if "appliance" in network['productTypes']: | |
| meraki_devices = dashboard.networks.getNetworkDevices(networkId=network_id) | |
| # Iterate through the devices in the network and obtain the serial number of the MX | |
| for device in meraki_devices: | |
| # Obtain MX serial number and reboot | |
| if "MX" in device['model']: | |
| mx_serial_num = device['serial'] | |
| result = dashboard.devices.rebootDevice(mx_serial_num) | |
| if result: | |
| print('{} reboot success'.format(mx_serial_num)) | |
| else: | |
| print('{} reboot fail'.format(mx_serial_num)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment