I understand that sometimes intentions get lost in translation in online written media. But my intention was indeed to help, not to sound like a pedantic d*. The reason I want to understand why the reboot is needed is to see if there is another possible solution that may be better.
Now that you've explained why the reboot is needed we can try to understand better. You say the problem lies with the cellular connection. Does that mean a USB modem that is in the MX's USB port? If it is then I can understand a reboot of the MX may help as the modem will then reboot with the MX. If not, I'm not sure if it's going to do much. Same goes for the access points.
I've started writing a script for you using the new Python SDK. It goes as follows:
from meraki.meraki import Meraki
# user API key
x_cisco_meraki_api_key = 'enter_your_API_key_here'
try:
client = Meraki(x_cisco_meraki_api_key)
# get a list of organizations the user has access to
orgs = client.organizations.get_organizations()
# prepare the orgcollect to be used in the get_organization_networks call
orgcollect = {}
for org in orgs:
# only interested in a specific organization
if org['id'] == 1234567: # your organization's ID
orgcollect['organization_id'] = org['id']
# fetch all networks in the organization(s)
if orgcollect: # make sure it's not an empty collection
networks = client.networks.get_organization_networks(orgcollect)
# loop over the networks
if networks: # make sure it's not an empty organization
for network in networks:
# create a devicescontroller to fetch devices
devicescontroller = client.devices
# fetch a list of devices in the specified network
devices = devicescontroller.get_network_devices(network['id'])
# prepare the devicescollection to reboot them
devicescollect = {}
for device in devices:
# only interested in MX devices
if 'MX' in device['model']:
devicescollect['serial'] = device['serial']
devicescollect['network_id'] = network['id']
# reboot the device
if devicescollect: # make sure there are devices to reboot
result = devicescontroller.reboot_network_device(devicescollect)
if result['success']:
print("The device with the name ", device['name'], "(", device['model'],
") in the network ", network['name'], " was successfully rebooted.")
else:
print("ERROR: The device with the name ", device['name'], "(", device['model'],
") in the network ", network['name'], " could not be rebooted.")
else:
print("Empty Organization")
else:
print("No organizations selected")
except:
print("Exception occurred, possibly and invalid API key.")
I have tested the script, but not thoroughly so all use is at your own risk.
A couple of things you should know about the script:
- I assume only the MX's need to be rebooted, so I filter on the model number containing MX
- I assume all devices that need the reboot are in a single organization, you need to fill in its ID in the code
- Make sure the computer you execute the script from is not behind one of the MX's that's getting a reboot or that will cause issues.
- More info about the Python SDK and how to install it here: https://developer.cisco.com/meraki/api/#/python/getting-started/what-can-the-api-be-used-for
Hope that helps.