- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Unused ports disable script - Stacked ports show as disabled. But still have connectivity.
I was able to get this script running in a test network I have set up.
BUT...
It disabled the stack ports even if they are connected. Now I don't lose the stack, but in the switch port view I have added the column "enabled" from the status section and the stacked ports are listed as disabled, and I verified on a Production network that they are enabled in this view.
I've rebooted the stack but they stay "disabled"
To fix this I've had to run the script again and change the last line to "True"
How can I exclude the stack ports?
They look like ports 25, 26 (MS390-24P)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You would need to add a condition to check if the port number is in the list of stack ports before disabling it.
Good luck with your studies.
Please, if this post was useful, leave your kudos and mark it as solved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This has much more to do with programming than with Meraki itself, an example of logic with the condition would be this.
# List of stack ports stack_ports = [25, 26] # Your code for fetching the ports # ... for port in ports: # Check if the port is not in the stack ports if port not in stack_ports: # Your code for disabling the port
Please, if this post was useful, leave your kudos and mark it as solved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What I would do personally is use a tag on the port to exclude them, personal preference I find tags a bit cleaner, more portable and they help me remember what automations are running or not running on a port/device/network.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How do you put tags on your stack ports? I can only add a name?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just like how your script can enable and disable them despite that not being in the dashboard, you can tag them with the API.
On an MS410, the stack ports are 19 and 20 so....
>>> dashboard.switch.updateDeviceSwitchPort('Q***-****-****',20,tags=['no_auto_shut'])
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can go the 'hard way' by creating an exclusion table
excluded_ports_db = {
'MS225-24P': ['29', '30'],
'MS225-48LP': ['53', '54']
# The list goes on based on what you have
}
dashboard = meraki.DashboardAPI(getApiKey(), suppress_logging=True)
devices = dashboard.organizations.getOrganizationDevices(ORG_ID, total_pages='all')
for device in devices:
model = device['model']
if model in excluded_ports_db:
port_statuses = dashboard.switch.getDeviceSwitchPortsStatuses(device['serial'], timespan=(31*24*60*60))
for port_status in port_statuses:
port_id = port_status['portId']
if port_id not in excluded_ports_db[model]:
total_usage_kb = port_status['usageInKb']['total']
if total_usage_kb == 0:
dashboard.switch.updateDeviceSwitchPort(device['serial'], port_id,enabled=False)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you.
I had assistance with the below to work with. But I like yours better!
Was looking to eliminate the Modular ports and then remove the last two ports from the list (which are the stacked ports) then get the rest of the ports to work with.
# Create an empty placeholder for only the intended ports. Exclude things like MOD ports.
target_ports = []
# Loop over the ports and add only the intended ports to the target port list.
for port_status in port_statuses:
# Check if '-MOD-' exists in the portId value string. If it does, skip it.
if '-MOD-' not in port_status['portId']:
# Add only values that do not contain -MOD- to the target ports
target_ports.append(port_status)
# Sanity check, print the number of ports to make sure this is as expected
print('Ports: {}'.format(len(target_ports)))
# Extract the last 2 ports from the list of target ports
last_two = target_ports[-2:]
# Extract all except for the last 2 ports from the list of target ports
primary_ports = target_ports[:-2]
