Fix atlas_known — parse response body to detect 'not found' hosts

Instead of blanket-marking managed BU hosts, now parses the Atlas API
response: if it returns a valid {active, inactive} structure, the host
is known. If it returns an error or 'not found' message (even with a
2xx status), the host is not known and won't show a badge.

This prevents the shield showing on hosts Atlas doesn't actually track,
while correctly showing it on hosts Atlas recognizes (with or without
plans).
This commit is contained in:
Jordan Ramos
2026-06-16 15:45:43 -06:00
parent 09db1c2ae9
commit c0e3139503

View File

@@ -291,28 +291,35 @@ function createAtlasRouter() {
if (result.status >= 200 && result.status < 300) { if (result.status >= 200 && result.status < 300) {
let allPlans = []; let allPlans = [];
let activePlans = []; let activePlans = [];
let atlasRecognizesHost = false;
try { try {
const parsed = JSON.parse(result.body); const parsed = JSON.parse(result.body);
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) { if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
activePlans = Array.isArray(parsed.active) ? parsed.active : []; // Check for "not found" error responses that come back as 200
const inactive = Array.isArray(parsed.inactive) ? parsed.inactive : []; if (parsed.error || parsed.message?.includes('not found')) {
allPlans = [...activePlans, ...inactive]; atlasRecognizesHost = false;
} else {
atlasRecognizesHost = true;
activePlans = Array.isArray(parsed.active) ? parsed.active : [];
const inactive = Array.isArray(parsed.inactive) ? parsed.inactive : [];
allPlans = [...activePlans, ...inactive];
}
} else if (Array.isArray(parsed)) { } else if (Array.isArray(parsed)) {
atlasRecognizesHost = true;
allPlans = parsed; allPlans = parsed;
activePlans = parsed; activePlans = parsed;
} }
} catch (e) { } catch (e) {
allPlans = []; allPlans = [];
activePlans = []; activePlans = [];
atlasRecognizesHost = false;
} }
const planCount = activePlans.length; const planCount = activePlans.length;
const hasActionPlan = planCount > 0; const hasActionPlan = planCount > 0;
// Atlas "knows" this host if: // Atlas knows this host if it returned a valid structured response
// 1. It returned any plans (active or inactive), OR // (not "not found" or error). This determines whether the badge renders.
// 2. The host belongs to a managed BU (these should always show the badge) const atlasKnown = atlasRecognizesHost;
// Non-managed BU hosts with empty responses don't get a badge.
const atlasKnown = allPlans.length > 0 || isManagedHost;
try { try {
if (!hasActionPlan) { if (!hasActionPlan) {