<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Cycle Port in Network Platform API</title>
    <link>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421893#M3584</link>
    <description>&lt;P&gt;Posting update as I was looking for this API call.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developer.cisco.com/meraki/api/cycle-device-switch-ports/" target="_blank" rel="nofollow noopener noreferrer"&gt;https://developer.cisco.com/meraki/api/cycle-device-switch-ports/&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Nov 2023 20:25:37 GMT</pubDate>
    <dc:creator>Andy Mikulas</dc:creator>
    <dc:date>2023-11-21T20:25:37Z</dc:date>
    <item>
      <title>Cycle Port</title>
      <link>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421884#M3575</link>
      <description>&lt;P&gt;We are having an issue with a PoE device that only seems to crop up every few days. It appears that the devices have an inherent problem that the vendor needs to fix with a firmware update. In the meantime, the workaround is to go into the switch and click the "cycle port" button. I'll end up writing a python script that will loop through the switches in my organization and cycle to ports that have a tag for the problem devices. Is there a way to cycle a port through the API?&lt;/P&gt;&lt;P&gt;I know I could disable and enable the port using: &lt;/P&gt;&lt;PRE&gt;meraki.updateswitchport(apikey, serialnum, portnum, name=None, tags=None, enabled=False, &lt;BR /&gt;    porttype=None, vlan=None,voicevlan=None, allowedvlans=None, poe=None, isolation=None,&lt;BR /&gt;    rstp=None,   stpguard=None, accesspolicynum=None, suppressprint=False)

meraki.updateswitchport(apikey, serialnum, portnum, name=None, tags=None, enabled=True, &lt;BR /&gt;    porttype=None, vlan=None,voicevlan=None, allowedvlans=None, poe=None, isolation=None,&lt;BR /&gt;    rstp=None,   stpguard=None, accesspolicynum=None, suppressprint=False)&lt;/PRE&gt;&lt;P&gt;However, this sends alerts of changes to the switch ports whereas the "cycle port" button doesn't send any alerts. I'd like to cut down on the spam if possible as I would end up with alerts from all of our networks every morning.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 15:46:39 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421884#M3575</guid>
      <dc:creator>Jason-907</dc:creator>
      <dc:date>2019-09-11T15:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle Port</title>
      <link>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421885#M3576</link>
      <description>I've never been able to find an API that has cycle port option. I looked for it because I wanted to use it to reboot access points (which I ended up doing a separate python script/API call for which is the reboot API call).&lt;BR /&gt;&lt;BR /&gt;So as of right now, there isn't an option for API to cycle port. Hopefully in the future they'll provide that.</description>
      <pubDate>Wed, 11 Sep 2019 17:59:45 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421885#M3576</guid>
      <dc:creator>Nolan H.</dc:creator>
      <dc:date>2019-09-11T17:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle Port</title>
      <link>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421886#M3577</link>
      <description>&lt;P&gt;If this is a Meraki Switch (MS) then configure a port schedule instead.&lt;/P&gt;&lt;P&gt;&lt;A href="https://documentation.meraki.com/MS/Access_Control/Port_Schedules" target="_self" rel="nofollow noopener noreferrer"&gt;https://documentation.meraki.com/MS/Access_Control/Port_Schedules&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 21:02:30 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421886#M3577</guid>
      <dc:creator>Philip D'Ath</dc:creator>
      <dc:date>2019-09-11T21:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle Port</title>
      <link>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421887#M3578</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;A href="https://community.meraki.com/t5/user/viewprofilepage/user-id/340"&gt;@Philip D'Ath&lt;/A&gt; wrote:&lt;BR /&gt;&lt;P&gt;If this is a Meraki Switch (MS) then configure a port schedule instead.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I'll take a look at it, but I want it go off and back on immediately. It seems like this method would require the port to be down for 1/2 an hour at a minimum.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 11 Sep 2019 21:13:25 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421887#M3578</guid>
      <dc:creator>Jason-907</dc:creator>
      <dc:date>2019-09-11T21:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle Port</title>
      <link>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421888#M3579</link>
      <description>&lt;P&gt;&amp;gt;&lt;SPAN&gt; It seems like this method would require the port to be down for 1/2 an hour at a minimum.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Correct.  You can't do it at a horrible time of the day like 2am?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 21:20:32 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421888#M3579</guid>
      <dc:creator>Philip D'Ath</dc:creator>
      <dc:date>2019-09-11T21:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle Port</title>
      <link>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421889#M3580</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;A href="https://community.meraki.com/t5/user/viewprofilepage/user-id/340"&gt;@Philip D'Ath&lt;/A&gt; wrote:&lt;BR /&gt;&lt;P&gt;&amp;gt;&lt;SPAN&gt; It seems like this method would require the port to be down for 1/2 an hour at a minimum.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Correct.  You can't do it at a horrible time of the day like 2am?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;No--Security cameras. What's happening is if we use the most efficient format, the cameras will lose communication with the server and ends up buffering everything until the server or camera reboots. Our camera guy just does it manually, but he was hoping we could automate. I'll test it out and just deal with the spam.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 21:38:20 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421889#M3580</guid>
      <dc:creator>Jason-907</dc:creator>
      <dc:date>2019-09-11T21:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle Port</title>
      <link>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421890#M3581</link>
      <description>&lt;P&gt;Since the API endpoint doesn't seem to exist, have you tried adapting your script to:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Disable the email alert that is triggered by the port status change&lt;/LI&gt;&lt;LI&gt;Disable the port&lt;/LI&gt;&lt;LI&gt;Enable the port&lt;/LI&gt;&lt;LI&gt;Enable the email alert again&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Of course you'll need to get the network ID for each switch but that shouldn't be a big problem.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2019 08:19:31 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421890#M3581</guid>
      <dc:creator>raphael.meyer@kering.com</dc:creator>
      <dc:date>2019-09-12T08:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle Port</title>
      <link>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421891#M3582</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;A href="https://community.meraki.com/t5/user/viewprofilepage/user-id/24879"&gt;@raphael.meyer@kering.com&lt;/A&gt; wrote:&lt;BR /&gt;&lt;P&gt;Since the API endpoint doesn't seem to exist, have you tried adapting your script to:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Disable the email alert that is triggered by the port status change&lt;/LI&gt;&lt;LI&gt;Disable the port&lt;/LI&gt;&lt;LI&gt;Enable the port&lt;/LI&gt;&lt;LI&gt;Enable the email alert again&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Of course you'll need to get the network ID for each switch but that shouldn't be a big problem.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That is a clever solution, but the alerts are set for configuration changes, not port status changes, so this wouldn't actually solve this one for me.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2019 17:56:32 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421891#M3582</guid>
      <dc:creator>Jason-907</dc:creator>
      <dc:date>2019-09-12T17:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle Port</title>
      <link>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421892#M3583</link>
      <description>&lt;P&gt;I wanted to add to this since I really needed a solution and I had to make my own.&lt;/P&gt;&lt;P&gt;For this script you need two text files: device_serials.txt and tag.txt  in the same directory as your python script.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;EM&gt;device_serials&lt;/EM&gt; has device serial numbers per line&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;tag&lt;/EM&gt; has the tag of the switch port&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;How it works:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;It scans the device serials matching those in the &lt;EM&gt;device_serials.txt &lt;/EM&gt;file.&lt;/LI&gt;&lt;LI&gt;All the ports in that switch that have the tag written in the &lt;EM&gt;tag.txt&lt;/EM&gt; file will be cycled. &lt;/LI&gt;&lt;LI&gt;I made it it like this so that I could target specific ports on a switch.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Here's my script, which is based on Meraki tagging.&lt;/P&gt;&lt;P&gt;With a little Python know-how, this is easy to modify this based on device properties:&lt;/P&gt;&lt;PRE class="lia-code-sample language-python"&gt;&lt;CODE&gt;#By Josh Carbajal

