bb-Ricardo / netbox-sync

Sync objects from VMware or redfish sources to NetBox
MIT License
286 stars 65 forks source link

Errors when importing VMware inventory results #116

Closed baguilar951 closed 2 years ago

baguilar951 commented 2 years ago

Hello,

Encountering these errors when running a sync of the inventory on a particular vCenter:

2021-11-05 04:21:17,782 - DEBUG2: Sending PATCH to 'https://~netbox_url~/api/dcim/devices/29/' with data 'b'{"name": "it-dell-2.~domain~", "device_type": 42, "device_role": 19, "platform": 2, "site": 5, "cluster": 3, "tags": [{"name": "NetBox-synced"}, {"name": "Source: m"}, {"name": "icon_server"}]}''.
2021-11-05 04:21:17,918 - DEBUG2: Received HTTP Status 400.
2021-11-05 04:21:17,918 - ERROR: NetBox returned: PATCH /api/dcim/devices/29/ Bad Request
2021-11-05 04:21:17,918 - ERROR: NetBox returned body: {'rack': ['Rack Production Rack (002.01.53) does not belong to site vCenter: m.']}
2021-11-05 04:21:17,918 - ERROR: Request Failed for device. Used data: {'name': 'it-dell-2.~domain~', 'device_type': 42, 'device_role': 19, 'platform': 2, 'site': 5, 'cluster': 3, 'tags': [{'name': 'NetBox-synced'}, {'name': 'Source: m'}, {'name': 'icon_server'}]}

^ Presumably, and from what has been comitted to Netbox, the synchronization creates a new site with the name vCenter: My Example vCenter and the sync is trying to update the details of a device that obviously does not exist under that site name but does exist under another site with the proper name.

The other issue is:

2021-11-05 04:21:26,760 - INFO: Creating new NetBox 'interface' object 'vmnic3 (it-dell-2.~domain~)' with data: {'tagged_vlans': [110], 'tags': [{'name': 'NetBox-synced'}, {'name': 'Source: m'}], 'name': 'vmnic3', 'device': 29, 'mac_address': 'E4:43:4B:xx:xx:xx', 'enabled': True, 'description': '1Gb/s  pNIC (vSwitch0)', 'type': '1000base-t', 'mtu': 1500, 'mode': 'tagged'}
2021-11-05 04:21:26,760 - DEBUG2: Sending POST to 'https://~netbox_url~/api/dcim/interfaces/' with data 'b'{"tagged_vlans": [110], "tags": [{"name": "NetBox-synced"}, {"name": "Source: m"}], "name": "vmnic3", "device": 29, "mac_address": "E4:43:4B:xx:xx:xx", "enabled": true, "description": "1Gb/s  pNIC (vSwitch0)", "type": "1000base-t", "mtu": 1500, "mode": "tagged"}''.
2021-11-05 04:21:26,813 - DEBUG2: Received HTTP Status 400.
2021-11-05 04:21:26,813 - ERROR: NetBox returned: POST /api/dcim/interfaces/ Bad Request
2021-11-05 04:21:26,813 - ERROR: NetBox returned body: {'tagged_vlans': ["VLAN Management Network (2) must belong to the same site as the interface's parent device, or it must be global."]}
2021-11-05 04:21:26,814 - ERROR: Request Failed for interface. Used data: {'tagged_vlans': [110], 'tags': [{'name': 'NetBox-synced'}, {'name': 'Source: m'}], 'name': 'vmnic3', 'device': 29, 'mac_address': 'E4:43:4B:xx:xx:xx', 'enabled': True, 'description': '1Gb/s  pNIC (vSwitch0)', 'type': '1000base-t', 'mtu': 1500, 'mode': 'tagged'}

^ Not sure why this is trying to update a physical interface that exists or trying to connect a cable to a virtual interface, ideally the flexibility to create a vmnic under the physical interface in Netbox by creating a child under said physical interface is a much more logical solution here.

Let me know if I am missing a configuration somewhere.

bb-Ricardo commented 2 years ago

This is probably the main issue: https://github.com/bb-Ricardo/netbox-sync/blob/c26b726ba6659917fd73863f110add44141cd881/settings-example.ini#L142-L150

Also here under IMPORTANT: https://github.com/bb-Ricardo/netbox-sync/blob/main/docs/source_vmware.md#setup

ESXi Virtual interfaces are not really a "child" interface of a certain physical interface. Thats why they are created as virtual interfaces.

