From 20096a215b49dc8ea6e09856f19cf1f2ca08b856 Mon Sep 17 00:00:00 2001 From: TheNetworkGuy Date: Wed, 30 Oct 2024 21:10:22 +0100 Subject: [PATCH] Added HG and template checks for devices and VM's. Temp disabled inventory mapping for VMs --- netbox_zabbix_sync.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/netbox_zabbix_sync.py b/netbox_zabbix_sync.py index b6c2b80..4a58dfa 100755 --- a/netbox_zabbix_sync.py +++ b/netbox_zabbix_sync.py @@ -137,8 +137,15 @@ def main(arguments): create_journal, logger) logger.debug(f"Host {vm.name}: started operations on VM.") vm.set_hostgroup(vm_hostgroup_format,netbox_site_groups,netbox_regions) + # Check if a valid hostgroup has been found for this VM. + if not vm.hostgroup: + continue vm.set_vm_template() - vm.set_inventory(nb_vm) + # Check if a valid template has been found for this VM. + if not vm.zbx_template_names: + continue + # Temporary disable inventory sync for VM's + # vm.set_inventory(nb_vm) # Checks if device is in cleanup state if vm.status in zabbix_device_removal: @@ -183,7 +190,13 @@ def main(arguments): create_journal, logger) logger.debug(f"Host {device.name}: started operations on device.") device.set_hostgroup(hostgroup_format,netbox_site_groups,netbox_regions) + # Check if a valid hostgroup has been found for this VM. + if not device.hostgroup: + continue device.set_template(templates_config_context, templates_config_context_overrule) + # Check if a valid template has been found for this VM. + if not device.zbx_template_names: + continue device.set_inventory(nb_device) # Checks if device is part of cluster. # Requires clustering variable