cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
575
Views
2
Helpful
3
Replies

DNAC - Get Switch Hierarchy via API

evanm
Level 1
Level 1

Hello Community,

I am not sure if I am overlooking something but struggling to easily return where a switch was added to via the API. For context, I have added 1800 switches into DNAC. I would like to verify they have been added to the correct hierarchy but not sure how to best go about this. 

api_.devices.get_network_device_by_ip will show me that it has been added but the location or locationName keys are blank even though a switch has been properly assigned. As a workaround, I can locate the site_id it is in and pull all the devices of the building via response = api_.sites.get_membership(site_id) then loop through the results to check if it exists but this seems extreme. 
 
Any tips or advice would be greatly appreciated.
 
Regards.
 
-E

 

1 Accepted Solution

Accepted Solutions

This was a known issue with the /network-device API in the existing DNAC releases. You can use "Get Device Detail", it should provide the location.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

View solution in original post

3 Replies 3

This was a known issue with the /network-device API in the existing DNAC releases. You can use "Get Device Detail", it should provide the location.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Thanks bigevilbeard! Much appreciated. I noticed that get_device_detail provides a weird output for switches that are not being managed correctly even though assigned to the correct area/building. Not the end of the world but wondering if you've seen this before. Here's a switch that was added to DNAC but not managed due to credentials not matching the global setting.

prob_sw.PNG

When I query the API for this switch, it does not provide the location but the following response:

 

{'response': {'location': '--', 'timestamp': 1685995080000}}

 

 I am guessing the solution is to fix the switch so it is managed properly but thought I would mention it anyways. I suspect the only option for these would be to proceed with what I mentioned previously. Use api_.sites.get_membership(site_id) then loop through the results to check if the IP exists.

Thanks again for taking to the time to response.

-E

Last time i saw this issues all which was returned was 'null', but this was ages back since i last looked at this tbh. Just this problem you first saw stuck in my mind, as stuff does!

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io