mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-12-12 11:29:38 -06:00
corrected linting errors and a minor bug in cf_to_string
This commit is contained in:
parent
bc12064b6a
commit
c27505b927
@ -468,25 +468,25 @@ class PhysicalDevice:
|
|||||||
# Includes proxy group fix since Zabbix <= 6 should ignore this
|
# Includes proxy group fix since Zabbix <= 6 should ignore this
|
||||||
proxy_types = ["proxy"]
|
proxy_types = ["proxy"]
|
||||||
proxy_name = None
|
proxy_name = None
|
||||||
|
|
||||||
if self.zabbix.version >= 7.0:
|
if self.zabbix.version >= 7.0:
|
||||||
# Only insert groups in front of list for Zabbix7
|
# Only insert groups in front of list for Zabbix7
|
||||||
proxy_types.insert(0, "proxy_group")
|
proxy_types.insert(0, "proxy_group")
|
||||||
|
|
||||||
# loop through supported proxy-types
|
# loop through supported proxy-types
|
||||||
for proxy_type in proxy_types:
|
for proxy_type in proxy_types:
|
||||||
# Check if we should use custom fields for proxy config
|
# Check if we should use custom fields for proxy config
|
||||||
field_config = "proxy_cf" if proxy_type=="proxy" else "proxy_group_cf"
|
field_config = "proxy_cf" if proxy_type=="proxy" else "proxy_group_cf"
|
||||||
if config[field_config]:
|
if config[field_config]:
|
||||||
if config[field_config] in self.nb.custom_fields:
|
if config[field_config] in self.nb.custom_fields:
|
||||||
if self.nb.custom_fields[config[field_config]]:
|
if self.nb.custom_fields[config[field_config]]:
|
||||||
proxy_name = cf_to_string(self.nb.custom_fields[config[field_config]])
|
proxy_name = cf_to_string(self.nb.custom_fields[config[field_config]])
|
||||||
elif config[field_config] in self.nb.site.custom_fields:
|
elif config[field_config] in self.nb.site.custom_fields:
|
||||||
if self.nb.site.custom_fields[config[field_config]]:
|
if self.nb.site.custom_fields[config[field_config]]:
|
||||||
proxy_name = cf_to_string(self.nb.site.custom_fields[config[field_config]])
|
proxy_name = cf_to_string(self.nb.site.custom_fields[config[field_config]])
|
||||||
|
|
||||||
# Otherwise check if the proxy is configured in NetBox CC
|
# Otherwise check if the proxy is configured in NetBox CC
|
||||||
if (not proxy_name and "zabbix" in self.nb.config_context and
|
if (not proxy_name and "zabbix" in self.nb.config_context and
|
||||||
proxy_type in self.nb.config_context["zabbix"]):
|
proxy_type in self.nb.config_context["zabbix"]):
|
||||||
proxy_name = self.nb.config_context["zabbix"][proxy_type]
|
proxy_name = self.nb.config_context["zabbix"][proxy_type]
|
||||||
|
|
||||||
@ -503,7 +503,7 @@ class PhysicalDevice:
|
|||||||
)
|
)
|
||||||
self.zbxproxy = proxy
|
self.zbxproxy = proxy
|
||||||
return True
|
return True
|
||||||
|
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
"Host %s: unable to find proxy %s", self.name, proxy_name
|
"Host %s: unable to find proxy %s", self.name, proxy_name
|
||||||
)
|
)
|
||||||
|
|||||||
@ -55,11 +55,10 @@ def cf_to_string(cf, key="name", logger=None):
|
|||||||
Converts a dict custom fields to string
|
Converts a dict custom fields to string
|
||||||
"""
|
"""
|
||||||
if isinstance(cf, dict):
|
if isinstance(cf, dict):
|
||||||
if key:
|
if key in cf:
|
||||||
return cf[key]
|
return cf[key]
|
||||||
else:
|
logger.error("Conversion of custom field failed, '%s' not found in cf dict.", key)
|
||||||
logger.error("Conversion of custom field failed, '%s' not found in cf dict.", key)
|
return None
|
||||||
return None
|
|
||||||
return cf
|
return cf
|
||||||
|
|
||||||
|
|
||||||
@ -217,4 +216,4 @@ def sanatize_log_output(data):
|
|||||||
continue
|
continue
|
||||||
# A macro is not used, so we sanitize the value.
|
# A macro is not used, so we sanitize the value.
|
||||||
sanitized_data["details"][key] = "********"
|
sanitized_data["details"][key] = "********"
|
||||||
return sanitized_data
|
return sanitized_data
|
||||||
|
|||||||
@ -82,7 +82,7 @@ def main(arguments):
|
|||||||
device_cfs = []
|
device_cfs = []
|
||||||
vm_cfs = []
|
vm_cfs = []
|
||||||
device_cfs = list(
|
device_cfs = list(
|
||||||
netbox.extras.custom_fields.filter(type=["text","object","select"],
|
netbox.extras.custom_fields.filter(type=["text","object","select"],
|
||||||
content_types="dcim.device")
|
content_types="dcim.device")
|
||||||
)
|
)
|
||||||
verify_hg_format(
|
verify_hg_format(
|
||||||
@ -91,7 +91,7 @@ def main(arguments):
|
|||||||
if config["sync_vms"]:
|
if config["sync_vms"]:
|
||||||
vm_cfs = list(
|
vm_cfs = list(
|
||||||
netbox.extras.custom_fields.filter(
|
netbox.extras.custom_fields.filter(
|
||||||
type=["text","object","select"],
|
type=["text","object","select"],
|
||||||
content_types="virtualization.virtualmachine"
|
content_types="virtualization.virtualmachine"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user