fix: health_check_status SQL subquery in hosts API
Some checks failed
CI Pipeline / Rust Format Check (push) Failing after 3s
CI Pipeline / Clippy Lints (push) Successful in 45s
CI Pipeline / Rust Unit Tests (push) Successful in 1m0s
CI Pipeline / Security Audit (push) Successful in 4s
CI Pipeline / Frontend Lint & Type Check (push) Failing after 10s
CI Pipeline / Build .deb & Release (push) Has been skipped
Some checks failed
CI Pipeline / Rust Format Check (push) Failing after 3s
CI Pipeline / Clippy Lints (push) Successful in 45s
CI Pipeline / Rust Unit Tests (push) Successful in 1m0s
CI Pipeline / Security Audit (push) Successful in 4s
CI Pipeline / Frontend Lint & Type Check (push) Failing after 10s
CI Pipeline / Build .deb & Release (push) Has been skipped
- Fixed broken SQL in hosts.rs that was using Python string replacement instead of proper CASE expression for health_check_status - Added serde default for health_check_poll_interval_secs config - Fixed missing AgentClient import in health_check_poller.rs - Added /etc/patch-manager/keys to systemd ReadWritePaths - Integration test verified: health check CRUD, service/HTTP checks work
This commit is contained in:
@ -112,7 +112,21 @@ async fn list_hosts(
|
|||||||
SELECT h.id, h.fqdn, host(h.ip_address)::text AS ip_address, h.display_name,
|
SELECT h.id, h.fqdn, host(h.ip_address)::text AS ip_address, h.display_name,
|
||||||
h.os_family, h.os_name, h.health_status, h.agent_version,
|
h.os_family, h.os_name, h.health_status, h.agent_version,
|
||||||
COALESCE(hpd.patch_count, 0) AS patches_missing,
|
COALESCE(hpd.patch_count, 0) AS patches_missing,
|
||||||
" + hc_subquery + ",
|
CASE
|
||||||
|
WHEN NOT EXISTS (SELECT 1 FROM host_health_checks hc WHERE hc.host_id = h.id AND hc.enabled = TRUE)
|
||||||
|
THEN NULL
|
||||||
|
WHEN EXISTS (
|
||||||
|
SELECT 1 FROM host_health_checks hc
|
||||||
|
LEFT JOIN LATERAL (
|
||||||
|
SELECT healthy FROM host_health_check_results r
|
||||||
|
WHERE r.check_id = hc.id ORDER BY r.checked_at DESC LIMIT 1
|
||||||
|
) lr ON TRUE
|
||||||
|
WHERE hc.host_id = h.id AND hc.enabled = TRUE
|
||||||
|
AND (lr.healthy IS NULL OR lr.healthy = FALSE)
|
||||||
|
)
|
||||||
|
THEN 'some_unhealthy'
|
||||||
|
ELSE 'all_healthy'
|
||||||
|
END AS health_check_status,
|
||||||
h.registered_at
|
h.registered_at
|
||||||
FROM hosts h
|
FROM hosts h
|
||||||
LEFT JOIN host_patch_data hpd ON hpd.host_id = h.id
|
LEFT JOIN host_patch_data hpd ON hpd.host_id = h.id
|
||||||
@ -131,7 +145,21 @@ async fn list_hosts(
|
|||||||
h.display_name, h.os_family, h.os_name,
|
h.display_name, h.os_family, h.os_name,
|
||||||
h.health_status, h.agent_version,
|
h.health_status, h.agent_version,
|
||||||
COALESCE(hpd.patch_count, 0) AS patches_missing,
|
COALESCE(hpd.patch_count, 0) AS patches_missing,
|
||||||
" + hc_subquery + ",
|
CASE
|
||||||
|
WHEN NOT EXISTS (SELECT 1 FROM host_health_checks hc WHERE hc.host_id = h.id AND hc.enabled = TRUE)
|
||||||
|
THEN NULL
|
||||||
|
WHEN EXISTS (
|
||||||
|
SELECT 1 FROM host_health_checks hc
|
||||||
|
LEFT JOIN LATERAL (
|
||||||
|
SELECT healthy FROM host_health_check_results r
|
||||||
|
WHERE r.check_id = hc.id ORDER BY r.checked_at DESC LIMIT 1
|
||||||
|
) lr ON TRUE
|
||||||
|
WHERE hc.host_id = h.id AND hc.enabled = TRUE
|
||||||
|
AND (lr.healthy IS NULL OR lr.healthy = FALSE)
|
||||||
|
)
|
||||||
|
THEN 'some_unhealthy'
|
||||||
|
ELSE 'all_healthy'
|
||||||
|
END AS health_check_status,
|
||||||
h.registered_at
|
h.registered_at
|
||||||
FROM hosts h
|
FROM hosts h
|
||||||
LEFT JOIN host_patch_data hpd ON hpd.host_id = h.id
|
LEFT JOIN host_patch_data hpd ON hpd.host_id = h.id
|
||||||
|
|||||||
Reference in New Issue
Block a user