<?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: KeyError: 'lanIp' - Meraki in Network Platform API</title>
    <link>https://community.cisco.com/t5/network-platform-api/keyerror-lanip-meraki/m-p/5427513#M4551</link>
    <description>&lt;P&gt;Actually, we have around 10+ organizations, and a significant number of networks under each organization. 90% devices are online. Unfortunately, the script is not capable enough to fetch the DNS details. You can also suggest if there is any working script to get the DNS details of the devices including network and organization details.&lt;/P&gt;</description>
    <pubDate>Mon, 29 Apr 2024 07:42:56 GMT</pubDate>
    <dc:creator>Vmadathil</dc:creator>
    <dc:date>2024-04-29T07:42:56Z</dc:date>
    <item>
      <title>KeyError: 'lanIp' - Meraki</title>
      <link>https://community.cisco.com/t5/network-platform-api/keyerror-lanip-meraki/m-p/5427509#M4547</link>
      <description>&lt;P&gt;I need to fetch the DNS details of the devices of all the Networks under a particular Organization. I applied the following script which ended up with an error.&lt;/P&gt;&lt;P&gt;Script:-&lt;/P&gt;&lt;P&gt;import meraki&lt;BR /&gt;import pandas as pd&lt;BR /&gt;import time&lt;/P&gt;&lt;P&gt;# Replace with your Meraki Dashboard API key&lt;BR /&gt;API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"&lt;/P&gt;&lt;P&gt;# Organization ID (can be found in the URL when logged in to your dashboard)&lt;BR /&gt;ORGANIZATION_ID = "XXXXXX"&lt;/P&gt;&lt;P&gt;# Network ID (can be found in the network details URL)&lt;BR /&gt;NETWORK_ID = "XXXXXXXXX"&lt;/P&gt;&lt;P&gt;# Function to fetch AP information for a given network&lt;BR /&gt;def get_ap_info(network_id):&lt;BR /&gt;dashboard = meraki.DashboardAPI(API_KEY)&lt;BR /&gt;aps = None&lt;BR /&gt;while not aps:&lt;BR /&gt;try:&lt;BR /&gt;aps = dashboard.networks.getNetworkDevices(networkId=network_id)&lt;BR /&gt;except meraki.exceptions.APIError as e:&lt;BR /&gt;if e.status_code == 429:&lt;BR /&gt;print("API rate limit exceeded. Waiting before retrying...")&lt;BR /&gt;time.sleep(10) # Wait for 10 seconds before retrying&lt;BR /&gt;else:&lt;BR /&gt;raise # Re-raise the exception if it's not a rate limit error&lt;/P&gt;&lt;P&gt;ap_data = []&lt;BR /&gt;for ap in aps:&lt;BR /&gt;ap_info = {&lt;BR /&gt;"Name": ap["name"],&lt;BR /&gt;"AP ID": ap["serial"],&lt;BR /&gt;"Mode": ap["model"],&lt;BR /&gt;"Primary DNS": "",&lt;BR /&gt;"Secondary DNS": "",&lt;BR /&gt;"IP Type": "Static" if ap.get("lanIp") else "Dynamic" # Determine IP type (Static or Dynamic)&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;# Attempt to fetch additional details using device details API (may require additional permissions)&lt;BR /&gt;try:&lt;BR /&gt;device = dashboard.devices.getDevice(serial=ap["serial"])&lt;BR /&gt;ap_info["Primary DNS"] = device["lanIp"] # Assuming LAN IP is the primary DNS&lt;BR /&gt;# Fetching secondary DNS (if available) from the DHCP settings&lt;BR /&gt;if "dhcpSubnets" in device:&lt;BR /&gt;for subnet in device["dhcpSubnets"]:&lt;BR /&gt;if "dnsNameservers" in subnet:&lt;BR /&gt;ap_info["Secondary DNS"] = subnet["dnsNameservers"][1] if len(subnet["dnsNameservers"]) &amp;gt; 1 else "N/A"&lt;BR /&gt;break&lt;BR /&gt;except meraki.APIError as e:&lt;BR /&gt;print(f"Error fetching device details for {ap['serial']}: {e}")&lt;/P&gt;&lt;P&gt;ap_data.append(ap_info)&lt;/P&gt;&lt;P&gt;return ap_data&lt;/P&gt;&lt;P&gt;# Fetch AP information for the specified network&lt;BR /&gt;ap_data = get_ap_info(NETWORK_ID)&lt;/P&gt;&lt;P&gt;# Create pandas DataFrame and save to CSV&lt;BR /&gt;df = pd.DataFrame(ap_data)&lt;BR /&gt;df.to_csv("ap_information.csv", index=False)&lt;/P&gt;&lt;P&gt;print("AP information retrieved and saved to ap_information.csv")&lt;/P&gt;&lt;P&gt;Error:-&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;2024-04-24 09:35:50       meraki:     INFO &amp;gt; Meraki dashboard API session initialized with these parameters: {'version': '1.45.0', 'api_key': '************************************511c', 'base_url': '&lt;A class="" title="https://api.meraki.com/api/v1%27" href="https://api.meraki.com/api/v1%27" target="_blank" rel="noreferrer noopener nofollow"&gt;https://api.meraki.com/api/v1'&lt;/A&gt;, 'single_request_timeout': 60, 'certificate_path': '', 'requests_proxy': '', 'wait_on_rate_limit': True, 'nginx_429_retry_wait_time': 60, 'action_batch_retry_wait_time': 60, 'network_delete_retry_wait_time': 240, 'retry_4xx_error': False, 'retry_4xx_error_wait_time': 60, 'maximum_retries': 2, 'simulate': False, 'be_geo_id': None, 'caller': None, 'use_iterator_for_get_pages': False}&lt;BR /&gt;2024-04-24 09:35:50       meraki:     INFO &amp;gt; GET &lt;A class="" title="https://api.meraki.com/api/v1/networks/n_691865492754857725/devices" href="https://api.meraki.com/api/v1/networks/N_691865492754857725/devices" target="_blank" rel="noreferrer noopener nofollow"&gt;https://api.meraki.com/api/v1/networks/N_XXXXXXXXXXXXX/devices&lt;/A&gt;&lt;BR /&gt;2024-04-24 09:35:51       meraki:     INFO &amp;gt; networks, getNetworkDevices - 200 OK&lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt;  File "C:\Users\10011912\Documents\getdnsinfo 1.py", line 47, in &amp;lt;module&amp;gt;&lt;BR /&gt;    ap_data = get_ap_info(NETWORK_ID)&lt;BR /&gt;  File "C:\Users\10011912\Documents\getdnsinfo 1.py", line 26, in get_ap_info&lt;BR /&gt;    "IP Type": "Static" if ap["lanIp"] else "Dynamic"  # Determine IP type (Static or Dynamic)&lt;BR /&gt;KeyError: 'lanIp'&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;please help me to fix the issue.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 14:21:50 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/keyerror-lanip-meraki/m-p/5427509#M4547</guid>
      <dc:creator>Vmadathil</dc:creator>
      <dc:date>2024-04-24T14:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: KeyError: 'lanIp' - Meraki</title>
      <link>https://community.cisco.com/t5/network-platform-api/keyerror-lanip-meraki/m-p/5427510#M4548</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;3 things.&lt;/P&gt;&lt;P&gt;1- Never post your orgID , networkID or any other sensible info here. &lt;/P&gt;&lt;P&gt;2 - getNetworkDevices is not efficient. You should use getOrganizationDevices&lt;/P&gt;&lt;P&gt;3- You should print(device) to see if that device contains or not the key lanIp.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 14:39:03 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/keyerror-lanip-meraki/m-p/5427510#M4548</guid>
      <dc:creator>Raphael_L</dc:creator>
      <dc:date>2024-04-24T14:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: KeyError: 'lanIp' - Meraki</title>
      <link>https://community.cisco.com/t5/network-platform-api/keyerror-lanip-meraki/m-p/5427511#M4549</link>
      <description>&lt;P&gt;As &lt;A href="https://community.meraki.com/t5/user/viewprofilepage/user-id/13291"&gt;@Raphletourn&lt;/A&gt; says, check that lanIp is present.&lt;/P&gt;&lt;P&gt;The API is not consistent in how missing/undefined elements are handled in response data. The element may not be there at all, or it may have Null value. Often elements are context dependent.&lt;/P&gt;&lt;P&gt;It's not documented, so you need to code defensively to cope with these situations.&lt;/P&gt;&lt;P&gt;I've not tested this specific call, but I'd guess that if an AP exists but has not yet been assigned an IP (either static or dynamic), perhaps the lanIp is simply left out of the response. I.e. an AP that is in inventory and assigned to a network, but it has not yet been plugged in.&lt;/P&gt;&lt;P&gt;Btw when posting code, it helps if you use the formatting option "Insert/Edit code sample", as without the indentation Python scripts can be ambiguous/invalid/hard to read.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 12:33:33 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/keyerror-lanip-meraki/m-p/5427511#M4549</guid>
      <dc:creator>sungod</dc:creator>
      <dc:date>2024-04-25T12:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: KeyError: 'lanIp' - Meraki</title>
      <link>https://community.cisco.com/t5/network-platform-api/keyerror-lanip-meraki/m-p/5427512#M4550</link>
      <description>&lt;P&gt;Hi, I did necessary changes and tested. Now I am getting information without any errors. But getting the device IP on the DNS server column. and DNS server details is still missing.&lt;/P&gt;&lt;P&gt;Modified Script:-&lt;/P&gt;&lt;P&gt;import meraki&lt;BR /&gt;import pandas as pd&lt;/P&gt;&lt;P&gt;# Replace with your Meraki Dashboard API key&lt;BR /&gt;API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"&lt;/P&gt;&lt;P&gt;# Organization ID (can be found in the URL when logged in to your dashboard)&lt;BR /&gt;ORGANIZATION_ID = "xxxxx"&lt;/P&gt;&lt;P&gt;# Function to fetch AP information for a given organization&lt;BR /&gt;def get_ap_info(org_id):&lt;BR /&gt;dashboard = meraki.DashboardAPI(API_KEY)&lt;BR /&gt;devices = dashboard.organizations.getOrganizationDevices(org_id)&lt;/P&gt;&lt;P&gt;ap_data = []&lt;BR /&gt;for device in devices:&lt;BR /&gt;# Print device details to inspect the structure and presence of 'lanIp' key&lt;BR /&gt;print(device)&lt;/P&gt;&lt;P&gt;ap_info = {&lt;BR /&gt;"Name": device["name"],&lt;BR /&gt;"AP ID": device["serial"],&lt;BR /&gt;"Mode": device["model"],&lt;BR /&gt;"Primary DNS": "",&lt;BR /&gt;"Secondary DNS": "",&lt;BR /&gt;"IP Type": "Dynamic" # Default to Dynamic IP&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;# Check if the device has a wired interface (and thus a LAN IP)&lt;BR /&gt;if "lanIp" in device:&lt;BR /&gt;ap_info["IP Type"] = "Static"&lt;BR /&gt;ap_info["Primary DNS"] = device["lanIp"]&lt;/P&gt;&lt;P&gt;# Attempt to fetch additional details using device details API (may require additional permissions)&lt;BR /&gt;try:&lt;BR /&gt;# Fetch device details&lt;BR /&gt;device_details = dashboard.devices.getDevice(serial=device["serial"])&lt;BR /&gt;# Fetching secondary DNS (if available) from the DHCP settings&lt;BR /&gt;if "dhcpSubnets" in device_details:&lt;BR /&gt;for subnet in device_details["dhcpSubnets"]:&lt;BR /&gt;if "dnsNameservers" in subnet:&lt;BR /&gt;ap_info["Secondary DNS"] = subnet["dnsNameservers"][1] if len(subnet["dnsNameservers"]) &amp;gt; 1 else "N/A"&lt;BR /&gt;break&lt;BR /&gt;except meraki.APIError as e:&lt;BR /&gt;print(f"Error fetching device details for {device['serial']}: {e}")&lt;/P&gt;&lt;P&gt;ap_data.append(ap_info)&lt;/P&gt;&lt;P&gt;return ap_data&lt;/P&gt;&lt;P&gt;# Fetch AP information for the specified organization&lt;BR /&gt;ap_data = get_ap_info(ORGANIZATION_ID)&lt;/P&gt;&lt;P&gt;# Create pandas DataFrame and save to CSV&lt;BR /&gt;df = pd.DataFrame(ap_data)&lt;BR /&gt;df.to_csv("ap_information.csv", index=False)&lt;/P&gt;&lt;P&gt;print("AP information retrieved and saved to ap_information.csv")&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2024 07:39:30 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/keyerror-lanip-meraki/m-p/5427512#M4550</guid>
      <dc:creator>Vmadathil</dc:creator>
      <dc:date>2024-04-29T07:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: KeyError: 'lanIp' - Meraki</title>
      <link>https://community.cisco.com/t5/network-platform-api/keyerror-lanip-meraki/m-p/5427513#M4551</link>
      <description>&lt;P&gt;Actually, we have around 10+ organizations, and a significant number of networks under each organization. 90% devices are online. Unfortunately, the script is not capable enough to fetch the DNS details. You can also suggest if there is any working script to get the DNS details of the devices including network and organization details.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2024 07:42:56 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/keyerror-lanip-meraki/m-p/5427513#M4551</guid>
      <dc:creator>Vmadathil</dc:creator>
      <dc:date>2024-04-29T07:42:56Z</dc:date>
    </item>
    <item>
      <title>Re: KeyError: 'lanIp' - Meraki</title>
      <link>https://community.cisco.com/t5/network-platform-api/keyerror-lanip-meraki/m-p/5427514#M4552</link>
      <description>&lt;P&gt;I got the script.&lt;/P&gt;&lt;P&gt;import meraki&lt;BR /&gt;import pandas as pd&lt;BR /&gt;import json&lt;/P&gt;&lt;P&gt;# Replace with your Meraki Dashboard API key&lt;BR /&gt;API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"&lt;/P&gt;&lt;P&gt;# Organization ID (can be found in the URL when logged in to your dashboard)&lt;BR /&gt;ORGANIZATION_ID = "XXXXXX"&lt;/P&gt;&lt;P&gt;# Function to fetch management interface information for devices in a network&lt;BR /&gt;def get_management_interface_info(network_id, org_name, network_name):&lt;BR /&gt;dashboard = meraki.DashboardAPI(API_KEY)&lt;BR /&gt;devices = dashboard.networks.getNetworkDevices(network_id)&lt;/P&gt;&lt;P&gt;management_info = []&lt;BR /&gt;for device in devices:&lt;BR /&gt;try:&lt;BR /&gt;management_interface = dashboard.devices.getDeviceManagementInterface(serial=device['serial'])&lt;BR /&gt;device_info = {&lt;BR /&gt;"Organization": org_name,&lt;BR /&gt;"Organization ID": ORGANIZATION_ID,&lt;BR /&gt;"Network": network_name,&lt;BR /&gt;"Network ID": network_id,&lt;BR /&gt;"Serial": device['serial'],&lt;BR /&gt;"Device Name": device['name'],&lt;BR /&gt;"Active DDNS Hostname": management_interface.get('ddnsHostnames', {}).get('activeDdnsHostname', ''),&lt;BR /&gt;"DDNS Hostname WAN1": management_interface.get('ddnsHostnames', {}).get('ddnsHostnameWan1', ''),&lt;BR /&gt;"DDNS Hostname WAN2": management_interface.get('ddnsHostnames', {}).get('ddnsHostnameWan2', ''),&lt;BR /&gt;"WAN1 Enabled": management_interface.get('wan1', {}).get('wanEnabled', ''),&lt;BR /&gt;"WAN1 Using Static IP": management_interface.get('wan1', {}).get('usingStaticIp', ''),&lt;BR /&gt;"WAN1 Static IP": management_interface.get('wan1', {}).get('staticIp', ''),&lt;BR /&gt;"WAN1 Static Subnet Mask": management_interface.get('wan1', {}).get('staticSubnetMask', ''),&lt;BR /&gt;"WAN1 Static Gateway IP": management_interface.get('wan1', {}).get('staticGatewayIp', ''),&lt;BR /&gt;"WAN1 Static DNS": ', '.join(management_interface.get('wan1', {}).get('staticDns', [])),&lt;BR /&gt;"WAN1 VLAN": management_interface.get('wan1', {}).get('vlan', ''),&lt;BR /&gt;"WAN2 Enabled": management_interface.get('wan2', {}).get('wanEnabled', ''),&lt;BR /&gt;"WAN2 Using Static IP": management_interface.get('wan2', {}).get('usingStaticIp', ''),&lt;BR /&gt;"WAN2 Static IP": management_interface.get('wan2', {}).get('staticIp', ''),&lt;BR /&gt;"WAN2 Static Subnet Mask": management_interface.get('wan2', {}).get('staticSubnetMask', ''),&lt;BR /&gt;"WAN2 Static Gateway IP": management_interface.get('wan2', {}).get('staticGatewayIp', ''),&lt;BR /&gt;"WAN2 Static DNS": ', '.join(management_interface.get('wan2', {}).get('staticDns', [])),&lt;BR /&gt;"WAN2 VLAN": management_interface.get('wan2', {}).get('vlan', '')&lt;BR /&gt;}&lt;BR /&gt;management_info.append(device_info)&lt;BR /&gt;except meraki.APIError as e:&lt;BR /&gt;print(f"Error fetching management interface information for device {device['serial']}: {e}")&lt;/P&gt;&lt;P&gt;return management_info&lt;/P&gt;&lt;P&gt;# Function to fetch management interface information for devices in all networks of an organization&lt;BR /&gt;def get_organization_management_interface_info(org_id):&lt;BR /&gt;dashboard = meraki.DashboardAPI(API_KEY)&lt;BR /&gt;org_name = dashboard.organizations.getOrganization(org_id)['name']&lt;BR /&gt;networks = dashboard.organizations.getOrganizationNetworks(org_id)&lt;/P&gt;&lt;P&gt;org_management_info = []&lt;BR /&gt;for network in networks:&lt;BR /&gt;network_id = network['id']&lt;BR /&gt;network_name = network['name']&lt;BR /&gt;management_info = get_management_interface_info(network_id, org_name, network_name)&lt;BR /&gt;org_management_info.extend(management_info)&lt;/P&gt;&lt;P&gt;return org_management_info&lt;/P&gt;&lt;P&gt;# Fetch management interface information for devices within the organization&lt;BR /&gt;org_management_info = get_organization_management_interface_info(ORGANIZATION_ID)&lt;/P&gt;&lt;P&gt;# Convert to DataFrame&lt;BR /&gt;df = pd.DataFrame(org_management_info)&lt;/P&gt;&lt;P&gt;# Save to CSV&lt;BR /&gt;df.to_csv("organization_management_interface_info.csv", index=False)&lt;/P&gt;&lt;P&gt;print("Management interface information retrieved and saved to organization_management_interface_info.csv.")&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2024 07:07:12 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/keyerror-lanip-meraki/m-p/5427514#M4552</guid>
      <dc:creator>Vmadathil</dc:creator>
      <dc:date>2024-05-03T07:07:12Z</dc:date>
    </item>
  </channel>
</rss>

