Switchport Status call

nvrdone
Here to help

Switchport Status call

So I am working on an API call to disable ports that have not sent/received traffic for the last 15days.  Got everything working correctly with my test environment, went to prod and noticed I'm pulling a lot of useless info.  So i figured out that the call works the way I think it should ONLY on single switches, if the switch is in the stack it pulls "fake" information.

 

First function is from my_meraki module that i use to store all functions.

 

Second is the actual call, I have the dangerous part commented out because currently if the switch is in a stack it will disable all ports as it pulls 0 for the usage.  If not in a stack works perfectly.  Not sure if this is an intended function or if i screwed something up or....  idk just at a loss.

 

# Get Switchport Status
def switchportstat(apikey, serial):
global json_swportstat
url = "https://api.meraki.com/api/v0/devices/"+serial+"/switchPortStatuses?timespan=1296000"
payload = {}
headers = {'X-Cisco-Meraki-API-Key': apikey,'Content-Type': "application/json",'cache-control': "no-cache"}
r = requests.get(url, headers=headers, data=payload)
json_swportstat = r.json()
#personal function list
import my_meraki

#Old meraki SDK from github
from meraki import meraki

current_devices = meraki.getnetworkdevices(API_KEY, netid, ORG_ID)
device_serial = [device['serial'] for device in current_devices]
device_model = [device['model'] for device in current_devices]
for serial, model in zip(device_serial, device_model):
if model in 'MS225-48FP':
my_meraki.switchportstat(API_KEY, serial)
for line in my_meraki.json_swportstat:
portid = line.get('portId')
strportid = str(portid)
portidlist = list(strportid)
portidcomb = [''.join(portidlist)]
usage = line.get('usageInKb')
total = usage.get('total')
strtotal = str(total)
totallist = list(strtotal)
totalcomb = [''.join(totallist)]
full = zip(portidcomb, totalcomb)
for port, use in full:
print(serial, port, use)
#if use is '0' and port not in ('49', '50', '51', '52', '53', '54'):
#print('disabling: ',port)

 

3 Replies 3
PhilipDAth
Kind of a big deal
Kind of a big deal

Are you running a recent firmware on your MS stack?

nvrdone
Here to help

Yep, 11.29

APOC
Conversationalist

Has there been any update to this. I am working on a similar project. Just kind if getting my feet wet in api and python

Get notified when there are additional replies to this discussion.