Skip BU history entries when previous_bu is unknown

Only record BU reassignment in ivanti_finding_bu_history when the
previous_bu is a known managed BU (from EXPECTED_BUS). Findings that
were never in our sync cache show as UNKNOWN which provides no
actionable insight for asset movement tracking.

Closes #28
This commit is contained in:
Jordan Ramos
2026-06-17 14:58:01 -06:00
parent a95fd03f5e
commit f257cfad88

View File

@@ -798,12 +798,17 @@ async function runBUDriftChecker(newlyArchivedIds, apiKey, clientId, skipTls, pr
if (classification === 'bu_reassignment' && found) {
try {
// Determine previous BU from the pre-sync snapshot (passed in from syncFindings)
const previousBu = (previousBuMap && previousBuMap.get(id)) || 'UNKNOWN';
const previousBu = (previousBuMap && previousBuMap.get(id)) || '';
// Only record if we have a known previous BU — "UNKNOWN → X" entries
// provide no actionable insight for asset movement tracking.
if (previousBu && EXPECTED_BUS.has(previousBu)) {
await pool.query(
`INSERT INTO ivanti_finding_bu_history (finding_id, finding_title, host_name, previous_bu, new_bu, detected_at)
VALUES ($1, $2, $3, $4, $5, NOW())`,
[id, found.title || '', found.hostName || '', previousBu, found.bu]
);
}
} catch (err) {
console.error(`[BU Drift Checker] Error recording BU change for finding ${id}:`, err.message);
}