From a0ea21d731f574f3680dfa15b8f6319a4d7f7428 Mon Sep 17 00:00:00 2001 From: TheNetworkGuy Date: Thu, 25 Jul 2024 16:23:59 +0200 Subject: [PATCH] Fixed bug in which some instances a nested hostgroup was not created --- modules/device.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/device.py b/modules/device.py index 74d4e12..df8918d 100644 --- a/modules/device.py +++ b/modules/device.py @@ -536,24 +536,26 @@ class NetworkDevice(): """ Checks if Zabbix object is still valid with Netbox parameters. """ - # Set Hostgroup ID - # If not, create the hostgroup and try finding the group again - if not self.setZabbixGroupID(groups): - # No hostgroup was found + # If group is found or if the hostgroup is nested + if not self.setZabbixGroupID(groups) or len(self.hostgroup.split('/')) > 1: if create_hostgroups: # Script is allowed to create a new hostgroup new_groups = self.createZabbixHostgroup(groups) for group in new_groups: - # Go through all newly created groups + # Add all new groups to the list of groups groups.append(group) - self.setZabbixGroupID(groups) - else: - e = (f"Device {self.name}: different hostgroup is required but " - "unable to create hostgroup without generation permission.") - self.logger.warning(e) - raise SyncInventoryError(e) + # check if the initial group was not already found (and this is a nested folder check) + if not self.group_id: + # Function returns true / false but also sets GroupID + if not self.setZabbixGroupID(groups) and not create_hostgroups: + e = (f"Device {self.name}: different hostgroup is required but " + "unable to create hostgroup without generation permission.") + self.logger.warning(e) + raise SyncInventoryError(e) + # Prepare templates and proxy config self.zbxTemplatePrepper(templates) self.setProxy(proxies) + # Get host object from Zabbix host = self.zabbix.host.get(filter={'hostid': self.zabbix_id}, selectInterfaces=['type', 'ip', 'port', 'details',