bb-Ricardo / netbox-sync

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

Hosts that form VMWare cluster that get synchroniyed as Devices are "merged" into one Device #177

Closed plevart closed 2 years ago

plevart commented 2 years ago

Hi, I'm very pleased that this tool exists and I'm using it to synchronize virtual machines of my VMWare cluster with NetBox. Besides VirtualMachine objects, I noticed an object of type Device which holds a name of one of 3 physical machines that form the VMWare cluster. I noticed that whenever I run the synchronization, netbox-sync tries to "squeeze" the data of 3 machines into one entry of type Device, overwriting what it had just written:

2022-04-25 09:50:36,341 - INFO: Starting NetBox Sync v1.2.3 (2022-04-09)
2022-04-25 09:50:37,489 - INFO: Successfully connected to NetBox 'netbox.integralis.si'
2022-04-25 09:50:37,489 - INFO: Initializing sources
2022-04-25 09:50:37,556 - INFO: Successfully connected to vCenter SDK 'vc1.marand.si'
2022-04-25 09:50:37,556 - INFO: Querying necessary objects from NetBox. This might take a while.
2022-04-25 09:50:40,700 - INFO: Finished querying necessary objects from NetBox
2022-04-25 09:50:40,717 - INFO: Query data from vCenter: 'vc1.marand.si'
2022-04-25 09:50:42,970 - INFO: Device 'esx5.marand.si' attribute 'name' changed from 'esx6.marand.si' to 'esx5.marand.si'
2022-04-25 09:50:42,970 - INFO: Device 'esx5.marand.si' attribute 'serial' changed from 'YMLU009510' to 'YMLU009509'
2022-04-25 09:50:42,972 - INFO: Interface 'vmnic0 (esx5.marand.si)' attribute 'mac_address' changed from '4C:52:62:48:26:0D' to '4C:52:62:48:23:70'
2022-04-25 09:50:42,972 - INFO: Interface 'vmnic1 (esx5.marand.si)' attribute 'mac_address' changed from '4C:52:62:48:26:0E' to '4C:52:62:48:23:71'
2022-04-25 09:50:42,972 - INFO: Interface 'vmnic2 (esx5.marand.si)' attribute 'mac_address' changed from '4C:52:62:4A:8A:69' to '4C:52:62:4A:8C:01'
2022-04-25 09:50:42,973 - INFO: Interface 'vmnic2 (esx5.marand.si)' attribute 'description' changed from 'pNIC' to ' pNIC'
2022-04-25 09:50:42,973 - INFO: Interface 'vmnic3 (esx5.marand.si)' attribute 'mac_address' changed from '4C:52:62:4A:8A:6A' to '4C:52:62:4A:8C:02'
2022-04-25 09:50:42,973 - INFO: Interface 'vmnic3 (esx5.marand.si)' attribute 'description' changed from 'pNIC' to ' pNIC'
2022-04-25 09:50:42,974 - INFO: Interface 'vmnic4 (esx5.marand.si)' attribute 'mac_address' changed from '4C:52:62:4A:8A:6B' to '4C:52:62:4A:8C:03'
2022-04-25 09:50:42,974 - INFO: Interface 'vmnic4 (esx5.marand.si)' attribute 'description' changed from 'pNIC' to ' pNIC'
2022-04-25 09:50:42,974 - INFO: Interface 'vmnic5 (esx5.marand.si)' attribute 'mac_address' changed from '4C:52:62:4A:8A:6C' to '4C:52:62:4A:8C:04'
2022-04-25 09:50:42,974 - INFO: Interface 'vmnic5 (esx5.marand.si)' attribute 'description' changed from 'pNIC' to ' pNIC'
2022-04-25 09:50:42,975 - INFO: Interface 'vmnic6 (esx5.marand.si)' attribute 'mac_address' changed from 'B4:96:91:78:A4:74' to 'B4:96:91:78:A0:D8'
2022-04-25 09:50:42,975 - INFO: Interface 'vmnic6 (esx5.marand.si)' attribute 'type' changed from '10gbase-t' to '10gbase-x-sfpp'
2022-04-25 09:50:42,975 - INFO: Interface 'vmnic7 (esx5.marand.si)' attribute 'mac_address' changed from 'B4:96:91:78:A4:75' to 'B4:96:91:78:A0:D9'
2022-04-25 09:50:42,975 - INFO: Interface 'vmnic7 (esx5.marand.si)' attribute 'type' changed from '10gbase-t' to '10gbase-x-sfpp'
2022-04-25 09:50:42,976 - INFO: Interface 'vmnic8 (esx5.marand.si)' attribute 'mac_address' changed from 'B4:96:91:78:99:C8' to 'B4:96:91:78:99:40'
2022-04-25 09:50:42,976 - INFO: Interface 'vmnic8 (esx5.marand.si)' attribute 'type' changed from '10gbase-t' to '10gbase-x-sfpp'
2022-04-25 09:50:42,976 - INFO: Interface 'vmnic9 (esx5.marand.si)' attribute 'mac_address' changed from 'B4:96:91:78:99:C9' to 'B4:96:91:78:99:41'
2022-04-25 09:50:42,976 - INFO: Interface 'vmnic9 (esx5.marand.si)' attribute 'type' changed from '10gbase-t' to '10gbase-x-sfpp'
2022-04-25 09:50:42,977 - INFO: Interface 'vmk0 (esx5.marand.si)' attribute 'mac_address' changed from 'B4:96:91:78:A4:74' to 'B4:96:91:78:A0:D8'
2022-04-25 09:50:42,979 - INFO: Interface 'vmk5 (esx5.marand.si)' attribute 'mac_address' changed from '00:50:56:61:F1:4A' to '00:50:56:69:59:44'
2022-04-25 09:50:42,981 - INFO: Interface 'vmk1 (esx5.marand.si)' attribute 'mac_address' changed from '00:50:56:65:89:AA' to '00:50:56:61:1B:65'
2022-04-25 09:50:42,983 - INFO: Interface 'vmk2 (esx5.marand.si)' attribute 'mac_address' changed from '00:50:56:66:74:F1' to '00:50:56:67:C0:AE'
2022-04-25 09:50:42,985 - INFO: Interface 'vmk3 (esx5.marand.si)' attribute 'mac_address' changed from '00:50:56:6A:06:D4' to '00:50:56:6C:70:E5'
2022-04-25 09:50:42,987 - INFO: Interface 'vmk4 (esx5.marand.si)' attribute 'mac_address' changed from '00:50:56:6D:61:BE' to '00:50:56:64:2F:92'
2022-04-25 09:50:45,081 - INFO: Device 'esx7.marand.si' attribute 'name' changed from 'esx5.marand.si' to 'esx7.marand.si'
2022-04-25 09:50:45,081 - INFO: Device 'esx7.marand.si' attribute 'serial' changed from 'YMLU009509' to 'YMLU009508'
2022-04-25 09:50:45,083 - INFO: Interface 'vmnic0 (esx7.marand.si)' attribute 'mac_address' changed from '4C:52:62:48:23:70' to '4C:52:62:48:23:7F'
2022-04-25 09:50:45,083 - INFO: Interface 'vmnic1 (esx7.marand.si)' attribute 'mac_address' changed from '4C:52:62:48:23:71' to '4C:52:62:48:23:80'
2022-04-25 09:50:45,084 - INFO: Interface 'vmnic2 (esx7.marand.si)' attribute 'mac_address' changed from '4C:52:62:4A:8C:01' to '4C:52:62:4A:8B:F9'
2022-04-25 09:50:45,084 - INFO: Interface 'vmnic3 (esx7.marand.si)' attribute 'mac_address' changed from '4C:52:62:4A:8C:02' to '4C:52:62:4A:8B:FA'
2022-04-25 09:50:45,085 - INFO: Interface 'vmnic4 (esx7.marand.si)' attribute 'mac_address' changed from '4C:52:62:4A:8C:03' to '4C:52:62:4A:8B:FB'
2022-04-25 09:50:45,085 - INFO: Interface 'vmnic5 (esx7.marand.si)' attribute 'mac_address' changed from '4C:52:62:4A:8C:04' to '4C:52:62:4A:8B:FC'
2022-04-25 09:50:45,086 - INFO: Interface 'vmnic6 (esx7.marand.si)' attribute 'mac_address' changed from 'B4:96:91:78:A0:D8' to 'B4:96:91:78:A5:8C'
2022-04-25 09:50:45,086 - INFO: Interface 'vmnic7 (esx7.marand.si)' attribute 'mac_address' changed from 'B4:96:91:78:A0:D9' to 'B4:96:91:78:A5:8D'
2022-04-25 09:50:45,087 - INFO: Interface 'vmnic8 (esx7.marand.si)' attribute 'mac_address' changed from 'B4:96:91:78:99:40' to 'B4:96:91:78:A5:F4'
2022-04-25 09:50:45,087 - INFO: Interface 'vmnic9 (esx7.marand.si)' attribute 'mac_address' changed from 'B4:96:91:78:99:41' to 'B4:96:91:78:A5:F5'
2022-04-25 09:50:45,087 - INFO: Interface 'vmk0 (esx7.marand.si)' attribute 'mac_address' changed from 'B4:96:91:78:A0:D8' to 'B4:96:91:78:A5:8C'
2022-04-25 09:50:45,089 - INFO: Interface 'vmk5 (esx7.marand.si)' attribute 'mac_address' changed from '00:50:56:69:59:44' to '00:50:56:69:94:D4'
2022-04-25 09:50:45,091 - INFO: Interface 'vmk1 (esx7.marand.si)' attribute 'mac_address' changed from '00:50:56:61:1B:65' to '00:50:56:62:F8:53'
2022-04-25 09:50:45,093 - INFO: Interface 'vmk2 (esx7.marand.si)' attribute 'mac_address' changed from '00:50:56:67:C0:AE' to '00:50:56:66:A1:C3'
2022-04-25 09:50:45,096 - INFO: Interface 'vmk3 (esx7.marand.si)' attribute 'mac_address' changed from '00:50:56:6C:70:E5' to '00:50:56:62:0A:04'
2022-04-25 09:50:45,098 - INFO: Interface 'vmk4 (esx7.marand.si)' attribute 'mac_address' changed from '00:50:56:64:2F:92' to '00:50:56:64:01:D0'
2022-04-25 09:50:47,287 - INFO: Device 'esx6.marand.si' attribute 'name' changed from 'esx7.marand.si' to 'esx6.marand.si'
2022-04-25 09:50:47,287 - INFO: Device 'esx6.marand.si' attribute 'serial' changed from 'YMLU009508' to 'YMLU009510'
2022-04-25 09:50:47,288 - INFO: Interface 'vmnic0 (esx6.marand.si)' attribute 'mac_address' changed from '4C:52:62:48:23:7F' to '4C:52:62:48:26:0D'
2022-04-25 09:50:47,289 - INFO: Interface 'vmnic1 (esx6.marand.si)' attribute 'mac_address' changed from '4C:52:62:48:23:80' to '4C:52:62:48:26:0E'
2022-04-25 09:50:47,289 - INFO: Interface 'vmnic2 (esx6.marand.si)' attribute 'mac_address' changed from '4C:52:62:4A:8B:F9' to '4C:52:62:4A:8A:69'
2022-04-25 09:50:47,290 - INFO: Interface 'vmnic3 (esx6.marand.si)' attribute 'mac_address' changed from '4C:52:62:4A:8B:FA' to '4C:52:62:4A:8A:6A'
2022-04-25 09:50:47,290 - INFO: Interface 'vmnic4 (esx6.marand.si)' attribute 'mac_address' changed from '4C:52:62:4A:8B:FB' to '4C:52:62:4A:8A:6B'
2022-04-25 09:50:47,291 - INFO: Interface 'vmnic5 (esx6.marand.si)' attribute 'mac_address' changed from '4C:52:62:4A:8B:FC' to '4C:52:62:4A:8A:6C'
2022-04-25 09:50:47,291 - INFO: Interface 'vmnic6 (esx6.marand.si)' attribute 'mac_address' changed from 'B4:96:91:78:A5:8C' to 'B4:96:91:78:A4:74'
2022-04-25 09:50:47,292 - INFO: Interface 'vmnic7 (esx6.marand.si)' attribute 'mac_address' changed from 'B4:96:91:78:A5:8D' to 'B4:96:91:78:A4:75'
2022-04-25 09:50:47,292 - INFO: Interface 'vmnic8 (esx6.marand.si)' attribute 'mac_address' changed from 'B4:96:91:78:A5:F4' to 'B4:96:91:78:99:C8'
2022-04-25 09:50:47,293 - INFO: Interface 'vmnic9 (esx6.marand.si)' attribute 'mac_address' changed from 'B4:96:91:78:A5:F5' to 'B4:96:91:78:99:C9'
2022-04-25 09:50:47,293 - INFO: Interface 'vmk0 (esx6.marand.si)' attribute 'mac_address' changed from 'B4:96:91:78:A5:8C' to 'B4:96:91:78:A4:74'
2022-04-25 09:50:47,295 - INFO: Interface 'vmk5 (esx6.marand.si)' attribute 'mac_address' changed from '00:50:56:69:94:D4' to '00:50:56:61:F1:4A'
2022-04-25 09:50:47,297 - INFO: Interface 'vmk1 (esx6.marand.si)' attribute 'mac_address' changed from '00:50:56:62:F8:53' to '00:50:56:65:89:AA'
2022-04-25 09:50:47,299 - INFO: Interface 'vmk2 (esx6.marand.si)' attribute 'mac_address' changed from '00:50:56:66:A1:C3' to '00:50:56:66:74:F1'
2022-04-25 09:50:47,301 - INFO: Interface 'vmk3 (esx6.marand.si)' attribute 'mac_address' changed from '00:50:56:62:0A:04' to '00:50:56:6A:06:D4'
2022-04-25 09:50:47,304 - INFO: Interface 'vmk4 (esx6.marand.si)' attribute 'mac_address' changed from '00:50:56:64:01:D0' to '00:50:56:6D:61:BE'
...

