robertcsapo / ciscodnacnetbox

Cisco DNA Center Integration with NetBox
Other
34 stars 16 forks source link

Sync issue with Netbox Version - 3.0.3, DNAC version - 2.2.2.5 #5

Closed DHaider-COS closed 3 years ago

DHaider-COS commented 3 years ago

when setting up the plugin and running it for first time I get an exception on the status page. Below is the exception traceback that is shown in netbox.

Traceback (most recent call last): File "/opt/netbox/venv/lib/python3.9/site-packages/rq/worker.py", line 1043, in perform_job rv = job.perform() File "/opt/netbox/venv/lib/python3.9/site-packages/rq/job.py", line 814, in perform self._result = self._execute() File "/opt/netbox/venv/lib/python3.9/site-packages/rq/job.py", line 837, in _execute result = self.func(*self.args, self.kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/ciscodnacnetbox/ciscodnac/data.py", line 23, in full_sync devices = Data.sync_devices(kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/ciscodnacnetbox/ciscodnac/data.py", line 262, in sync_devices for device in tenants.devices(tenant=dnac): File "/opt/netbox/venv/lib/python3.9/site-packages/ciscodnacnetbox/ciscodnac/init.py", line 69, in devices return tenant.devices.get_device_list().response File "/opt/netbox/venv/lib/python3.9/site-packages/dnacentersdk/api/v2_1_2/devices.py", line 640, in get_device_list json_data = self._session.get(endpoint_full_url, params=params) File "/opt/netbox/venv/lib/python3.9/site-packages/dnacentersdk/restsession.py", line 398, in get with self.request('GET', url, erc, 0, params=params, **kwargs) as resp: File "/opt/netbox/venv/lib/python3.9/site-packages/dnacentersdk/restsession.py", line 320, in request check_response_code(response, erc) File "/opt/netbox/venv/lib/python3.9/site-packages/dnacentersdk/utils.py", line 216, in check_response_code raise ApiError(response) dnacentersdk.exceptions.ApiError: [404] Not Found - The URI requested is invalid or the resource requested, such as a user, does not exist. Also returned when the requested format is not supported by the requested method.

I also get a server error page when clicking on the status link from the side bar. with the exception

<class 'dnacentersdk.exceptions.ApiError'> [404] Not Found - The URI requested is invalid or the resource requested, such as a user, does not exist. Also returned when >the requested format is not supported by the requested method. Python version: 3.9.7 NetBox version: 3.0.3

I would love to know if this may just be a settings issue or an issue with our specific combo of netbox and DNAC. We use both of these applications in production and would LOVE to see this integration actually work. Would save a few dozen manhours for sure!

DHaider-COS commented 3 years ago

the error on the status page looks like it changes based on if the sync is running or not, when its not running its a different error, below is the complete exception.

<class 'KeyError'>

'dnac.spokanecounty.org'

Python version: 3.9.7 NetBox version: 3.0.3

robertcsapo commented 3 years ago

tenant.devices.get_device_list().response this seems to indicate that this is an issue towards Cisco DNA Center Platform API.

DHaider-COS commented 3 years ago

When I disabled and reenabled the REST API, I got a new exception when initiating the sync, listed below.

Traceback (most recent call last): File "/opt/netbox/venv/lib/python3.9/site-packages/rq/worker.py", line 1043, in perform_job rv = job.perform() File "/opt/netbox/venv/lib/python3.9/site-packages/rq/job.py", line 814, in perform self._result = self._execute() File "/opt/netbox/venv/lib/python3.9/site-packages/rq/job.py", line 837, in _execute result = self.func(*self.args, self.kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/ciscodnacnetbox/ciscodnac/data.py", line 23, in full_sync devices = Data.sync_devices(kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/ciscodnacnetbox/ciscodnac/data.py", line 322, in sync_devices slug=site_members[device.serialNumber], KeyError: None

If I tested with the Cisco DNA Center sandbox, it would pull all that data into our netbox right? If so would there be an easy way to remove it?

DHaider-COS commented 3 years ago

I have tested against the 2.2.2.3 sandbox and got that newer exception as well.

Traceback (most recent call last): File "/opt/netbox/venv/lib/python3.9/site-packages/rq/worker.py", line 1043, in perform_job rv = job.perform() File "/opt/netbox/venv/lib/python3.9/site-packages/rq/job.py", line 814, in perform self._result = self._execute() File "/opt/netbox/venv/lib/python3.9/site-packages/rq/job.py", line 837, in _execute result = self.func(*self.args, self.kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/ciscodnacnetbox/ciscodnac/data.py", line 23, in full_sync devices = Data.sync_devices(kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/ciscodnacnetbox/ciscodnac/data.py", line 322, in sync_devices slug=site_members[device.serialNumber], KeyError: None

what is interesting is that netbox was able to pull in the devices from the sandbox even with this exception being thrown. however our regular instance of DNA Center did not pull in device, only sites.

--UPDATE----

I think I was able to figure out what was causing this error, we had a device in DNAC that we imported (cisco FMC) that did not import into DNAC correctly. it did not have a serial number as well as some other information. after removing this device and trying a full sync again it finally synced without an exception.

except now I see another bug that may be related, if you don't think so i can create a new issue.

On the status page it lists all the devices that it should see in dnac, however when you go to the tenant owner and see how many devices it is tied to, its off by about 30 devices. (181 shown on the settings page and only 152 in the tenant's stats).

When I try and do a Devices Sync the page just sits and eventually throws a 504 gateway timeout error page.

Any ideas on what could be causing this?

DHaider-COS commented 3 years ago

---Final update---

I have figured out the last big hurdle that I was having. Since we have had netbox out in the wild for a bit, we have been slowly adding DNA Center Switches manually into the system. when the plugin goes and does a sync it will not re-add devices that are already in netbox. I have tested this theory by removing a switch from netbox then rerunning the full sync and watched it then get pulled in.

so the only other thing that is still just not working quite right is the device sync itself, but since the full sync is working I don't think thats a work stopping bug.

THANK YOU VERY MUCH FOR THIS PLUGIN! it is amazing how many manhours you have saved me!