mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-07-13 15:24:48 -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)
|
||||||
|
@ -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",
|
||||||
|
@ -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