It looks like the "key" of that Device object is the same for all 3 machines. Can I do something to my VMWare cluster so that I get 3 separate Device objects in NetBox?

bb-Ricardo commented 2 years ago

Hi, can you run the Tool with the option -l DEBUG2 this will help to debug the issue.

plevart commented 2 years ago

Hm, it looks like the "fuzzy" matching logic incorrectly identifies a Device. I don't know how, though. This is, I think, the relevant part of the DEBUG2 log:

2022-04-25 10:10:13,329 - DEBUG: vCenter returned '3' hosts
2022-04-25 10:10:13,331 - DEBUG: Parsing vCenter host: esx5.marand.si
2022-04-25 10:10:13,334 - DEBUG2: Trying to find site name for device 'esx5.marand.si'
2022-04-25 10:10:13,334 - DEBUG2: Found a matching host_site_relation 'Posta' (esx[567].*) for esx5.marand.si.
2022-04-25 10:10:13,621 - DEBUG2: Found SerialNumberTag: YMLU009509
2022-04-25 10:10:13,621 - DEBUG2: Found ServiceTag: YMLU009509
2022-04-25 10:10:13,621 - DEBUG2: Found EnclosureSerialNumberTag: YMLU009509
2022-04-25 10:10:13,621 - DEBUG2: Found a matching host_tenant_relation 'MARAND, d.o.o.' (.*\.marand\.si) for esx5.marand.si.
2022-04-25 10:10:14,372 - DEBUG2: Found host proxySwitch Distributed Switch
2022-04-25 10:10:15,091 - DEBUG2: Parsing PhysicalNic: vmnic0
2022-04-25 10:10:15,091 - DEBUG2: Parsing PhysicalNic: vmnic1
2022-04-25 10:10:15,091 - DEBUG2: Parsing PhysicalNic: vmnic2
2022-04-25 10:10:15,091 - DEBUG2: Parsing PhysicalNic: vmnic3
2022-04-25 10:10:15,091 - DEBUG2: Parsing PhysicalNic: vmnic4
2022-04-25 10:10:15,091 - DEBUG2: Parsing PhysicalNic: vmnic5
2022-04-25 10:10:15,091 - DEBUG2: Parsing PhysicalNic: vmnic6
2022-04-25 10:10:15,091 - DEBUG2: Parsing PhysicalNic: vmnic7
2022-04-25 10:10:15,092 - DEBUG2: Parsing PhysicalNic: vmnic8
2022-04-25 10:10:15,092 - DEBUG2: Parsing PhysicalNic: vmnic9
2022-04-25 10:10:15,475 - DEBUG2: Parsing HostVirtualNic: vmk0
2022-04-25 10:10:15,475 - DEBUG2: Parsing HostVirtualNic: vmk5
2022-04-25 10:10:15,475 - DEBUG2: Parsing HostVirtualNic: vmk1
2022-04-25 10:10:15,475 - DEBUG2: Parsing HostVirtualNic: vmk2
2022-04-25 10:10:15,475 - DEBUG2: Parsing HostVirtualNic: vmk3
2022-04-25 10:10:15,476 - DEBUG2: Parsing HostVirtualNic: vmk4
2022-04-25 10:10:15,476 - DEBUG2: Trying to find a device based on the collected name, cluster, IP and MAC addresses
2022-04-25 10:10:15,476 - DEBUG2: No exact match found. Trying to find device based on MAC addresses
2022-04-25 10:10:15,476 - DEBUG2: No match found. Trying to find device based on serial number
2022-04-25 10:10:15,476 - DEBUG2: No match found. Trying to find device based on asset tag
2022-04-25 10:10:15,476 - DEBUG2: Found a matching device object: esx6.marand.si (Posta)
2022-04-25 10:10:15,476 - DEBUG2: Parsing 'device' data structure: esx5.marand.si
2022-04-25 10:10:15,477 - DEBUG2: Parsing 'device type' data structure: PRIMERGY RX2530 M5
2022-04-25 10:10:15,477 - DEBUG2: Parsing 'manufacturer' data structure: FUJITSU
2022-04-25 10:10:15,477 - DEBUG2: Parsing 'site' data structure: Posta
2022-04-25 10:10:15,477 - DEBUG2: Parsing 'cluster' data structure: FUJITSU Server PRIMERGY RX2530 M5
2022-04-25 10:10:15,477 - DEBUG2: Parsing 'platform' data structure: VMware ESXi 7.0.0
2022-04-25 10:10:15,477 - DEBUG2: Parsing 'tenant' data structure: MARAND, d.o.o.
2022-04-25 10:10:15,477 - INFO: Device 'esx5.marand.si' attribute 'name' changed from 'esx6.marand.si' to 'esx5.marand.si'
2022-04-25 10:10:15,477 - INFO: Device 'esx5.marand.si' attribute 'serial' changed from 'YMLU009510' to 'YMLU009509'
2022-04-25 10:10:15,477 - DEBUG: Updated device object: esx5.marand.si