You need to define cluster_site_relation in your settings properly and try to run the script again. But It can cause issues with objects that have been created through the script already.

Best is to switch back to a database state before the first sync.

baguilar951 commented 2 years ago

Hi @bb-Ricardo,

Thank you for the docs, I probably should have gone deeper in the docs. I was able to get the inventory imported into the correct Site now. I am still encountering this error when the plugin is trying to create the VMK virtual interfaces:

2021-11-09 02:56:33,972 - INFO: Updating NetBox 'interface' object 'vmk3 (nutanix-6-esx.~domain~)' with data: {'name': 'vmk3', 'type': 'virtual', 'mtu': 9000, 'mac_address': '00:50:56:xx:xx:xx', 'description': 'PROD-BB-1 (10 Gb 1, vlan ID: 4)', 'mode': 'access', 'untagged_vlan': 67, 'tags': [{'name': 'NetBox-synced'}, {'name': 'Source: vCenter Prod'}]} 2021-11-09 02:56:33,972 - DEBUG2: Sending PATCH to 'https://racktables-test.~domain~/api/dcim/interfaces/62/' with data 'b'{"name": "vmk3", "type": "virtual", "mtu": 9000, "mac_address": "00:50:56:xx:xx:xx", "description": "PROD-BB-1 (10 Gb 1, vlan ID: 4)", "mode": "access", "untagged_vlan": 67, "tags": [{"name": "NetBox-synced"}, {"name": "Source: vCenter Prod"}]}''. 2021-11-09 02:56:34,050 - DEBUG2: Received HTTP Status 400. 2021-11-09 02:56:34,051 - ERROR: NetBox returned: PATCH /api/dcim/interfaces/62/ Bad Request 2021-11-09 02:56:34,051 - ERROR: NetBox returned body: {'type': ['Virtual interfaces cannot have a cable attached.']} 2021-11-09 02:56:34,051 - ERROR: Request Failed for interface. Used data: {'name': 'vmk3', 'type': 'virtual', 'mtu': 9000, 'mac_address': '00:50:56:xx:xx:xx', 'description': 'PROD-BB-1 (10 Gb 1, vlan ID: 4)', 'mode': 'access', 'untagged_vlan': 67, 'tags': [{'name': 'NetBox-synced'}, {'name': 'Source: vCenter Prod'}]}

The issue seems to stem from the fact that we have already existing interfaces which we created when we first created the host devices in netbox. With some of the hosts, it replaced and overwrote our original interfaces we created which is okay I guess, though we didn't even have MAC addresses documented in netbox so I am not sure how the script determined it was okay to overwrite the existing interface information. It also deleted/overwrote our documented iDRAC interfaces for some Dell machines, so that was very interesting. It looks like the order in which the interfaces were created originally is what the plugin uses to create and overwrite the existing ones.

This is our production netbox instance with the existing information: image

After the sync in our test instance: image

I understand that in some environments, VMK interfaces are logically not children of a particular physical interface, but rather children of a virtual switch. If the VMK holds the IP information and it is connected through a particular vSwitch on 1 or more uplinks, I would imagine it would be easy to place the VMK as a virtual interface under a VMNIC. If there isn't anything that can be done to add this in the plugin, that is okay. I wish Netbox had a way to create and assign virtual switches natively. Assigning the physical uplinks and then the virtual interfaces under the PHY would be very logical for our environment.

bb-Ricardo commented 2 years ago

Hi,

to your first question I can refer to the source code(you might need to scroll): https://github.com/bb-Ricardo/netbox-sync/blob/c26b726ba6659917fd73863f110add44141cd881/module/sources/common/source_base.py#L38-L58

for your second question: currently you can only assign ONE parent interface to a virtual interface. I would be the wrong information as there can be one, two ore more interfaces parent of a virtual interface.

In general you might want to skip syncing the hosts at all. You seem to have everything already documented. Add just sync the VM information.

ghost commented 2 years ago

In general you might want to skip syncing the hosts at all. You seem to have everything already documented. Add just sync the VM information.

This is a good idea to have a switch that we can exclude the hosts. Should I open a feature request?

bb-Ricardo commented 2 years ago

Hi, It's already there. Set host_exclude_filter to .*, then no host should be synced to NetBox.

bb-Ricardo commented 2 years ago

Can I close this issue?

bb-Ricardo commented 2 years ago

closing this issue due to no reply.