mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-12-11 19:09:39 -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
|
||||
proxy_types = ["proxy"]
|
||||
proxy_name = None
|
||||
|
||||
|
||||
if self.zabbix.version >= 7.0:
|
||||
# Only insert groups in front of list for Zabbix7
|
||||
proxy_types.insert(0, "proxy_group")
|
||||
|
||||
# loop through supported proxy-types
|
||||
# loop through supported proxy-types
|
||||
for proxy_type in proxy_types:
|
||||
# Check if we should use custom fields for proxy config
|
||||
field_config = "proxy_cf" if proxy_type=="proxy" else "proxy_group_cf"
|
||||
if config[field_config]:
|
||||
field_config = "proxy_cf" if proxy_type=="proxy" else "proxy_group_cf"
|
||||
if config[field_config]:
|
||||
if config[field_config] in self.nb.custom_fields:
|
||||
if 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:
|
||||
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
|
||||
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_name = self.nb.config_context["zabbix"][proxy_type]
|
||||
|
||||
@ -503,7 +503,7 @@ class PhysicalDevice:
|
||||
)
|
||||
self.zbxproxy = proxy
|
||||
return True
|
||||
|
||||
|
||||
self.logger.warning(
|
||||
"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
|
||||
"""
|
||||
if isinstance(cf, dict):
|
||||
if key:
|
||||
if key in cf:
|
||||
return cf[key]
|
||||
else:
|
||||
logger.error("Conversion of custom field failed, '%s' not found in cf dict.", key)
|
||||
return None
|
||||
logger.error("Conversion of custom field failed, '%s' not found in cf dict.", key)
|
||||
return None
|
||||
return cf
|
||||
|
||||
|
||||
@ -217,4 +216,4 @@ def sanatize_log_output(data):
|
||||
continue
|
||||
# A macro is not used, so we sanitize the value.
|
||||
sanitized_data["details"][key] = "********"
|
||||
return sanitized_data
|
||||
return sanitized_data
|
||||
|
||||
@ -82,7 +82,7 @@ def main(arguments):
|
||||
device_cfs = []
|
||||
vm_cfs = []
|
||||
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")
|
||||
)
|
||||
verify_hg_format(
|
||||
@ -91,7 +91,7 @@ def main(arguments):
|
||||
if config["sync_vms"]:
|
||||
vm_cfs = list(
|
||||
netbox.extras.custom_fields.filter(
|
||||
type=["text","object","select"],
|
||||
type=["text","object","select"],
|
||||
content_types="virtualization.virtualmachine"
|
||||
)
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user