Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulnerability dashboard: Update update-reports script. #18919

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions ee/vulnerability-dashboard/scripts/update-reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ module.exports = {
// For each software version, look up affected hosts.
// (i.e. they have this version of software installed)
let hostApidsBySoftwareVersionApid = {};// « Save a mapping for use below.
let vulnerableWaresWithNoHostInformation = [];
await sails.helpers.flow.simultaneouslyForEach(vulnerableWares, async(ware)=>{
// Get hosts with this version of software installed.
// [?] https://fleetdm.com/docs/using-fleet/rest-api#list-hosts
Expand All @@ -296,8 +297,11 @@ module.exports = {
})
.timeout(120000)
.retry(['requestFailed', {name: 'TimeoutError'}])
.intercept({raw:{statusCode: 404}} , (error)=>{
return new Error(`When sending a request to the '/api/v1/fleet/hosts' API endpoint to get a filtered array of hosts with ${ware.name} ${ware.version} installed (software ID: ${ware.id}), the Fleet instance returned a 404 response when we expected it to return an array of ${ware.hosts_count} host(s).\n Response from Fleet instance: ${error.raw.body}`);
.tolerate({raw:{statusCode: 404}} , (error)=>{
// If the hosts API returns a 404 response for a software item that was returned from in the list of vulnerable software, we'll log a warning and remove this software from the list of software.
sails.log.warn(`When sending a request to the '/api/v1/fleet/hosts' API endpoint to get a filtered array of hosts with ${ware.name} ${ware.version} installed (software ID: ${ware.id}), the Fleet instance returned a 404 response when we expected it to return an array of ${ware.hosts_count} host(s).\n Response from Fleet instance: ${error.raw.body}`);
vulnerableWaresWithNoHostInformation.push(ware);// Add this software to the vulnerableWaresWithNoHostInformation array, these will be removed before we create and update database records.
return {};// Return an empty object. This will let the script continue without information about this software.
});
if (!responseData.hosts) {// When pages of results are exhausted, bail. (`responseData.software` is absent in that case)
return true;
Expand Down Expand Up @@ -345,6 +349,9 @@ module.exports = {
}
});//∞ </each software version>

// Remove any software items that was not returned in the hosts API.
vulnerableWares = _.difference(vulnerableWares, vulnerableWaresWithNoHostInformation);

let hostRecordsToUpdate = [];
// Unrecognized hosts? Save 'em to the database.
let newRecordsForUnrecognizedHosts = []; {
Expand Down
Loading