Fixed bug where a single host exception would stop the sync.

This commit is contained in:
TheNetworkGuy 2024-10-30 13:50:20 +01:00
parent 66f24e6891
commit 7bf72de0f9

View File

@ -131,8 +131,8 @@ def main(arguments):
nb_version = netbox.version nb_version = netbox.version
# Go through all Netbox devices # Go through all Netbox devices
try: for nb_vm in netbox_vms:
for nb_vm in netbox_vms: try:
vm = VirtualMachine(nb_vm, zabbix, netbox_journals, nb_version, vm = VirtualMachine(nb_vm, zabbix, netbox_journals, nb_version,
create_journal, logger) create_journal, logger)
vm.set_hostgroup(vm_hostgroup_format,netbox_site_groups,netbox_regions) vm.set_hostgroup(vm_hostgroup_format,netbox_site_groups,netbox_regions)
@ -172,8 +172,11 @@ def main(arguments):
# Add VM to Zabbix # Add VM to Zabbix
vm.createInZabbix(zabbix_groups, zabbix_templates, vm.createInZabbix(zabbix_groups, zabbix_templates,
zabbix_proxy_list) zabbix_proxy_list)
except SyncError:
pass
for nb_device in netbox_devices: for nb_device in netbox_devices:
try:
# Set device instance set data such as hostgroup and template information. # Set device instance set data such as hostgroup and template information.
device = PhysicalDevice(nb_device, zabbix, netbox_journals, nb_version, device = PhysicalDevice(nb_device, zabbix, netbox_journals, nb_version,
create_journal, logger) create_journal, logger)
@ -186,13 +189,13 @@ def main(arguments):
# Check if device is primary or secondary # Check if device is primary or secondary
if device.promoteMasterDevice(): if device.promoteMasterDevice():
e = (f"Device {device.name}: is " e = (f"Device {device.name}: is "
f"part of cluster and primary.") f"part of cluster and primary.")
logger.info(e) logger.info(e)
else: else:
# Device is secondary in cluster. # Device is secondary in cluster.
# Don't continue with this device. # Don't continue with this device.
e = (f"Device {device.name}: is part of cluster " e = (f"Device {device.name}: is part of cluster "
f"but not primary. Skipping this host...") f"but not primary. Skipping this host...")
logger.info(e) logger.info(e)
continue continue
# Checks if device is in cleanup state # Checks if device is in cleanup state
@ -228,8 +231,8 @@ def main(arguments):
# Add device to Zabbix # Add device to Zabbix
device.createInZabbix(zabbix_groups, zabbix_templates, device.createInZabbix(zabbix_groups, zabbix_templates,
zabbix_proxy_list) zabbix_proxy_list)
except SyncError: except SyncError:
pass pass
if __name__ == "__main__": if __name__ == "__main__":