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:
@@ -291,28 +291,35 @@ function createAtlasRouter() {
|
||||
if (result.status >= 200 && result.status < 300) {
|
||||
let allPlans = [];
|
||||
let activePlans = [];
|
||||
let atlasRecognizesHost = false;
|
||||
try {
|
||||
const parsed = JSON.parse(result.body);
|
||||
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
||||
activePlans = Array.isArray(parsed.active) ? parsed.active : [];
|
||||
const inactive = Array.isArray(parsed.inactive) ? parsed.inactive : [];
|
||||
allPlans = [...activePlans, ...inactive];
|
||||
// Check for "not found" error responses that come back as 200
|
||||
if (parsed.error || parsed.message?.includes('not found')) {
|
||||
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)) {
|
||||
atlasRecognizesHost = true;
|
||||
allPlans = parsed;
|
||||
activePlans = parsed;
|
||||
}
|
||||
} catch (e) {
|
||||
allPlans = [];
|
||||
activePlans = [];
|
||||
atlasRecognizesHost = false;
|
||||
}
|
||||
|
||||
const planCount = activePlans.length;
|
||||
const hasActionPlan = planCount > 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;
|
||||
// Atlas knows this host if it returned a valid structured response
|
||||
// (not "not found" or error). This determines whether the badge renders.
|
||||
const atlasKnown = atlasRecognizesHost;
|
||||
|
||||
try {
|
||||
if (!hasActionPlan) {
|
||||
|
||||
Reference in New Issue
Block a user