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

[7.15] [Osquery] Fix live query search doesn't return relevant results for agents (#116332) #116384

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions x-pack/plugins/osquery/public/agents/use_all_agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const useAllAgents = (
return useQuery<GetAgentsResponse>(
['agents', osqueryPolicies, searchValue, perPage],
() => {
let kuery = `${osqueryPolicies.map((p) => `policy_id:${p}`).join(' or ')}`;
let kuery = `(${osqueryPolicies.map((p) => `policy_id:${p}`).join(' or ')})`;

if (searchValue) {
kuery += ` and (local_metadata.host.hostname:*${searchValue}* or local_metadata.elastic.agent.id:*${searchValue}*)`;
Expand All @@ -54,10 +54,13 @@ export const useAllAgents = (
enabled: !osqueryPoliciesLoading && osqueryPolicies.length > 0,
onSuccess: () => setErrorToast(),
onError: (error) =>
setErrorToast(error as Error, {
// @ts-expect-error update types
setErrorToast(error?.body, {
title: i18n.translate('xpack.osquery.agents.fetchError', {
defaultMessage: 'Error while fetching agents',
}),
// @ts-expect-error update types
toastMessage: error?.body?.error,
}),
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ export const ECSMappingEditorField = ({ field, query, fieldRef }: ECSMappingEdit
LIMIT 5;
*/

if (selectItem.type === 'FunctionCall' && selectItem.hasAs) {
if (selectItem.hasAs && selectItem.alias) {
return [
{
label: selectItem.alias,
Expand Down
13 changes: 9 additions & 4 deletions x-pack/plugins/osquery/server/routes/fleet_wrapper/get_agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ export const getAgentsRoute = (router: IRouter, osqueryContext: OsqueryAppContex
async (context, request, response) => {
const esClient = context.core.elasticsearch.client.asInternalUser;

const agents = await osqueryContext.service
.getAgentService()
// @ts-expect-error update types
?.listAgents(esClient, request.query);
let agents;
try {
agents = await osqueryContext.service
.getAgentService()
// @ts-expect-error update types
?.listAgents(esClient, request.query);
} catch (error) {
return response.badRequest({ body: error });
}

return response.ok({ body: agents });
}
Expand Down