From 4a53b53789d9af793e18fdae9b911d87e61d7375 Mon Sep 17 00:00:00 2001 From: TheNetworkGuy Date: Tue, 24 Jun 2025 21:28:32 +0200 Subject: [PATCH] Removed previous patch for Nonetype hostgroups and made a proper fix by refactoring the set_hostgroup() function and removing it from virtual_machines.py --- modules/device.py | 6 ++---- modules/hostgroups.py | 1 - modules/virtual_machine.py | 20 +------------------- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/modules/device.py b/modules/device.py index c3baa17..03ca191 100644 --- a/modules/device.py +++ b/modules/device.py @@ -48,6 +48,7 @@ class PhysicalDevice: self.zbx_template_names = [] self.zbx_templates = [] self.hostgroups = [] + self.hostgroup_type = "dev" self.tenant = nb.tenant self.config_context = nb.config_context self.zbxproxy = None @@ -121,7 +122,7 @@ class PhysicalDevice: """Set the hostgroup for this device""" # Create new Hostgroup instance hg = Hostgroup( - "dev", + self.hostgroup_type, self.nb, self.nb_api_version, logger=self.logger, @@ -564,9 +565,6 @@ class PhysicalDevice: final_data = [] # Check if the hostgroup is in a nested format and check each parent for hostgroup in self.hostgroups: - # Check if hostgroup is string. If Nonetype skip hostgroup - if not isinstance(hostgroup, str): - continue for pos in range(len(hostgroup.split("/"))): zabbix_hg = hostgroup.rsplit("/", pos)[0] if self.lookupZabbixHostgroup(hostgroups, zabbix_hg): diff --git a/modules/hostgroups.py b/modules/hostgroups.py index 38c44c0..213b4cf 100644 --- a/modules/hostgroups.py +++ b/modules/hostgroups.py @@ -144,7 +144,6 @@ class Hostgroup: ) self.logger.warning(msg) return None - #raise HostgroupError(msg) def list_formatoptions(self): """ diff --git a/modules/virtual_machine.py b/modules/virtual_machine.py index e0f7abb..847375d 100644 --- a/modules/virtual_machine.py +++ b/modules/virtual_machine.py @@ -16,6 +16,7 @@ class VirtualMachine(PhysicalDevice): super().__init__(*args, **kwargs) self.hostgroup = None self.zbx_template_names = None + self.hostgroup_type = "vm" def _inventory_map(self): """use VM inventory maps""" @@ -29,25 +30,6 @@ class VirtualMachine(PhysicalDevice): """use VM tag maps""" return config["vm_tag_map"] - def set_hostgroup(self, hg_format, nb_site_groups, nb_regions): - """Set the hostgroup for this device""" - # Create new Hostgroup instance - hg = Hostgroup( - "vm", - self.nb, - self.nb_api_version, - logger=self.logger, - nested_sitegroup_flag=config["traverse_site_groups"], - nested_region_flag=config["traverse_regions"], - nb_groups=nb_site_groups, - nb_regions=nb_regions, - ) - # Generate hostgroup based on hostgroup format - if isinstance(hg_format, list): - self.hostgroups = [hg.generate(f) for f in hg_format] - else: - self.hostgroups.append(hg.generate(hg_format)) - def set_vm_template(self): """Set Template for VMs. Overwrites default class to skip a lookup of custom fields."""