Fixed some minor Flake8 errors

This commit is contained in:
TheNetworkGuy 2025-04-28 15:10:48 +02:00
parent e91eecffaa
commit 04a610cf84

View File

@ -157,7 +157,8 @@ class PhysicalDevice():
if config["inventory_mode"] == "disabled": if config["inventory_mode"] == "disabled":
if config["inventory_sync"]: if config["inventory_sync"]:
self.logger.error(f"Host {self.name}: Unable to map NetBox inventory to Zabbix. " self.logger.error(f"Host {self.name}: Unable to map NetBox inventory to Zabbix. "
"Inventory sync is enabled in config but inventory mode is disabled.") "Inventory sync is enabled in "
"config but inventory mode is disabled.")
return True return True
if config["inventory_mode"] == "manual": if config["inventory_mode"] == "manual":
self.inventory_mode = 0 self.inventory_mode = 0
@ -359,7 +360,7 @@ class PhysicalDevice():
if "zabbix" not in self.nb.config_context: if "zabbix" not in self.nb.config_context:
return False return False
if ("proxy" in self.nb.config_context["zabbix"] and if ("proxy" in self.nb.config_context["zabbix"] and
not self.nb.config_context["zabbix"]["proxy"]): not self.nb.config_context["zabbix"]["proxy"]):
return False return False
# Proxy group takes priority over a proxy due # Proxy group takes priority over a proxy due
# to it being HA and therefore being more reliable # to it being HA and therefore being more reliable
@ -409,16 +410,17 @@ class PhysicalDevice():
# Set Zabbix proxy if defined # Set Zabbix proxy if defined
self.setProxy(proxies) self.setProxy(proxies)
# Set basic data for host creation # Set basic data for host creation
create_data = {"host": self.name, create_data = {
"name": self.visible_name, "host": self.name,
"status": self.zabbix_state, "name": self.visible_name,
"interfaces": interfaces, "status": self.zabbix_state,
"groups": groups, "interfaces": interfaces,
"templates": templateids, "groups": groups,
"description": description, "templates": templateids,
"inventory_mode": self.inventory_mode, "description": description,
"inventory": self.inventory "inventory_mode": self.inventory_mode,
} "inventory": self.inventory
}
# If a Zabbix proxy or Zabbix Proxy group has been defined # If a Zabbix proxy or Zabbix Proxy group has been defined
if self.zbxproxy: if self.zbxproxy:
# If a lower version than 7 is used, we can assume that # If a lower version than 7 is used, we can assume that
@ -518,7 +520,7 @@ class PhysicalDevice():
# Function returns true / false but also sets GroupID # Function returns true / false but also sets GroupID
if not self.setZabbixGroupID(groups) and not create_hostgroups: if not self.setZabbixGroupID(groups) and not create_hostgroups:
e = (f"Host {self.name}: different hostgroup is required but " e = (f"Host {self.name}: different hostgroup is required but "
"unable to create hostgroup without generation permission.") "unable to create hostgroup without generation permission.")
self.logger.warning(e) self.logger.warning(e)
raise SyncInventoryError(e) raise SyncInventoryError(e)
# Prepare templates and proxy config # Prepare templates and proxy config
@ -569,7 +571,7 @@ class PhysicalDevice():
templateids.append({'templateid': template['templateid']}) templateids.append({'templateid': template['templateid']})
# Update Zabbix with NB templates and clear any old / lost templates # Update Zabbix with NB templates and clear any old / lost templates
self.updateZabbixHost(templates_clear=host["parentTemplates"], self.updateZabbixHost(templates_clear=host["parentTemplates"],
templates=templateids) templates=templateids)
else: else:
self.logger.debug(f"Host {self.name}: template(s) in-sync.") self.logger.debug(f"Host {self.name}: template(s) in-sync.")
@ -594,7 +596,7 @@ class PhysicalDevice():
if self.zbxproxy: if self.zbxproxy:
# Check if proxy or proxy group is defined # Check if proxy or proxy group is defined
if (self.zbxproxy["idtype"] in host and if (self.zbxproxy["idtype"] in host and
host[self.zbxproxy["idtype"]] == self.zbxproxy["id"]): host[self.zbxproxy["idtype"]] == self.zbxproxy["id"]):
self.logger.debug(f"Host {self.name}: proxy in-sync.") self.logger.debug(f"Host {self.name}: proxy in-sync.")
# Backwards compatibility for Zabbix <= 6 # Backwards compatibility for Zabbix <= 6
elif "proxy_hostid" in host and host["proxy_hostid"] == self.zbxproxy["id"]: elif "proxy_hostid" in host and host["proxy_hostid"] == self.zbxproxy["id"]:
@ -646,7 +648,7 @@ class PhysicalDevice():
else: else:
self.logger.warning(f"Host {self.name}: inventory_mode OUT of sync.") self.logger.warning(f"Host {self.name}: inventory_mode OUT of sync.")
self.updateZabbixHost(inventory_mode=str(self.inventory_mode)) self.updateZabbixHost(inventory_mode=str(self.inventory_mode))
if config["inventory_sync"] and self.inventory_mode in [0,1]: if config["inventory_sync"] and self.inventory_mode in [0, 1]:
# Check host inventory mapping # Check host inventory mapping
if host['inventory'] == self.inventory: if host['inventory'] == self.inventory:
self.logger.debug(f"Host {self.name}: inventory in-sync.") self.logger.debug(f"Host {self.name}: inventory in-sync.")
@ -664,7 +666,7 @@ class PhysicalDevice():
if key in host["interfaces"][0]: if key in host["interfaces"][0]:
# If SNMP is used, go through nested dict # If SNMP is used, go through nested dict
# to compare SNMP parameters # to compare SNMP parameters
if isinstance(item,dict) and key == "details": if isinstance(item, dict) and key == "details":
for k, i in item.items(): for k, i in item.items():
if k in host["interfaces"][0][key]: if k in host["interfaces"][0][key]:
# Set update if values don't match # Set update if values don't match