import meraki
import requests
import json
from datetime import datetime

#DECLARATIONS
API_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
dashboard = meraki.DashboardAPI(API_KEY)
payload = None
headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "X-Cisco-Meraki-API-Key": API_KEY
}
dt = datetime.now().strftime("%Y_%m_%d-%I.%M.%S.%p")
divider = "\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"

#FUNCTIONS
def getresponse(serialnumber):
    url = "https://api.meraki.com/api/v1/devices/{}/switch/ports".format(serialnumber)
    response = requests.request('GET', url, headers=headers, data = payload)
    refined = json.loads(response.text)
    if 'errors' in refined:
        print("Could not establish a good API handshake with device serial ({})".format(serialnumber))
        logFile.write("\nCould not establish a good API handshake with device serial ({}).\n".format(serialnumber))
        logFile.write(divider)
    else:
        switch = dashboard.devices.getDevice(serial)
        name = switch['name']
        logFile.write("\nDevice {}, with serial {} found.".format(name, serialnumber))
        findRebootTag(refined, serialnumber)

def findRebootTag(goodresponse, serialnumber):
    ports = []
    for device in goodresponse:
        if tag in device['tags']:
            print(device)
            ports.append(str(device['portId']))
        else:
            pass
    print(ports)
    logFile.write("\nDevice serial: {}.\tPorts tagged with {}: {}".format(serialnumber, tag, ports))
    cycle(ports, serialnumber)

def cycle(ports, serialnumber):
    if ports:
        for port_number in ports:
            print("Port number: " + port_number)
        #cycleAll = dashboard.switch.cycleDeviceSwitchPorts(serialnumber, ports)
        logFile.write("\nCycling ports {} for device serial {}.\n".format(ports, serialnumber))
        logFile.write(divider)
    else:
        print("No ports tagged with {} found for device serial ({})".format(tag, serialnumber))
        logFile.write("\nNo ports tagged with {} found for device serial ({}).\n".format(tag, serialnumber))
        logFile.write(divider)

#MAIN RUN
tagFile = open("tag.txt", "r")
tag = tagFile.read()
tagFile.close()
logFile = open("{}.txt".format(dt), "w")
logFile.write("Log: Meraki API via Python custom script\n")
with open("device_serials.txt") as txtfile:
    serialtxt = txtfile.read().splitlines()
    for serial in serialtxt:
        if serial:
            getresponse(serial)
        else:
            pass
    logFile.close()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As you can see, it creates a log named with a datetime stamp. If you want to automate this kind of stuff, use Task Scheduler, for example, and run the python script with a batch file. &lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 19:00:45 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421892#M3583</guid>
      <dc:creator>plainjosh</dc:creator>
      <dc:date>2021-07-30T19:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle Port</title>
      <link>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421893#M3584</link>
      <description>&lt;P&gt;Posting update as I was looking for this API call.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developer.cisco.com/meraki/api/cycle-device-switch-ports/" target="_blank" rel="nofollow noopener noreferrer"&gt;https://developer.cisco.com/meraki/api/cycle-device-switch-ports/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2023 20:25:37 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/cycle-port/m-p/5421893#M3584</guid>
      <dc:creator>Andy Mikulas</dc:creator>
      <dc:date>2023-11-21T20:25:37Z</dc:date>
    </item>
  </channel>
</rss>

