mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-07-13 15:24:48 -06:00
Fixed several config errors, double exception imports, Linter stuff and edited test for new device_inventory_map key
This commit is contained in:
parent
9e1a90833d
commit
a325863aec
@ -124,8 +124,8 @@ class PhysicalDevice:
|
|||||||
self.nb,
|
self.nb,
|
||||||
self.nb_api_version,
|
self.nb_api_version,
|
||||||
logger=self.logger,
|
logger=self.logger,
|
||||||
nested_sitegroup_flag=traverse_site_groups,
|
nested_sitegroup_flag=config['traverse_site_groups'],
|
||||||
nested_region_flag=traverse_regions,
|
nested_region_flag=config['traverse_regions'],
|
||||||
nb_groups=nb_site_groups,
|
nb_groups=nb_site_groups,
|
||||||
nb_regions=nb_regions,
|
nb_regions=nb_regions,
|
||||||
)
|
)
|
||||||
@ -166,7 +166,7 @@ class PhysicalDevice:
|
|||||||
return [device_type_cfs[config["template_cf"]]]
|
return [device_type_cfs[config["template_cf"]]]
|
||||||
# Custom field not found, return error
|
# Custom field not found, return error
|
||||||
e = (
|
e = (
|
||||||
f"Custom field {template_cf} not "
|
f"Custom field {config['template_cf']} not "
|
||||||
f"found for {self.nb.device_type.manufacturer.name}"
|
f"found for {self.nb.device_type.manufacturer.name}"
|
||||||
f" - {self.nb.device_type.display}."
|
f" - {self.nb.device_type.display}."
|
||||||
)
|
)
|
||||||
@ -394,7 +394,7 @@ class PhysicalDevice:
|
|||||||
macros = ZabbixUsermacros(
|
macros = ZabbixUsermacros(
|
||||||
self.nb,
|
self.nb,
|
||||||
self._usermacro_map(),
|
self._usermacro_map(),
|
||||||
usermacro_sync,
|
config['usermacro_sync'],
|
||||||
logger=self.logger,
|
logger=self.logger,
|
||||||
host=self.name,
|
host=self.name,
|
||||||
)
|
)
|
||||||
@ -411,10 +411,10 @@ class PhysicalDevice:
|
|||||||
tags = ZabbixTags(
|
tags = ZabbixTags(
|
||||||
self.nb,
|
self.nb,
|
||||||
self._tag_map(),
|
self._tag_map(),
|
||||||
tag_sync,
|
config['tag_sync'],
|
||||||
tag_lower,
|
config['tag_lower'],
|
||||||
tag_name=tag_name,
|
tag_name=config['tag_name'],
|
||||||
tag_value=tag_value,
|
tag_value=config['tag_value'],
|
||||||
logger=self.logger,
|
logger=self.logger,
|
||||||
host=self.name,
|
host=self.name,
|
||||||
)
|
)
|
||||||
@ -771,15 +771,11 @@ class PhysicalDevice:
|
|||||||
self.updateZabbixHost(inventory=self.inventory)
|
self.updateZabbixHost(inventory=self.inventory)
|
||||||
|
|
||||||
# Check host usermacros
|
# Check host usermacros
|
||||||
if usermacro_sync:
|
if config['usermacro_sync']:
|
||||||
macros_filtered = []
|
macros_filtered = []
|
||||||
# Do not re-sync secret usermacros unless sync is set to 'full'
|
# Do not re-sync secret usermacros unless sync is set to 'full'
|
||||||
if str(usermacro_sync).lower() != "full":
|
if str(config['usermacro_sync']).lower() != "full":
|
||||||
for m in
|
for m in deepcopy(self.usermacros):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(self.usermacros):
|
|
||||||
if m["type"] == str(1):
|
if m["type"] == str(1):
|
||||||
# Remove the value as the api doesn't return it
|
# Remove the value as the api doesn't return it
|
||||||
# this will allow us to only update usermacros that don't exist
|
# this will allow us to only update usermacros that don't exist
|
||||||
@ -792,7 +788,7 @@ class PhysicalDevice:
|
|||||||
self.updateZabbixHost(macros=self.usermacros)
|
self.updateZabbixHost(macros=self.usermacros)
|
||||||
|
|
||||||
# Check host usermacros
|
# Check host usermacros
|
||||||
if tag_sync:
|
if config['tag_sync']:
|
||||||
if remove_duplicates(host["tags"], sortkey="tag") == self.tags:
|
if remove_duplicates(host["tags"], sortkey="tag") == self.tags:
|
||||||
self.logger.debug(f"Host {self.name}: tags in-sync.")
|
self.logger.debug(f"Host {self.name}: tags in-sync.")
|
||||||
else:
|
else:
|
||||||
|
@ -4,9 +4,6 @@ from modules.device import PhysicalDevice
|
|||||||
from modules.exceptions import InterfaceConfigError, SyncInventoryError, TemplateError
|
from modules.exceptions import InterfaceConfigError, SyncInventoryError, TemplateError
|
||||||
from modules.hostgroups import Hostgroup
|
from modules.hostgroups import Hostgroup
|
||||||
from modules.interface import ZabbixInterface
|
from modules.interface import ZabbixInterface
|
||||||
|
|
||||||
from modules.exceptions import (TemplateError, InterfaceConfigError,
|
|
||||||
SyncInventoryError)
|
|
||||||
from modules.config import load_config
|
from modules.config import load_config
|
||||||
# Load config
|
# Load config
|
||||||
config = load_config()
|
config = load_config()
|
||||||
@ -22,15 +19,15 @@ class VirtualMachine(PhysicalDevice):
|
|||||||
|
|
||||||
def _inventory_map(self):
|
def _inventory_map(self):
|
||||||
"""use VM inventory maps"""
|
"""use VM inventory maps"""
|
||||||
return vm_inventory_map
|
return config["vm_inventory_map"]
|
||||||
|
|
||||||
def _usermacro_map(self):
|
def _usermacro_map(self):
|
||||||
"""use VM usermacro maps"""
|
"""use VM usermacro maps"""
|
||||||
return vm_usermacro_map
|
return config["vm_usermacro_map"]
|
||||||
|
|
||||||
def _tag_map(self):
|
def _tag_map(self):
|
||||||
"""use VM tag maps"""
|
"""use VM tag maps"""
|
||||||
return vm_tag_map
|
return config["vm_tag_map"]
|
||||||
|
|
||||||
def set_hostgroup(self, hg_format, nb_site_groups, nb_regions):
|
def set_hostgroup(self, hg_format, nb_site_groups, nb_regions):
|
||||||
"""Set the hostgroup for this device"""
|
"""Set the hostgroup for this device"""
|
||||||
@ -40,8 +37,8 @@ class VirtualMachine(PhysicalDevice):
|
|||||||
self.nb,
|
self.nb,
|
||||||
self.nb_api_version,
|
self.nb_api_version,
|
||||||
logger=self.logger,
|
logger=self.logger,
|
||||||
nested_sitegroup_flag=traverse_site_groups,
|
nested_sitegroup_flag=config["traverse_site_groups"],
|
||||||
nested_region_flag=traverse_regions,
|
nested_region_flag=config["traverse_regions"],
|
||||||
nb_groups=nb_site_groups,
|
nb_groups=nb_site_groups,
|
||||||
nb_regions=nb_regions,
|
nb_regions=nb_regions,
|
||||||
)
|
)
|
||||||
|
@ -43,7 +43,7 @@ class TestPhysicalDevice(unittest.TestCase):
|
|||||||
"traverse_site_groups": False,
|
"traverse_site_groups": False,
|
||||||
"inventory_mode": "disabled",
|
"inventory_mode": "disabled",
|
||||||
"inventory_sync": False,
|
"inventory_sync": False,
|
||||||
"inventory_map": {}
|
"device_inventory_map": {}
|
||||||
}):
|
}):
|
||||||
self.device = PhysicalDevice(
|
self.device = PhysicalDevice(
|
||||||
self.mock_nb_device,
|
self.mock_nb_device,
|
||||||
@ -303,7 +303,7 @@ class TestPhysicalDevice(unittest.TestCase):
|
|||||||
"device_cf": "zabbix_hostid",
|
"device_cf": "zabbix_hostid",
|
||||||
"inventory_mode": "manual",
|
"inventory_mode": "manual",
|
||||||
"inventory_sync": True,
|
"inventory_sync": True,
|
||||||
"inventory_map": {
|
"device_inventory_map": {
|
||||||
"name": "name",
|
"name": "name",
|
||||||
"serial": "serialno_a"
|
"serial": "serialno_a"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user