I'm I correct to assume that the "fuzzy" matching logic finds a matching device only by it's site? I do have a mapping that yields the same site for all 3 hosts:

# Same as cluster site but on host level. If unset it will fall back
# to cluster_site_relation.
host_site_relation = esx[567].* = "Posta"
bb-Ricardo commented 2 years ago

Location has nothing to do with it. It's the serial number with the enclosures. I assume these servers are blade servers?

bb-Ricardo commented 2 years ago

mmhh, these are not Blade servers and it doesn't match on serial either

bb-Ricardo commented 2 years ago

ahh, do they share all the same asset tag? If so, then try to switch of the asset tag syncing in the config and remove the asset tag from the device in NetBox.

plevart commented 2 years ago

Pardon, I have expressed myself incorrectly. I meant "site" instead of "location". The site is same for all 3 hosts. What does this line mean:

2022-04-25 10:10:15,476 - DEBUG2: Found a matching device object: esx6.marand.si (Posta)

These are quite big machines. I don't think they are blades. And each has its unique serial number.

plevart commented 2 years ago

Yes, the Asset Tag has value "System Asset Tag" for all 3 hosts. Do I just clear the field and save before re-syncing with changed config?

bb-Ricardo commented 2 years ago

Almost, these are the two relevant lines:

2022-04-25 10:10:15,476 - DEBUG2: No match found. Trying to find device based on asset tag
2022-04-25 10:10:15,476 - DEBUG2: Found a matching device object: esx6.marand.si (Posta)
bb-Ricardo commented 2 years ago
plevart commented 2 years ago

It worked. I now have 3 devices.

plevart commented 2 years ago

Thank you very much. DEBUG2 is very useful. I'll use it from now on...

bb-Ricardo commented 2 years ago

An asset Tag is meant to be unique, like a serial number. Not sure who (VMWare or Fujitsu) causes this problem here. If you can live without the tag automatically synced then you're ready to go.