Show known hypervisors and the Hetzner placeholder for virtual machines

This commit is contained in:
2026-11-18 22:39:29 +01:00
parent 08177d8843
commit bcd3bd86ad
13 changed files with 530 additions and 11 deletions
+29
View File
@@ -0,0 +1,29 @@
SELECT asset.asset_id, host.agent_id, inventory.data->>'hostname' AS hostname
FROM assets asset
JOIN LATERAL (
SELECT a.agent_id, a.revoked_at
FROM agent_installations a
WHERE a.tenant_id=asset.tenant_id AND a.asset_id=asset.asset_id AND a.created_at<=$2
AND a.last_authenticated_at IS NOT NULL AND a.last_contact_at IS NOT NULL
ORDER BY a.enrollment_generation DESC, a.created_at DESC, a.agent_id
LIMIT 1
) host ON host.revoked_at IS NULL
JOIN LATERAL (
SELECT data FROM observations
WHERE tenant_id=asset.tenant_id AND agent_id=host.agent_id AND received_at<=$2
AND source_id IN ('linux.base','windows.base')
ORDER BY observed_at DESC, received_at DESC, sequence DESC
LIMIT 1
) inventory ON true
WHERE asset.tenant_id=$1 AND asset.archived_at IS NULL
AND ($3::uuid[] IS NULL OR asset.asset_id=ANY($3))
AND nullif(btrim(inventory.data->>'hostname'),'') IS NOT NULL
AND ($4='' OR strpos(lower(inventory.data->>'hostname'), lower($4))>0)
AND EXISTS (
SELECT FROM jsonb_array_elements(CASE WHEN jsonb_typeof(inventory.data->'observations')='array'
THEN inventory.data->'observations' ELSE '[]'::jsonb END) o
WHERE o->>'scope' IN ('linux.hardware','windows.hardware')
AND o->>'quality'='valid' AND o#>>'{data,device_type}'='hypervisor'
)
ORDER BY lower(inventory.data->>'hostname'), asset.asset_id
LIMIT $5