Find Unused Ports And Shut them Down

Solved
AhmedJawad
Getting noticed

Find Unused Ports And Shut them Down

Hi All, 

 

  Thank you in advance for your help. Is there any API to list the org or network wired ports and filter unused ports, then shut them down? 

 

 

1 Accepted Solution
WellyHartanto
Getting noticed

If you want to check for switch ports which usage is zero for the last 31 days:
 
dashboard = meraki.DashboardAPI('your_api_key', suppress_logging=True)
devices = dashboard.organizations.getOrganizationDevices('your_org_id', total_pages='all')
for device in devices:
    if device['productType'] == 'switch':
        port_statuses = dashboard.switch.getDeviceSwitchPortsStatuses(device['serial'], timespan=(31*24*60*60))
        for port_status in port_statuses:
            port_id = port_status['portId']
            total_usage_kb = port_status['usageInKb']['total']

            if total_usage_kb == 0:
                dashboard.switch.updateDeviceSwitchPort(serial, port_id,enabled=False)

View solution in original post

10 Replies 10
rhbirkelund
Kind of a big deal
Kind of a big deal

Unfortunately, there is no single API call, which will do all of that. You'll have to write a script, that will implement several different API calls, that will filter ports that are unused, and disable them.

LinkedIn ::: https://blog.rhbirkelund.dk/

Like what you see? - Give a Kudo ## Did it answer your question? - Mark it as a Solution 🙂

All code examples are provided as is. Responsibility for Code execution lies solely your own.
WellyHartanto
Getting noticed

@AhmedJawad It would help if you defined what is "unused ports" for you.

 

Try to get the information on port usage (https://developer.cisco.com/meraki/api/get-device-switch-ports-statuses) for a defined timespan (max 31 days) then disable the ports which match your criteria (https://developer.cisco.com/meraki/api/update-device-switch-port

AhmedJawad
Getting noticed

If I'm using python SDK below , I just like to use SDK. 

 

how do i pass the time 30 days for example to the SDK below , see the Status line in the end there Serial, how do I pass time? 

 

Devices = dashboard.organizations.getOrganizationDevices(org_id, total_pages='all')

for Device in Devices:
    if Device['productType'] == 'switch':
        Serial = Device['serial']
        Status = dashboard.switch.getDeviceSwitchPortsStatuses(Serial)
        print(Status)
    break
WellyHartanto
Getting noticed

If you want to check for switch ports which usage is zero for the last 31 days:
 
dashboard = meraki.DashboardAPI('your_api_key', suppress_logging=True)
devices = dashboard.organizations.getOrganizationDevices('your_org_id', total_pages='all')
for device in devices:
    if device['productType'] == 'switch':
        port_statuses = dashboard.switch.getDeviceSwitchPortsStatuses(device['serial'], timespan=(31*24*60*60))
        for port_status in port_statuses:
            port_id = port_status['portId']
            total_usage_kb = port_status['usageInKb']['total']

            if total_usage_kb == 0:
                dashboard.switch.updateDeviceSwitchPort(serial, port_id,enabled=False)
Capt_Caaaveman
Getting noticed

I was able to get this to work!! 

If you check in the change log of the switch it shows the values changed

 

I did have to change the last line

 

I have "dashboard.switch.updateDeviceSwitchPort(device['serial'], port_id,enabled=False)"

WellyHartanto
Getting noticed

Yes, you are correct.

I was copy-pasting a fragment of my own script where 'serial' is a variable somewhere on my code to do other things.

I just tried to explain the logic and which API calls should be made.

In the end, your approach may vary to suit your own needs.

Capt_Caaaveman
Getting noticed

I appreciate you taking the time to post these.  Using real world meraki examples is helping me understand python a little. 

 

I wanted to share with anyone who is also new that this works and how I verified it worked.

 

Having time to sit, read, test and digest what I am doing is most of the time, far and few between. I have some time now in between projects so I'm trying to make as much progress as I can, while supporting all the IT services I need to.

BlakeRichardson
Kind of a big deal
Kind of a big deal

What happens when a client device is shutdown overnight and it's powered on the next morning? Wouldn't this create more work than good? 

If you found this post helpful, please give it Kudos. If my answer solves your problem, please click Accept as Solution so others can benefit from it.
DarrenOC
Kind of a big deal
Kind of a big deal

When auditing I look for ports that have been down for a period of time I.e longer than a month.  These are then shut and placed into a non routable VLAN

Darren OConnor | doconnor@resalire.co.uk
https://www.linkedin.com/in/darrenoconnor/

I'm not an employee of Cisco/Meraki. My posts are based on Meraki best practice and what has worked for me in the field.
AhmedJawad
Getting noticed

I guess we can check when the last time the port had a client on it was. 

Get notified when there are additional replies to this discussion.