Updated main script with updated function names and to be valid code for ruff

This commit is contained in:
TheNetworkGuy
2026-02-11 14:31:20 +00:00
parent 18d67d5c2b
commit 9212f486bf
+8 -11
View File
@@ -115,15 +115,12 @@ def main(arguments):
else:
zabbix = ZabbixAPI(zabbix_host, token=zabbix_token, ssl_context=ssl_ctx)
zabbix.check_auth()
except (APIRequestError, ProcessingError) as e:
e = f"Zabbix returned the following error: {str(e)}"
except (APIRequestError, ProcessingError) as zbx_error:
e = f"Zabbix returned the following error: {zbx_error}."
logger.error(e)
sys.exit(1)
# Set API parameter mapping based on API version
if not str(zabbix.version).startswith("7"):
proxy_name = "host"
else:
proxy_name = "name"
proxy_name = "host" if not str(zabbix.version).startswith("7") else "name"
# Get all Zabbix and NetBox data
netbox_devices = list(netbox.dcim.devices.filter(**config["nb_device_filter"]))
netbox_vms = []
@@ -131,7 +128,7 @@ def main(arguments):
netbox_vms = list(
netbox.virtualization.virtual_machines.filter(**config["nb_vm_filter"])
)
netbox_site_groups = convert_recordset((netbox.dcim.site_groups.all()))
netbox_site_groups = convert_recordset(netbox.dcim.site_groups.all())
netbox_regions = convert_recordset(netbox.dcim.regions.all())
netbox_journals = netbox.extras.journal_entries
zabbix_groups = zabbix.hostgroup.get(output=["groupid", "name"])
@@ -212,7 +209,7 @@ def main(arguments):
)
continue
# Add VM to Zabbix
vm.createInZabbix(zabbix_groups, zabbix_templates, zabbix_proxy_list)
vm.create_in_zabbix(zabbix_groups, zabbix_templates, zabbix_proxy_list)
except SyncError:
pass
@@ -257,7 +254,7 @@ def main(arguments):
# Requires clustering variable
if device.isCluster() and config["clustering"]:
# Check if device is primary or secondary
if device.promoteMasterDevice():
if device.promote_primary_device():
logger.info(
"Device %s: is part of cluster and primary.", device.name
)
@@ -297,7 +294,7 @@ def main(arguments):
zabbix_groups.append(group)
# Check if device is already in Zabbix
if device.zabbix_id:
device.ConsistencyCheck(
device.consistency_check(
zabbix_groups,
zabbix_templates,
zabbix_proxy_list,
@@ -306,7 +303,7 @@ def main(arguments):
)
continue
# Add device to Zabbix
device.createInZabbix(zabbix_groups, zabbix_templates, zabbix_proxy_list)
device.create_in_zabbix(zabbix_groups, zabbix_templates, zabbix_proxy_list)
except SyncError:
pass
zabbix.logout()