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) {
|
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)) {
|
||||||
|
// 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 : [];
|
activePlans = Array.isArray(parsed.active) ? parsed.active : [];
|
||||||
const inactive = Array.isArray(parsed.inactive) ? parsed.inactive : [];
|
const inactive = Array.isArray(parsed.inactive) ? parsed.inactive : [];
|
||||||
allPlans = [...activePlans, ...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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user