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

Msp dashboard: add exit and detailed logs when Fleet instance returns 404 response. #25531

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
add more detailed logs for missing software installers
  • Loading branch information
eashaw committed Jan 16, 2025
commit 4699ddb3e31d306b7d55bbf8e359dce6a612af60
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ module.exports = {

softwareInstallerMissing: {
description: 'The Fleet instance returned a 404 response when a request was sent to copy an existing software installer to a new team',
responseType: 'notFound',
},
},

Original file line number Diff line number Diff line change
@@ -45,6 +45,9 @@ module.exports = {

if(id){
let softwareToDownload = await UndeployedSoftware.findOne({id: id});
if(!softwareToDownload){
throw 'notFound';
}
downloading = await sails.startDownload(softwareToDownload.uploadFd, {bucket: sails.config.uploads.bucketWithPostfix});
this.res.type(softwareToDownload.uploadMime);
this.res.attachment(softwareToDownload.name);
@@ -55,6 +58,10 @@ module.exports = {
headers: {
Authorization: `Bearer ${sails.config.custom.fleetApiToken}`,
}
}).intercept({raw: {statusCode: 404}}, (error)=>{
// If the Fleet instance returns a 404 response, log a warning and display the notFound response page.
sails.log.warn(`When attempting to get information about a software title (id: ${fleetApid}) for team_id ${teamApid}, the Fleet instance returned a 404 response. Full Error: ${require('util').inspect(error, {depth: 1})}`);
return 'notFound';
});
let filename = packageInformation.software_title.software_package.name;
// [?]: https://fleetdm.com/docs/rest-api/rest-api#download-package
@@ -64,6 +71,10 @@ module.exports = {
headers: {
Authorization: `Bearer ${sails.config.custom.fleetApiToken}`,
}
})
.intercept({raw: {statusCode: 404}}, (error)=>{
// If the installer is missing, throw an error with information about this software installer/title.
return new Error(`When attempting to download the installer for ${filename} (id: ${fleetApid}), the Fleet instance returned a 404 response when a request was sent to get a download stream of the installer on team_id ${teamApid}. Full Error: ${require('util').inspect(error, {depth: 1})}`);
});
this.res.attachment(filename);
}
Original file line number Diff line number Diff line change
@@ -103,8 +103,9 @@ module.exports = {
Authorization: `Bearer ${sails.config.custom.fleetApiToken}`,
}
})
.intercept('non200Response', (error)=>{
return new Error(`When attempting to transfer the installer for ${software.name} to a new team on the Fleet instance, the Fleet isntance returned a non-200 response when a request was sent to get a download stream of the installer on team_id ${teamIdToGetInstallerFrom}. Full Error: ${require('util').inspect(error, {depth: 1})}`);
.intercept({raw: {statusCode: 404}}, (error)=>{
sails.log.warn(`When attempting to transfer the installer for ${software.name} (id: ${software.fleetApid}) to a new team, the Fleet instance returned a 404 resposne when a request was sent to get a download stream of the installer on team_id ${teamIdToGetInstallerFrom}. Full Error: ${require('util').inspect(error, {depth: 1})}`);
return 'softwareInstallerMissing';
});
let tempUploadedSoftware = await sails.uploadOne(softwareStream, {bucket: sails.config.uploads.bucketWithPostfix});
softwareFd = tempUploadedSoftware.fd;