Skip to content
Snippets Groups Projects

Feature/add validation workflows

Merged Karel van Klink requested to merge feature/add-validation-workflows into develop
All threads resolved!
Compare and Show latest version
5 files
+ 58
67
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -91,22 +91,26 @@ class LibreNMSClient:
return device.json()
def validate_device(self, fqdn: str) -> list[str]:
def validate_device(self, fqdn: str) -> str | None:
"""Validate a device in LibreNMS by fetching the record match the queried :term:`FQDN` against its hostname.
:param str fqdn: The :term:`FQDN` of the host that is validated.
:return list[str]: A list of errors, if empty the device is successfully validated.
"""
errors = []
error = None
try:
device = self.get_device(fqdn)
received_hostname = device["devices"][0]["hostname"]
if device["devices"][0]["hostname"] != fqdn:
errors += ["Device hostname in LibreNMS does not match FQDN."]
if received_hostname != fqdn:
error = (
f"Device hostname in LibreNMS does not match FQDN.\n"
f"Expected '{fqdn}' but got '{received_hostname}'."
)
except HTTPError as e:
if e.response.status_code == HTTPStatus.NOT_FOUND:
errors += ["Device does not exist in LibreNMS."]
error = "Device does not exist in LibreNMS."
else:
raise
return errors
return error
Loading