<?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 Issue with Meraki Python Script -Air Marshall in Network Platform API</title>
    <link>https://community.cisco.com/t5/network-platform-api/issue-with-meraki-python-script-air-marshall/m-p/5431842#M5157</link>
    <description>&lt;P&gt;I have the script below, use to work, stopped working I've been banging my head on it trying to figure it out or is there a different /better way to get this info. Any help you could be would be much appreciated.&lt;/P&gt;&lt;P&gt;import meraki&lt;BR /&gt;import json&lt;BR /&gt;import requests&lt;BR /&gt;import time&lt;BR /&gt;import smtplib&lt;BR /&gt;from email.mime.multipart import MIMEMultipart&lt;BR /&gt;from email.mime.base import MIMEBase&lt;BR /&gt;from email import encoders&lt;BR /&gt;from datetime import datetime, timezone&lt;/P&gt;&lt;P&gt;#Put your API key here&lt;BR /&gt;apikey =&lt;BR /&gt;orgid =&lt;/P&gt;&lt;P&gt;def getNetworks(apikey):&lt;BR /&gt;url = "&lt;A href="https://api.meraki.com/api/v0/organizations/11111/networks" target="_blank" rel="noopener nofollow noreferrer"&gt;https://api.meraki.com/api/v0/organizations/11111/networks&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;payload = ""&lt;BR /&gt;headers = {&lt;BR /&gt;'X-Cisco-Meraki-API-Key': apikey,&lt;BR /&gt;'cache-control': "no-cache",&lt;BR /&gt;'Postman-Token': ""&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;response = requests.request("GET", url, data=payload, headers=headers)&lt;/P&gt;&lt;P&gt;return response&lt;BR /&gt;&lt;BR /&gt;def getMarshall(network, apikey):&lt;BR /&gt;url = "&lt;A href="https://api.meraki.com/api/v0/networks/" target="_blank" rel="noopener nofollow noreferrer"&gt;https://api.meraki.com/api/v0/networks/&lt;/A&gt;" + network + "/airMarshal"&lt;/P&gt;&lt;P&gt;querystring = {"timespan":"3600"}&lt;/P&gt;&lt;P&gt;payload = ""&lt;BR /&gt;headers = {&lt;BR /&gt;'X-Cisco-Meraki-API-Key': apikey,&lt;BR /&gt;'cache-control': "no-cache",&lt;BR /&gt;'Postman-Token': ""&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;response = requests.request("GET", url, data=payload, headers=headers, params=querystring)&lt;/P&gt;&lt;P&gt;return response&lt;/P&gt;&lt;P&gt;def mail():&lt;BR /&gt;time = datetime.now().strftime("%m%d%y")&lt;BR /&gt;filename = "airmarshallReport_" + time + ".csv"&lt;BR /&gt;subject = "Meraki Airmarshall Report"&lt;BR /&gt;recipients = ["test@test.com"]&lt;BR /&gt;&lt;BR /&gt;msg = MIMEMultipart()&lt;BR /&gt;msg["Subject"] = subject&lt;BR /&gt;msg["From"] = "airmarshall@test.com"&lt;BR /&gt;msg["To"] = ", ".join(recipients)&lt;BR /&gt;&lt;BR /&gt;part = MIMEBase("application", "octet-stream")&lt;BR /&gt;part.set_payload(open(filename, "rb").read())&lt;BR /&gt;encoders.encode_base64(part)&lt;BR /&gt;&lt;BR /&gt;part.add_header("Content-Disposition", "attachment; filename=\"" + filename + "\"")&lt;BR /&gt;&lt;BR /&gt;msg.attach(part)&lt;BR /&gt;&lt;BR /&gt;server = smtplib.SMTP("mail.test.com")&lt;BR /&gt;server.sendmail("airmarshall@test.com", recipients, msg.as_string())&lt;/P&gt;&lt;P&gt;response = getNetworks(apikey)&lt;BR /&gt;networks = response.json()&lt;BR /&gt;index1 = 0&lt;BR /&gt;index2 = 0&lt;BR /&gt;time = datetime.now().strftime("%m%d%y")&lt;/P&gt;&lt;P&gt;with open("airmarshallReport_" + time + ".csv", "w+") as f:&lt;BR /&gt;f.write("network,ssid,bssid,contained,devices,channels,firstseen,lastseen,wiredmacs,wiredlastseen\n")&lt;BR /&gt;for line in networks:&lt;BR /&gt;try:&lt;BR /&gt;x = getMarshall(networks[index1]["id"],apikey)&lt;BR /&gt;y = x.json()&lt;BR /&gt;index = 0&lt;BR /&gt;for i in y:&lt;BR /&gt;f.write('"' + str(networks[index1]["name"]) + '"' + "," + '"' + str(y[index]["ssid"]) + '"' + "," + '"' + str(y[index]["bssids"][0]["bssid"]) + '"' + "," + '"' + str(y[index]["bssids"][0]["contained"]) + '"' + ",")&lt;BR /&gt;try:&lt;BR /&gt;for i in y[index]["bssids"][0]["detectedBy"]:&lt;BR /&gt;f.write('"' + str(i["device"]) + " RSSI - " + str(i["rssi"]) + " ")&lt;BR /&gt;index2 += 1&lt;BR /&gt;f.write('"' + ",")&lt;BR /&gt;except:&lt;BR /&gt;f.write('"' + "none\"," )&lt;BR /&gt;try:&lt;BR /&gt;f.write('"' + str(y[index]["channels"][0]) + '"' + ",")&lt;BR /&gt;except:&lt;BR /&gt;f.write('"' + "none\",")&lt;BR /&gt;try:&lt;BR /&gt;f.write('"' + str(datetime.fromtimestamp(int(y[index]["firstSeen"]))) + '"' + "," + '"' + str(datetime.fromtimestamp(int(y[index]["lastSeen"]))) + '"' + "," + '"' + str(y[index]["wiredMacs"]) + '"' + "," + '"' + str(datetime.fromtimestamp(int(y[index]["wiredLastSeen"]))) + '"' + "\n")&lt;BR /&gt;except:&lt;BR /&gt;f.write("\"none\",\"none\",\"none\",\"none\"\n")&lt;BR /&gt;index += 1&lt;BR /&gt;except:&lt;BR /&gt;f.write('"' + str(networks[index1]["name"]) + '"' + "," + "\"none\"\n")&lt;BR /&gt;index1 += 1&lt;BR /&gt;&lt;BR /&gt;mail()&lt;/P&gt;</description>
    <pubDate>Mon, 02 Mar 2020 15:39:43 GMT</pubDate>
    <dc:creator>wrobbin</dc:creator>
    <dc:date>2020-03-02T15:39:43Z</dc:date>
    <item>
      <title>Issue with Meraki Python Script -Air Marshall</title>
      <link>https://community.cisco.com/t5/network-platform-api/issue-with-meraki-python-script-air-marshall/m-p/5431842#M5157</link>
      <description>&lt;P&gt;I have the script below, use to work, stopped working I've been banging my head on it trying to figure it out or is there a different /better way to get this info. Any help you could be would be much appreciated.&lt;/P&gt;&lt;P&gt;import meraki&lt;BR /&gt;import json&lt;BR /&gt;import requests&lt;BR /&gt;import time&lt;BR /&gt;import smtplib&lt;BR /&gt;from email.mime.multipart import MIMEMultipart&lt;BR /&gt;from email.mime.base import MIMEBase&lt;BR /&gt;from email import encoders&lt;BR /&gt;from datetime import datetime, timezone&lt;/P&gt;&lt;P&gt;#Put your API key here&lt;BR /&gt;apikey =&lt;BR /&gt;orgid =&lt;/P&gt;&lt;P&gt;def getNetworks(apikey):&lt;BR /&gt;url = "&lt;A href="https://api.meraki.com/api/v0/organizations/11111/networks" target="_blank" rel="noopener nofollow noreferrer"&gt;https://api.meraki.com/api/v0/organizations/11111/networks&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;payload = ""&lt;BR /&gt;headers = {&lt;BR /&gt;'X-Cisco-Meraki-API-Key': apikey,&lt;BR /&gt;'cache-control': "no-cache",&lt;BR /&gt;'Postman-Token': ""&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;response = requests.request("GET", url, data=payload, headers=headers)&lt;/P&gt;&lt;P&gt;return response&lt;BR /&gt;&lt;BR /&gt;def getMarshall(network, apikey):&lt;BR /&gt;url = "&lt;A href="https://api.meraki.com/api/v0/networks/" target="_blank" rel="noopener nofollow noreferrer"&gt;https://api.meraki.com/api/v0/networks/&lt;/A&gt;" + network + "/airMarshal"&lt;/P&gt;&lt;P&gt;querystring = {"timespan":"3600"}&lt;/P&gt;&lt;P&gt;payload = ""&lt;BR /&gt;headers = {&lt;BR /&gt;'X-Cisco-Meraki-API-Key': apikey,&lt;BR /&gt;'cache-control': "no-cache",&lt;BR /&gt;'Postman-Token': ""&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;response = requests.request("GET", url, data=payload, headers=headers, params=querystring)&lt;/P&gt;&lt;P&gt;return response&lt;/P&gt;&lt;P&gt;def mail():&lt;BR /&gt;time = datetime.now().strftime("%m%d%y")&lt;BR /&gt;filename = "airmarshallReport_" + time + ".csv"&lt;BR /&gt;subject = "Meraki Airmarshall Report"&lt;BR /&gt;recipients = ["test@test.com"]&lt;BR /&gt;&lt;BR /&gt;msg = MIMEMultipart()&lt;BR /&gt;msg["Subject"] = subject&lt;BR /&gt;msg["From"] = "airmarshall@test.com"&lt;BR /&gt;msg["To"] = ", ".join(recipients)&lt;BR /&gt;&lt;BR /&gt;part = MIMEBase("application", "octet-stream")&lt;BR /&gt;part.set_payload(open(filename, "rb").read())&lt;BR /&gt;encoders.encode_base64(part)&lt;BR /&gt;&lt;BR /&gt;part.add_header("Content-Disposition", "attachment; filename=\"" + filename + "\"")&lt;BR /&gt;&lt;BR /&gt;msg.attach(part)&lt;BR /&gt;&lt;BR /&gt;server = smtplib.SMTP("mail.test.com")&lt;BR /&gt;server.sendmail("airmarshall@test.com", recipients, msg.as_string())&lt;/P&gt;&lt;P&gt;response = getNetworks(apikey)&lt;BR /&gt;networks = response.json()&lt;BR /&gt;index1 = 0&lt;BR /&gt;index2 = 0&lt;BR /&gt;time = datetime.now().strftime("%m%d%y")&lt;/P&gt;&lt;P&gt;with open("airmarshallReport_" + time + ".csv", "w+") as f:&lt;BR /&gt;f.write("network,ssid,bssid,contained,devices,channels,firstseen,lastseen,wiredmacs,wiredlastseen\n")&lt;BR /&gt;for line in networks:&lt;BR /&gt;try:&lt;BR /&gt;x = getMarshall(networks[index1]["id"],apikey)&lt;BR /&gt;y = x.json()&lt;BR /&gt;index = 0&lt;BR /&gt;for i in y:&lt;BR /&gt;f.write('"' + str(networks[index1]["name"]) + '"' + "," + '"' + str(y[index]["ssid"]) + '"' + "," + '"' + str(y[index]["bssids"][0]["bssid"]) + '"' + "," + '"' + str(y[index]["bssids"][0]["contained"]) + '"' + ",")&lt;BR /&gt;try:&lt;BR /&gt;for i in y[index]["bssids"][0]["detectedBy"]:&lt;BR /&gt;f.write('"' + str(i["device"]) + " RSSI - " + str(i["rssi"]) + " ")&lt;BR /&gt;index2 += 1&lt;BR /&gt;f.write('"' + ",")&lt;BR /&gt;except:&lt;BR /&gt;f.write('"' + "none\"," )&lt;BR /&gt;try:&lt;BR /&gt;f.write('"' + str(y[index]["channels"][0]) + '"' + ",")&lt;BR /&gt;except:&lt;BR /&gt;f.write('"' + "none\",")&lt;BR /&gt;try:&lt;BR /&gt;f.write('"' + str(datetime.fromtimestamp(int(y[index]["firstSeen"]))) + '"' + "," + '"' + str(datetime.fromtimestamp(int(y[index]["lastSeen"]))) + '"' + "," + '"' + str(y[index]["wiredMacs"]) + '"' + "," + '"' + str(datetime.fromtimestamp(int(y[index]["wiredLastSeen"]))) + '"' + "\n")&lt;BR /&gt;except:&lt;BR /&gt;f.write("\"none\",\"none\",\"none\",\"none\"\n")&lt;BR /&gt;index += 1&lt;BR /&gt;except:&lt;BR /&gt;f.write('"' + str(networks[index1]["name"]) + '"' + "," + "\"none\"\n")&lt;BR /&gt;index1 += 1&lt;BR /&gt;&lt;BR /&gt;mail()&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 15:39:43 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/issue-with-meraki-python-script-air-marshall/m-p/5431842#M5157</guid>
      <dc:creator>wrobbin</dc:creator>
      <dc:date>2020-03-02T15:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Meraki Python Script -Air Marshall</title>
      <link>https://community.cisco.com/t5/network-platform-api/issue-with-meraki-python-script-air-marshall/m-p/5431843#M5158</link>
      <description>&lt;P&gt;My bad i figured it out sorry. It's Monday i had the wrong API key ugh...&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 15:52:33 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/issue-with-meraki-python-script-air-marshall/m-p/5431843#M5158</guid>
      <dc:creator>wrobbin</dc:creator>
      <dc:date>2020-03-02T15:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Meraki Python Script -Air Marshall</title>
      <link>https://community.cisco.com/t5/network-platform-api/issue-with-meraki-python-script-air-marshall/m-p/5431844#M5159</link>
      <description>&lt;P&gt;Glad to hear you found the issue  &lt;SPAN class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="44444.jpg" style="width: 597px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image.jpeg"&gt;&lt;img src="https://community.cisco.com/t5/image/serverpage/image-id/262238i8366B9C34220282B/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.jpeg" alt="image.jpeg" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 16:06:22 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/issue-with-meraki-python-script-air-marshall/m-p/5431844#M5159</guid>
      <dc:creator>Nolan H.</dc:creator>
      <dc:date>2020-03-02T16:06:22Z</dc:date>
    </item>
  </channel>
</rss>

