mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-07-13 07:24:47 -06:00
corrected linting errors
This commit is contained in:
parent
a3259c4fe3
commit
ba530ecd58
@ -320,7 +320,10 @@ class PhysicalDevice:
|
|||||||
for group in groups:
|
for group in groups:
|
||||||
if group["name"] == hg:
|
if group["name"] == hg:
|
||||||
self.group_ids.append({"groupid": group["groupid"]})
|
self.group_ids.append({"groupid": group["groupid"]})
|
||||||
e = f"Host {self.name}: matched group \"{group['name']}\" (ID:{group['groupid']})"
|
e = (
|
||||||
|
f"Host {self.name}: matched group "
|
||||||
|
f"\"{group['name']}\" (ID:{group['groupid']})"
|
||||||
|
)
|
||||||
self.logger.debug(e)
|
self.logger.debug(e)
|
||||||
if len(self.group_ids) == len(self.hostgroups):
|
if len(self.group_ids) == len(self.hostgroups):
|
||||||
return True
|
return True
|
||||||
@ -500,7 +503,6 @@ class PhysicalDevice:
|
|||||||
templateids.append({"templateid": template["templateid"]})
|
templateids.append({"templateid": template["templateid"]})
|
||||||
# Set interface, group and template configuration
|
# Set interface, group and template configuration
|
||||||
interfaces = self.setInterfaceDetails()
|
interfaces = self.setInterfaceDetails()
|
||||||
|
|
||||||
groups = self.group_ids
|
groups = self.group_ids
|
||||||
# Set Zabbix proxy if defined
|
# Set Zabbix proxy if defined
|
||||||
self.setProxy(proxies)
|
self.setProxy(proxies)
|
||||||
@ -702,9 +704,9 @@ class PhysicalDevice:
|
|||||||
if str(self.zabbix.version).startswith(("6", "5")):
|
if str(self.zabbix.version).startswith(("6", "5")):
|
||||||
group_dictname = "groups"
|
group_dictname = "groups"
|
||||||
# Check if hostgroups match
|
# Check if hostgroups match
|
||||||
if (sorted(host[group_dictname], key=itemgetter('groupid')) ==
|
if (sorted(host[group_dictname], key=itemgetter('groupid')) ==
|
||||||
sorted(self.group_ids, key=itemgetter('groupid'))):
|
sorted(self.group_ids, key=itemgetter('groupid'))):
|
||||||
self.logger.debug(f"Host {self.name}: hostgroups in-sync.")
|
self.logger.debug(f"Host {self.name}: hostgroups in-sync.")
|
||||||
else:
|
else:
|
||||||
self.logger.warning(f"Host {self.name}: hostgroups OUT of sync.")
|
self.logger.warning(f"Host {self.name}: hostgroups OUT of sync.")
|
||||||
self.updateZabbixHost(groups=self.group_ids)
|
self.updateZabbixHost(groups=self.group_ids)
|
||||||
|
@ -101,10 +101,14 @@ def remove_duplicates(input_list, sortkey=None):
|
|||||||
return output_list
|
return output_list
|
||||||
|
|
||||||
|
|
||||||
def verify_hg_format(hg_format, device_cfs=[], vm_cfs=[], hg_type="dev", logger=None):
|
def verify_hg_format(hg_format, device_cfs=None, vm_cfs=None, hg_type="dev", logger=None):
|
||||||
"""
|
"""
|
||||||
Verifies hostgroup field format
|
Verifies hostgroup field format
|
||||||
"""
|
"""
|
||||||
|
if not device_cfs:
|
||||||
|
device_cfs = []
|
||||||
|
if not vm_cfs:
|
||||||
|
vm_cfs = []
|
||||||
allowed_objects = {"dev": ["location",
|
allowed_objects = {"dev": ["location",
|
||||||
"rack",
|
"rack",
|
||||||
"role",
|
"role",
|
||||||
@ -130,9 +134,9 @@ def verify_hg_format(hg_format, device_cfs=[], vm_cfs=[], hg_type="dev", logger=
|
|||||||
,"cfs": {"dev": [], "vm": []}
|
,"cfs": {"dev": [], "vm": []}
|
||||||
}
|
}
|
||||||
for cf in device_cfs:
|
for cf in device_cfs:
|
||||||
allowed_objects['cfs']['dev'].append(cf.name)
|
allowed_objects['cfs']['dev'].append(cf.name)
|
||||||
for cf in vm_cfs:
|
for cf in vm_cfs:
|
||||||
allowed_objects['cfs']['vm'].append(cf.name)
|
allowed_objects['cfs']['vm'].append(cf.name)
|
||||||
hg_objects = []
|
hg_objects = []
|
||||||
if isinstance(hg_format,list):
|
if isinstance(hg_format,list):
|
||||||
for f in hg_format:
|
for f in hg_format:
|
||||||
@ -185,4 +189,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
|
||||||
|
@ -83,12 +83,14 @@ def main(arguments):
|
|||||||
device_cfs = list(
|
device_cfs = list(
|
||||||
netbox.extras.custom_fields.filter(type="text", content_types="dcim.device")
|
netbox.extras.custom_fields.filter(type="text", content_types="dcim.device")
|
||||||
)
|
)
|
||||||
verify_hg_format(hostgroup_format, device_cfs=device_cfs, hg_type="dev", logger=logger)
|
verify_hg_format(config["hostgroup_format"],
|
||||||
if sync_vms:
|
device_cfs=device_cfs, hg_type="dev", logger=logger)
|
||||||
|
if config["sync_vms"]:
|
||||||
vm_cfs = list(
|
vm_cfs = list(
|
||||||
netbox.extras.custom_fields.filter(type="text", content_types="virtualization.virtualmachine")
|
netbox.extras.custom_fields.filter(type="text",
|
||||||
|
content_types="virtualization.virtualmachine")
|
||||||
)
|
)
|
||||||
verify_hg_format(vm_hostgroup_format, vm_cfs=vm_cfs, hg_type="vm", logger=logger)
|
verify_hg_format(config["vm_hostgroup_format"], vm_cfs=vm_cfs, hg_type="vm", logger=logger)
|
||||||
# Set Zabbix API
|
# Set Zabbix API
|
||||||
try:
|
try:
|
||||||
ssl_ctx = ssl.create_default_context()
|
ssl_ctx = ssl.create_default_context()
|
||||||
@ -173,7 +175,7 @@ def main(arguments):
|
|||||||
if vm.status in config["zabbix_device_disable"]:
|
if vm.status in config["zabbix_device_disable"]:
|
||||||
vm.zabbix_state = 1
|
vm.zabbix_state = 1
|
||||||
# Add hostgroup if config is set
|
# Add hostgroup if config is set
|
||||||
if create_hostgroups:
|
if config["create_hostgroups"]:
|
||||||
# Create new hostgroup. Potentially multiple groups if nested
|
# Create new hostgroup. Potentially multiple groups if nested
|
||||||
hostgroups = vm.createZabbixHostgroup(zabbix_groups)
|
hostgroups = vm.createZabbixHostgroup(zabbix_groups)
|
||||||
# go through all newly created hostgroups
|
# go through all newly created hostgroups
|
||||||
@ -249,7 +251,7 @@ def main(arguments):
|
|||||||
if device.status in config["zabbix_device_disable"]:
|
if device.status in config["zabbix_device_disable"]:
|
||||||
device.zabbix_state = 1
|
device.zabbix_state = 1
|
||||||
# Add hostgroup is config is set
|
# Add hostgroup is config is set
|
||||||
if create_hostgroups:
|
if config["create_hostgroups"]:
|
||||||
# Create new hostgroup. Potentially multiple groups if nested
|
# Create new hostgroup. Potentially multiple groups if nested
|
||||||
hostgroups = device.createZabbixHostgroup(zabbix_groups)
|
hostgroups = device.createZabbixHostgroup(zabbix_groups)
|
||||||
# go through all newly created hostgroups
|
# go through all newly created hostgroups
|
||||||
|
Loading…
Reference in New Issue
Block a user