feature: Add editable hostname and operating system
Release / Build and Push Docker Image (push) Successful in 4m56s

This commit is contained in:
Keith Solomon
2026-04-14 07:42:39 -05:00
parent 1d9e98872c
commit d10e533793
8 changed files with 192 additions and 7 deletions
+33 -2
View File
@@ -238,7 +238,12 @@ def fetch_devices() -> list[dict]:
with get_conn() as conn:
rows = conn.execute(
"""
SELECT id, ip, hostname, os_name, mac, vendor, is_active, first_seen, last_seen
SELECT id, ip,
COALESCE(custom_hostname, hostname) AS hostname,
COALESCE(custom_os_name, os_name) AS os_name,
custom_hostname,
custom_os_name,
mac, vendor, is_active, first_seen, last_seen
FROM devices
ORDER BY is_active DESC, ip ASC
"""
@@ -250,7 +255,14 @@ def fetch_device(device_id: int) -> dict | None:
with get_conn() as conn:
device = conn.execute(
"""
SELECT id, ip, hostname, os_name, mac, vendor, is_active, first_seen, last_seen
SELECT id, ip,
COALESCE(custom_hostname, hostname) AS hostname,
COALESCE(custom_os_name, os_name) AS os_name,
custom_hostname,
custom_os_name,
hostname AS detected_hostname,
os_name AS detected_os_name,
mac, vendor, is_active, first_seen, last_seen
FROM devices
WHERE id = ?
""",
@@ -282,6 +294,25 @@ def fetch_device(device_id: int) -> dict | None:
return result
def update_device_identity(device_id: int, hostname: str | None, os_name: str | None) -> dict | None:
normalized_hostname = (hostname or "").strip() or None
normalized_os_name = (os_name or "").strip() or None
with get_conn() as conn:
updated = conn.execute(
"""
UPDATE devices
SET custom_hostname = ?, custom_os_name = ?
WHERE id = ?
""",
(normalized_hostname, normalized_os_name, device_id),
)
if updated.rowcount == 0:
return None
return fetch_device(device_id)
def fetch_scans(limit: int = 20) -> list[dict]:
with get_conn() as conn:
rows = conn.execute(