- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Python - Get list of switch ports from specific Network ID
Im trying to test getting info from my Org to learn building scripts.
I want to get the list of switch ports from a specific Network ID. I am able to pull the device ports if I use the switch's serial number:
response = dashboard.switch.getDeviceSwitchPorts(
serial
)
print(response)
https://developer.cisco.com/meraki/api-v1/get-device-switch-ports/
Im trying to expand upon this by getting the switch ports from a net ID
import meraki
API_KEY = 'c4............................................'
dashboard = meraki.DashboardAPI(API_KEY)
organization_id = 'XXXXXX'
# Get the list of networks in your organization
networks = dashboard.organizations.getOrganizationNetworks(
organization_id, total_pages='all'
)
# Find the network that you want
network_id = 'L_6................................'
# Get the list of switchports
switchports = dashboard.switch.getDeviceSwitchPorts(
network_id
)
# Print the list of switchports
for switchport in switchports:
print(switchport)
I get an error
ERROR > switch, getDeviceSwitchPorts - 404 Not Found, b''
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have you tried this API?
https://developer.cisco.com/meraki/api-v1/get-organization-switch-ports-statuses-by-switch/
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
Hi ,
https://developer.cisco.com/meraki/api/get-device-switch-ports/
/devices/{serial}/switch/ports
You can't input a Network ID , it requires a Serial number. You would be better using the Org-Wide call that alemabrahao has suggested and filter the json received or filter with the parameter networkids.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you both.
HMM. I was playing with this to add
# Filter the devices to only include switches
switches = []
for device in devices:
if device["model"].startswith("MS"):
switches.append(device)
# Print the list of switches
for switch in switches:
print(switch["serial"])
this gets me the serial of each switch.
Can I use this output in the operations you both have provided?
I assume I am going need to build an array or something
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So you want to get the list of switch ports by network ID?
API_KEY = 'xxxx'
ORG_ID = 123
NET_ID = L_123
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
WellyHartanto, Thank you.
Yes, I have about 50 networks that I manage. I want to be able to get the ports in each network so I can say, bounce all ports in a specific vlan. We have "homemade" PoE devices in certain vlans that need bounced every so often if they lose connectivity to a server.
I also want to look to disable unused ports after XX number of days.
I hope Im on the correct path to be able to accomplish those tasks?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes it can be done via API.
Take a look at the ouput when you make the API call for switch ports to determine the port VLAN.
For unused port, this thread may help: https://community.meraki.com/t5/Developers-APIs/Find-Unused-Ports-And-Shut-them-Down/m-p/223886/high...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
WellyHartanto,
question about the cycle ports script...
timespan=(31*24*60*60))
Is this 31 days, then 24 hrs in a day, 60 min in an hour, 60 sec in a minute?
so if you wanted a different # of days you just need to change the 31?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the timespan parameter is in seconds and a maximum of 31 days (you may want to read the documentation thoroughly)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Looks like "getOrganizationDevices" does not handle stacked switches. When I run it only returns the primary switch ports, and not the member switch ports.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Based on the documentation, I disagree.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HMM. ok. Ill have to take another look. thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I found it. the output splits the stacked switches, and put my 3rd switch which is standalone sandwiched in between.
Thank you again!
