Here's my own version of a bulk AP reboot script... Because Meraki steadfastly refuse to add any sort of bulk AP reboot facility to the dashboard (I've asked them on several occasions and they say they won't consider it, and that I "shouldn't need to reboot multiple AP's" without considering the use case where yes, you do actually want to do this and every other vendor providing a way) a couple of years ago I wrote a stand alone python script to do bulk AP reboots based on device tags, so that I can reboot either all AP's in the network, or AP's with a specific tag. As we have building name tags on our AP's to make it easier to group AP's based on building it makes it easy to reboot AP's in a certain building for example, and it would also be easy to add tags to AP's based on collections of AP's you might want to bulk reboot. The script originally used the v0 API but when I recently tried to use it I found it was broken due to changes in the API (such as tags going from a space separated list in a single string, to an array of tags) and python Meraki module changes so I've updated it to work with the current V1 API and current Meraki python module. #!/usr/bin/env python3
import json
import requests
import time
import meraki
import sys
import datetime
def reboot_ap(apikey, networkid, serial, suppressprint=False):
base_url = 'https://api.meraki.com/api/v1'
calltype = 'Device'
posturl = '{0}/networks/{1}/devices/{2}/reboot'.format(
str(base_url), str(networkid), str(serial))
headers = {
'x-cisco-meraki-api-key': format(str(apikey)),
'Content-Type': 'application/json'
}
postdata = {
'serial': format(str(serial))
}
dashboard = requests.post(posturl, data=json.dumps(postdata),
headers=headers)
print(dashboard.status_code, dashboard.text, calltype)
return
apikey = 'api_key_here'
network_id = 'network_id_here'
reboot_all = False
cmdline = False
if len(sys.argv) > 1:
cmdline = True
if sys.argv[1] == '--all':
reboot_tag = None
reboot_all = True
else:
reboot_tag = sys.argv[1]
dashboard = meraki.DashboardAPI(apikey, suppress_logging=True)
deviceList = dashboard.networks.getNetworkDevices(network_id)
tag_list = []
for device in deviceList:
new_tags = device['tags']
for tag in new_tags:
if not tag in tag_list:
tag_list.append(tag)
now = datetime.datetime.now()
print(now.strftime("%H:%M:%S %d-%m-%Y"))
print('Available Tags:\n')
for tag in tag_list:
print(tag)
if cmdline is False:
reboot_tag = input("\nEnter Tag of APs to reboot or press enter for all APs: ")
if not reboot_tag:
reboot_all = True
print('\nRebooting Devices:\n')
for device in deviceList:
if reboot_tag in device['tags'] or reboot_all:
try:
name = device['name']
except:
name = 'unknown'
print(name, device['serial'], device['lanIp'], device['tags'], '- ',end='')
reboot_ap(apikey, network_id, device['serial'])
time.sleep(0.5)
print() I'm pretty rusty with Python and this was a quick expedient script to get the job done in a hurry so I'm sure the Pythonistas in the audience will be rolling their eyes at the coding... 🙂 If you run the script without command line arguments it will scan all the devices in the wireless network gathering the tags from each device to build a list of all available network device tags, these tags are then displayed. You are then prompted to either press enter (which will reboot ALL AP's in the network, be careful.. press CTRL-C if you want to back out) or enter a tag name to reboot only those AP's with that tag. There is a 0.5 second delay between each reboot API call as if you call more than about every 0.2 seconds the API will reject the request. The success/failed result for each device will be displayed. If you use a single command line argument '--all' can be used to reboot all AP's without prompting (for example from a cron script) or you can use a tag name to reboot devices with that Tag without prompting. I use this script on Python 3.8 on Linux with the Meraki pip module installed. I don't think it relies on any other non-standard modules. While this version of the script hasn't been tested on Windows it should work as my original version did. Incidentally the Meraki Python module doesn't seem to have a reboot API call, nor does the official documentation list a reboot call, hence why the actual reboot action is hand coded as an HTML query using the requests library - I simply took one of the other example requests, changed the action to reboot and it worked! 🙂 Hope someone finds this useful.
... View more