enhances NetBox version detection #446

This commit is contained in:
Ricardo Bartels
2025-03-20 22:41:53 +01:00
parent 2e4c0f3163
commit 92711a92ed
+16 -2
View File
@@ -196,15 +196,29 @@ class NetBoxHandler:
str: NetBox API version
"""
response = None
result = None
try:
response = self.session.get(
self.url,
f"{self.url}/status",
timeout=self.settings.timeout,
verify=self.settings.validate_tls_certs)
except Exception as e:
do_error_exit(f"NetBox connection: {e}")
result = str(response.headers.get("API-Version"))
# noinspection PyBroadException
try:
result = grab(response.json(), "netbox-version").split("-")[0]
except Exception:
pass
if not isinstance(result, str):
result = str(response.headers.get("API-Version"))
try:
version.parse(result)
except Exception as e:
do_error_exit(f"Unable to parse NetBox version '{result}': {e}")
log.info(f"Successfully connected to NetBox '{self.settings.host_fqdn}'")
log.debug(f"Detected NetBox API version: {result}")