!!UPDATE!! I got it to work. I added an if statement to replace empty cells with None def read_csv_to_dict_list(filename):
data = []
with open(filename, 'r') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['Port_voiceVlan'] == '':
row['Port_voiceVlan'] = None
data.append(row)
return data
... View more
I figured it out, kinda I had the dict keys swapped with the update switch API requirements response = dashboard.switch.updateDeviceSwitchPort( Serial, portId=row['Port_num'], name=row['Port_name'], type=row['Port_type'], vlan=row['Port_vlan'], ) I removed tags as it wants an array, and voiceVlan as it must be an integer or null
... View more
line 1 of the csv is Port,name,tags,type,vlan,voiceVlan **Edit** I updated the csv. was getting confusing. If I print the dictionary keys.. dict_keys(['Port_num', 'Port_name', 'Port_tag', 'Port_type', 'Port_vlan', 'Port_voiceVlan'])
... View more
Thank you. I get an error line 41, in <module> serial, Port=row["portId"], ~~~^^^^^^^^^^ KeyError: 'portId' ** I changed the serial line. I have the SN as a variable already
... View more
I am trying to import a csv of switch port configs. I am able to print the csv from the below script def read_csv_to_dict_list(filename):
data = []
with open(filename, 'r') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
data.append(row)
return data
data = read_csv_to_dict_list("C:\\temp\\Sample Switch.csv")
# Access data
for row in data:
print(f"Port: {row['portId']}, Name: {row['name']}, Tags: {row['tags']}, Type: {row['type']}, Vlan: {row['vlan']}, VoiceVlan: {row['voiceVlan']}")" how do I use this with "updateDeviceSwitchPort"
... View more
Thank you. I should have lead off with, that I am looking at a python API for this task. I'm not sure if I want a bulk import like this. I was looking more for an read csv, and update ports, per single switch kinda API.
... View more
I have a project upcoming to replace our cisco 2960 switches with MS390's. I am looking to import the port configs from the 2960's to the 390's. I cant seem to find a recent import discussion or script to look at. I would like to do a switch at a time, as in target the SN/MAC of the 390 that I want to replicate the config to from a specific 2960 backup.
... View more
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]
... View more
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.
... View more
I was able to get this script running in a test network I have set up. https://community.meraki.com/t5/Developers-APIs/Find-Unused-Ports-And-Shut-them-Down/m-p/223886/high... 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)
... View more
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)"
... View more
Looks like "getOrganizationDevices" does not handle stacked switches. When I run it only returns the primary switch ports, and not the member switch ports.
... View more
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?
... View more
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?
... View more
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
... View more
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''
... View more
Thank you both. SOOOOO. To install the Meraki API on Thonny From the "Tools" menu select "Open system shell...". You should get a new terminal window stating the correct name of the pip command (usually pip or pip3). Then run "pip3 install -U meraki" Now on to look at the next set of errors
... View more
Thank you. I see in the Thonny info that "Target: This dialog lists all available packages, but allows upgrading and uninstalling only packages from" and points to C:\Users\username\AppData\Roaming\Python\Python310\site-packages the Meraki API and SDK are in that dir.
... View more
I am trying to use Thonny to edit/create python scripts to learn. I have Thonny installed, but I cant seem to import Meraki info. I have tried import meraki ModuleNotFoundError: No module named 'meraki' I have the Dashboard API library installed (1.42.0) via the GUI manage packages and searching for Metraki. do I need to install anything else?
... View more
//
//
LITHIUM.InformationBox({"updateFeedbackEvent":"LITHIUM:updateAjaxFeedback","componentSelector":"#informationbox_3c85e6c0f0a8df","feedbackSelector":".InfoMessage"});
LITHIUM.InformationBox({"updateFeedbackEvent":"LITHIUM:updateAjaxFeedback","componentSelector":"#informationbox_3c85e6c0f0a8df_0","feedbackSelector":".InfoMessage"});
LITHIUM.InformationBox({"updateFeedbackEvent":"LITHIUM:updateAjaxFeedback","componentSelector":"#informationbox_3c85e6c0f0a8df_1","feedbackSelector":".InfoMessage"});
LITHIUM.InformationBox({"updateFeedbackEvent":"LITHIUM:updateAjaxFeedback","componentSelector":"#informationbox_3c85e6c0f0a8df_2","feedbackSelector":".InfoMessage"});
LITHIUM.AutoComplete({"options":{"autosuggestionAvailableInstructionText":"Auto-suggestions available. Use Up and Down arrow keys to navigate.","triggerTextLength":4,"autocompleteInstructionsSelector":"#autocompleteInstructionsText_3c85e6be5455e7","updateInputOnSelect":true,"loadingText":"Searching...","emptyText":"No Matches","successText":"Results:","defaultText":"Enter a search word","autosuggestionUnavailableInstructionText":"No suggestions available","disabled":false,"footerContent":[{"scripts":"\n\n;(function($){LITHIUM.Link=function(params){var $doc=$(document);function handler(event){var $link=$(this);var token=$link.data('lia-action-token');if($link.data('lia-ajax')!==true&&token!==undefined){if(event.isPropagationStopped()===false&&event.isImmediatePropagationStopped()===false&&event.isDefaultPrevented()===false){event.stop();var $form=$('