mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-07-16 20:22:56 -06:00
Corrected linting errors
This commit is contained in:
parent
5b08d27a5e
commit
fbb9eeb48c
@ -62,16 +62,16 @@ def build_path(endpoint, list_of_dicts):
|
|||||||
This can be used to generate a joinable list to
|
This can be used to generate a joinable list to
|
||||||
be used in hostgroups.
|
be used in hostgroups.
|
||||||
"""
|
"""
|
||||||
path = []
|
item_path = []
|
||||||
itemlist = [i for i in list_of_dicts if i['name'] == endpoint]
|
itemlist = [i for i in list_of_dicts if i['name'] == endpoint]
|
||||||
item = itemlist[0] if len(itemlist) == 1 else None
|
item = itemlist[0] if len(itemlist) == 1 else None
|
||||||
path.append(item['name'])
|
item_path.append(item['name'])
|
||||||
while item['_depth'] > 0:
|
while item['_depth'] > 0:
|
||||||
itemlist = [i for i in list_of_dicts if i['name'] == str(item['parent'])]
|
itemlist = [i for i in list_of_dicts if i['name'] == str(item['parent'])]
|
||||||
item = itemlist[0] if len(itemlist) == 1 else None
|
item = itemlist[0] if len(itemlist) == 1 else None
|
||||||
path.append(item['name'])
|
item_path.append(item['name'])
|
||||||
path.reverse()
|
item_path.reverse()
|
||||||
return(path)
|
return item_path
|
||||||
|
|
||||||
def main(arguments):
|
def main(arguments):
|
||||||
"""Run the sync process."""
|
"""Run the sync process."""
|
||||||
@ -327,11 +327,11 @@ class NetworkDevice():
|
|||||||
continue
|
continue
|
||||||
# Add value of predefined variable to hostgroup format
|
# Add value of predefined variable to hostgroup format
|
||||||
if item == "site_group" and nb_site_groups and traverse_site_groups:
|
if item == "site_group" and nb_site_groups and traverse_site_groups:
|
||||||
path = build_path(site_group, nb_site_groups)
|
group_path = build_path(site_group, nb_site_groups)
|
||||||
hostgroup += "/".join(path) + "/"
|
hostgroup += "/".join(group_path) + "/"
|
||||||
elif item == "region" and nb_regions and traverse_regions:
|
elif item == "region" and nb_regions and traverse_regions:
|
||||||
path = build_path(region, nb_regions)
|
region_path = build_path(region, nb_regions)
|
||||||
hostgroup += "/".join(path) + "/"
|
hostgroup += "/".join(region_path) + "/"
|
||||||
else:
|
else:
|
||||||
hostgroup += hostgroup_vars[item] + "/"
|
hostgroup += hostgroup_vars[item] + "/"
|
||||||
# If the final hostgroup variable is empty
|
# If the final hostgroup variable is empty
|
||||||
@ -388,8 +388,8 @@ class NetworkDevice():
|
|||||||
f"context for template host {self.name}")
|
f"context for template host {self.name}")
|
||||||
raise TemplateError(e)
|
raise TemplateError(e)
|
||||||
if "templates" not in self.config_context["zabbix"]:
|
if "templates" not in self.config_context["zabbix"]:
|
||||||
e = ("Key 'zabbix' not found in config "
|
e = ("Key 'templates' not found in config "
|
||||||
f"context for template host {self.name}")
|
f"context 'zabbix' for template host {self.name}")
|
||||||
raise TemplateError(e)
|
raise TemplateError(e)
|
||||||
return self.config_context["zabbix"]["templates"]
|
return self.config_context["zabbix"]["templates"]
|
||||||
|
|
||||||
@ -411,12 +411,12 @@ class NetworkDevice():
|
|||||||
if nb_value and isinstance(nb_value, int | float | str ):
|
if nb_value and isinstance(nb_value, int | float | str ):
|
||||||
self.inventory[zbx_inv_field] = str(nb_value)
|
self.inventory[zbx_inv_field] = str(nb_value)
|
||||||
elif not nb_value:
|
elif not nb_value:
|
||||||
logger.debug('Inventory lookup for "%s" returned an empty value' % nb_inv_field)
|
logger.debug(f"Inventory lookup for '{nb_inv_field}' returned an empty value")
|
||||||
self.inventory[zbx_inv_field] = ""
|
self.inventory[zbx_inv_field] = ""
|
||||||
else:
|
else:
|
||||||
# Value is not a string or numeral, probably not what the user expected.
|
# Value is not a string or numeral, probably not what the user expected.
|
||||||
logger.error('Inventory lookup for "%s" returned an unexpected type,'
|
logger.error(f"Inventory lookup for '{nb_inv_field}' returned an unexpected type: "
|
||||||
' it will be skipped.' % nb_inv_field)
|
f"it will be skipped.")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def isCluster(self):
|
def isCluster(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user