mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-07-16 04:02:56 -06:00
Removed previous patch for Nonetype hostgroups and made a proper fix by refactoring the set_hostgroup() function and removing it from virtual_machines.py
This commit is contained in:
parent
6d4f1ac0a5
commit
4a53b53789
@ -48,6 +48,7 @@ class PhysicalDevice:
|
|||||||
self.zbx_template_names = []
|
self.zbx_template_names = []
|
||||||
self.zbx_templates = []
|
self.zbx_templates = []
|
||||||
self.hostgroups = []
|
self.hostgroups = []
|
||||||
|
self.hostgroup_type = "dev"
|
||||||
self.tenant = nb.tenant
|
self.tenant = nb.tenant
|
||||||
self.config_context = nb.config_context
|
self.config_context = nb.config_context
|
||||||
self.zbxproxy = None
|
self.zbxproxy = None
|
||||||
@ -121,7 +122,7 @@ class PhysicalDevice:
|
|||||||
"""Set the hostgroup for this device"""
|
"""Set the hostgroup for this device"""
|
||||||
# Create new Hostgroup instance
|
# Create new Hostgroup instance
|
||||||
hg = Hostgroup(
|
hg = Hostgroup(
|
||||||
"dev",
|
self.hostgroup_type,
|
||||||
self.nb,
|
self.nb,
|
||||||
self.nb_api_version,
|
self.nb_api_version,
|
||||||
logger=self.logger,
|
logger=self.logger,
|
||||||
@ -564,9 +565,6 @@ class PhysicalDevice:
|
|||||||
final_data = []
|
final_data = []
|
||||||
# Check if the hostgroup is in a nested format and check each parent
|
# Check if the hostgroup is in a nested format and check each parent
|
||||||
for hostgroup in self.hostgroups:
|
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("/"))):
|
for pos in range(len(hostgroup.split("/"))):
|
||||||
zabbix_hg = hostgroup.rsplit("/", pos)[0]
|
zabbix_hg = hostgroup.rsplit("/", pos)[0]
|
||||||
if self.lookupZabbixHostgroup(hostgroups, zabbix_hg):
|
if self.lookupZabbixHostgroup(hostgroups, zabbix_hg):
|
||||||
|
@ -144,7 +144,6 @@ class Hostgroup:
|
|||||||
)
|
)
|
||||||
self.logger.warning(msg)
|
self.logger.warning(msg)
|
||||||
return None
|
return None
|
||||||
#raise HostgroupError(msg)
|
|
||||||
|
|
||||||
def list_formatoptions(self):
|
def list_formatoptions(self):
|
||||||
"""
|
"""
|
||||||
|
@ -16,6 +16,7 @@ class VirtualMachine(PhysicalDevice):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.hostgroup = None
|
self.hostgroup = None
|
||||||
self.zbx_template_names = None
|
self.zbx_template_names = None
|
||||||
|
self.hostgroup_type = "vm"
|
||||||
|
|
||||||
def _inventory_map(self):
|
def _inventory_map(self):
|
||||||
"""use VM inventory maps"""
|
"""use VM inventory maps"""
|
||||||
@ -29,25 +30,6 @@ class VirtualMachine(PhysicalDevice):
|
|||||||
"""use VM tag maps"""
|
"""use VM tag maps"""
|
||||||
return config["vm_tag_map"]
|
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):
|
def set_vm_template(self):
|
||||||
"""Set Template for VMs. Overwrites default class
|
"""Set Template for VMs. Overwrites default class
|
||||||
to skip a lookup of custom fields."""
|
to skip a lookup of custom fields."""
|
||||||
|
Loading…
Reference in New Issue
Block a user