Skip to content

Commit

Permalink
EMT-146: add warning log, and improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
nnamdifrankie committed Apr 21, 2020
1 parent 6d4c1ed commit 9bb3550
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions x-pack/plugins/endpoint/server/routes/metadata/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,29 @@ async function enrichHostMetadata(
metadataRequestContext: MetadataRequestContext
): Promise<HostInfo> {
let hostStatus = HostStatus.ERROR;
let elasticAgentId = hostMetadata?.elastic?.agent?.id;
const log = logger(metadataRequestContext.endpointAppContext);
try {
/**
* Get agent status by elastic agent id if available or use the host id.
* https://github.com/elastic/endpoint-app-team/issues/354
*/

if (!elasticAgentId) {
elasticAgentId = hostMetadata.host.id;
log.warn(`Missing elastic agent id, using host id instead ${elasticAgentId}`);
}

const status = await metadataRequestContext.endpointAppContext.agentService.getAgentStatusById(
metadataRequestContext.requestHandlerContext.core.savedObjects.client,
hostMetadata.elastic.agent.id || hostMetadata.host.id
elasticAgentId
);
hostStatus = HOST_STATUS_MAPPING.get(status) || HostStatus.ERROR;
} catch (e) {
if (e.isBoom && e.output.statusCode === 404) {
logger(metadataRequestContext.endpointAppContext).warn(
`agent with id ${hostMetadata.elastic.agent.id} not found`
);
log.warn(`agent with id ${elasticAgentId} not found`);
} else {
log.error(e);
throw e;
}
}
Expand Down

0 comments on commit 9bb3550

Please sign in to comment.