Skip to content

Commit

Permalink
Update update-reports.js
Browse files Browse the repository at this point in the history
  • Loading branch information
eashaw committed Jul 2, 2024
1 parent b5112e7 commit d46c922
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions ee/vulnerability-dashboard/scripts/update-reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ module.exports = {
// So we'll look for an Operating system that matches that format, and log a warning and skip this host if one is not found.
hostsOperatingSystem = _.find(allOsRecords, {'fullName': 'Microsoft '+host.os_version});
if(!hostsOperatingSystem){
sails.log(`When building host records from the Fleet API, a host's (FleetApid: ${host.id}) os_version (os_version: ${host.os_version}) could not be matched to an operating system returned in the API response from the /os_versions endpoint. Host with missing operating system:`, host);
sails.log.verbose(`When building host records from the Fleet API, a host's (FleetApid: ${host.id}) os_version (os_version: ${host.os_version}) could not be matched to an operating system returned in the API response from the /os_versions endpoint. Host with missing operating system:`, host);
continue;
}
}
Expand Down Expand Up @@ -242,6 +242,21 @@ module.exports = {
}
}//∫


if (dry) {
sails.log.warn(`Dry run: ${newRecordsForUnrecognizedHosts.length} hosts were seemingly enrolled. (Fleet returned them in the API.)`);
sails.log.warn(`Dry run: ${hostRecordsToUpdate.length} hosts will be updated with new information. (Fleet returned them in the API.)`);
} else {
sails.log(`Creating ${newRecordsForUnrecognizedHosts.length} host records… `);
let batchedNewRecordsForUnrecognizedHosts = _.chunk(newRecordsForUnrecognizedHosts, 500);
for(let batch of batchedNewRecordsForUnrecognizedHosts){
await Host.createEach(batch);
}
for(let hostUpdate of hostRecordsToUpdate){
await Host.updateOne({id: hostUpdate.id}).set(_.omit(hostUpdate, 'id'));
}
}

// ██╗ ██╗██╗ ██╗██╗ ███╗ ██╗███████╗██████╗ █████╗ ██████╗ ██╗ ███████╗
// ██║ ██║██║ ██║██║ ████╗ ██║██╔════╝██╔══██╗██╔══██╗██╔══██╗██║ ██╔════╝
// ██║ ██║██║ ██║██║ ██╔██╗ ██║█████╗ ██████╔╝███████║██████╔╝██║ █████╗
Expand Down Expand Up @@ -520,7 +535,7 @@ module.exports = {
}//∞
numVulnerableWaresProcessed += vulnerableWares.length;
page++;
}, 45 * 60 * 1000)// (timeout after 45 mintutes)
}, 90 * 60 * 1000)// (timeout after 90 mintutes)
.intercept((err) =>
require('flaverr')({message: 'Could not get software from the Fleet API. Error details: '+err.message}, err)
);
Expand Down

0 comments on commit d46c922

Please sign in to comment.