Relocate baseline config to administration subtabs, refine nav row, and add live CPU and RAM reporting
CI Test Suite / Run Component Tests & Pipeline Verification (push) Successful in 2m12s
CI Test Suite / Run Component Tests & Pipeline Verification (push) Successful in 2m12s
This commit is contained in:
+37
-12
@@ -62,7 +62,8 @@ try:
|
||||
WindowsLogCollector,
|
||||
LinuxLogCollector,
|
||||
get_log_collector,
|
||||
is_routine_service_noise
|
||||
is_routine_service_noise,
|
||||
collect_system_metrics
|
||||
)
|
||||
except ImportError:
|
||||
from log_collector import (
|
||||
@@ -70,7 +71,8 @@ except ImportError:
|
||||
WindowsLogCollector,
|
||||
LinuxLogCollector,
|
||||
get_log_collector,
|
||||
is_routine_service_noise
|
||||
is_routine_service_noise,
|
||||
collect_system_metrics
|
||||
)
|
||||
|
||||
# Import specialized modular components
|
||||
@@ -1042,6 +1044,16 @@ def run_local_log_collection_cycle(db_path: str, window_hours: int = 12, min_run
|
||||
except Exception:
|
||||
inv = {}
|
||||
|
||||
try:
|
||||
metrics = collect_system_metrics() if "collect_system_metrics" in globals() else {}
|
||||
except Exception:
|
||||
metrics = {}
|
||||
|
||||
cpu_p = float(metrics.get("cpu_percent", 0.0))
|
||||
mem_p = float(metrics.get("memory_percent", 0.0))
|
||||
disk_p = float(metrics.get("disk_percent_free", inv.get("disk_percent_free", 0.0)))
|
||||
metrics_json = json.dumps(metrics) if metrics else "{}"
|
||||
|
||||
machine_id = get_machine_identifier()
|
||||
os_type = inv.get("os_type", "windows" if sys.platform == "win32" else "linux")
|
||||
os_name = inv.get("os_name", "")
|
||||
@@ -1059,9 +1071,11 @@ def run_local_log_collection_cycle(db_path: str, window_hours: int = 12, min_run
|
||||
c.execute("""
|
||||
UPDATE clients
|
||||
SET hostname = ?, os_type = ?, cert_fingerprint = 'LOCAL-HOST-BUILTIN', status = 'active', last_seen = ?,
|
||||
os_name = ?, is_server = ?, server_roles = ?, client_info_json = ?
|
||||
os_name = ?, is_server = ?, server_roles = ?, client_info_json = ?,
|
||||
cpu_percent = ?, memory_percent = ?, disk_percent_free = ?, metrics_json = ?
|
||||
WHERE client_id = ?
|
||||
""", (machine_id, os_type, now_sql, os_name, is_server, server_roles, client_info_json, machine_id))
|
||||
""", (machine_id, os_type, now_sql, os_name, is_server, server_roles, client_info_json,
|
||||
cpu_p, mem_p, disk_p, metrics_json, machine_id))
|
||||
except sqlite3.OperationalError:
|
||||
c.execute("""
|
||||
UPDATE clients
|
||||
@@ -1071,9 +1085,10 @@ def run_local_log_collection_cycle(db_path: str, window_hours: int = 12, min_run
|
||||
else:
|
||||
try:
|
||||
c.execute("""
|
||||
INSERT INTO clients (client_id, hostname, os_type, cert_fingerprint, status, first_seen, last_seen, os_name, is_server, server_roles, client_info_json)
|
||||
VALUES (?, ?, ?, 'LOCAL-HOST-BUILTIN', 'active', ?, ?, ?, ?, ?, ?)
|
||||
""", (machine_id, machine_id, os_type, now_sql, now_sql, os_name, is_server, server_roles, client_info_json))
|
||||
INSERT INTO clients (client_id, hostname, os_type, cert_fingerprint, status, first_seen, last_seen, os_name, is_server, server_roles, client_info_json, cpu_percent, memory_percent, disk_percent_free, metrics_json)
|
||||
VALUES (?, ?, ?, 'LOCAL-HOST-BUILTIN', 'active', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""", (machine_id, machine_id, os_type, now_sql, now_sql, os_name, is_server, server_roles, client_info_json,
|
||||
cpu_p, mem_p, disk_p, metrics_json))
|
||||
except sqlite3.OperationalError:
|
||||
c.execute("""
|
||||
INSERT INTO clients (client_id, hostname, os_type, cert_fingerprint, status, first_seen, last_seen)
|
||||
@@ -1461,15 +1476,25 @@ def enroll_client(req: ClientEnrollRequest, request: Request = None):
|
||||
req_is_server = 1 if req.is_server else (1 if req.os == "windows_server" else 0)
|
||||
req_server_roles = json.dumps(req.server_roles) if req.server_roles else "[]"
|
||||
req_client_info = json.dumps(req.client_info) if req.client_info else "{}"
|
||||
req_metrics = getattr(req, "metrics", None) or {}
|
||||
cpu_p = float(req_metrics.get("cpu_percent", 0.0))
|
||||
mem_p = float(req_metrics.get("memory_percent", 0.0))
|
||||
disk_p = float(req_metrics.get("disk_percent_free", 0.0))
|
||||
metrics_json = json.dumps(req_metrics) if req_metrics else "{}"
|
||||
|
||||
if existing:
|
||||
try:
|
||||
c.execute("""
|
||||
UPDATE clients
|
||||
SET hostname = ?, os_type = ?, cert_fingerprint = ?, status = 'active', last_seen = ?, client_version = ?,
|
||||
os_name = ?, is_server = ?, server_roles = ?, client_info_json = ?
|
||||
os_name = ?, is_server = ?, server_roles = ?, client_info_json = ?,
|
||||
cpu_percent = CASE WHEN ? > 0.0 THEN ? ELSE cpu_percent END,
|
||||
memory_percent = CASE WHEN ? > 0.0 THEN ? ELSE memory_percent END,
|
||||
disk_percent_free = CASE WHEN ? > 0.0 THEN ? ELSE disk_percent_free END,
|
||||
metrics_json = CASE WHEN ? != '{}' THEN ? ELSE metrics_json END
|
||||
WHERE client_id = ?
|
||||
""", (req.hostname, req.os, fp, now_sql, client_ver, req_os_name, req_is_server, req_server_roles, req_client_info, req.client_id))
|
||||
""", (req.hostname, req.os, fp, now_sql, client_ver, req_os_name, req_is_server, req_server_roles, req_client_info,
|
||||
cpu_p, cpu_p, mem_p, mem_p, disk_p, disk_p, metrics_json, metrics_json, req.client_id))
|
||||
except sqlite3.OperationalError:
|
||||
try:
|
||||
c.execute("""
|
||||
@@ -1486,9 +1511,9 @@ def enroll_client(req: ClientEnrollRequest, request: Request = None):
|
||||
else:
|
||||
try:
|
||||
c.execute("""
|
||||
INSERT INTO clients (client_id, hostname, os_type, cert_fingerprint, status, first_seen, last_seen, client_version, os_name, is_server, server_roles, client_info_json)
|
||||
VALUES (?, ?, ?, ?, 'active', ?, ?, ?, ?, ?, ?, ?)
|
||||
""", (req.client_id, req.hostname, req.os, fp, now_sql, now_sql, client_ver, req_os_name, req_is_server, req_server_roles, req_client_info))
|
||||
INSERT INTO clients (client_id, hostname, os_type, cert_fingerprint, status, first_seen, last_seen, client_version, os_name, is_server, server_roles, client_info_json, cpu_percent, memory_percent, disk_percent_free, metrics_json)
|
||||
VALUES (?, ?, ?, ?, 'active', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""", (req.client_id, req.hostname, req.os, fp, now_sql, now_sql, client_ver, req_os_name, req_is_server, req_server_roles, req_client_info, cpu_p, mem_p, disk_p, metrics_json))
|
||||
except sqlite3.OperationalError:
|
||||
try:
|
||||
c.execute("""
|
||||
|
||||
Reference in New Issue
Block a user