diff --git a/backend/routes/atlas.js b/backend/routes/atlas.js index 3a1d31f..ac73437 100644 --- a/backend/routes/atlas.js +++ b/backend/routes/atlas.js @@ -251,6 +251,19 @@ function createAtlasRouter() { return res.json({ synced: 0, withPlans: 0, failed: 0 }); } + // Build a set of host IDs belonging to managed BUs — these always show the badge + const managedPatterns = managedBUs.map(b => `%${b}%`); + let managedHostIds = new Set(); + try { + const { rows: managedRows } = await pool.query( + `SELECT DISTINCT host_id FROM ivanti_findings + WHERE host_id IS NOT NULL AND host_id > 0 + AND bu_ownership ILIKE ANY($1::text[])`, + [managedPatterns] + ); + managedHostIds = new Set(managedRows.map(r => r.host_id)); + } catch (_) { /* non-fatal — fall back to plans-only logic */ } + let synced = 0; let withPlans = 0; let failed = 0; @@ -273,6 +286,7 @@ function createAtlasRouter() { } const { hostId, result } = settled.value; + const isManagedHost = managedHostIds.has(hostId); if (result.status >= 200 && result.status < 300) { let allPlans = []; @@ -294,9 +308,11 @@ function createAtlasRouter() { const planCount = activePlans.length; const hasActionPlan = planCount > 0; - // Atlas "knows" this host if it returned any plans (active or inactive). - // Hosts with completely empty responses are not tracked by Atlas. - const atlasKnown = allPlans.length > 0; + // Atlas "knows" this host if: + // 1. It returned any plans (active or inactive), OR + // 2. The host belongs to a managed BU (these should always show the badge) + // Non-managed BU hosts with empty responses don't get a badge. + const atlasKnown = allPlans.length > 0 || isManagedHost; try { if (!hasActionPlan) {