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

[EDR Workflows] Include timeout in saved query run #172347

Merged
merged 4 commits into from
Dec 6, 2023
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
9 changes: 6 additions & 3 deletions x-pack/plugins/osquery/public/live_queries/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import React, { useCallback, useContext, useEffect, useMemo, useState } from 're
import { useForm as useHookForm, FormProvider } from 'react-hook-form';
import { isEmpty, find, pickBy, isNumber } from 'lodash';

import { QUERY_TIMEOUT } from '../../../common/constants';
import {
containsDynamicQuery,
replaceParamsQuery,
Expand Down Expand Up @@ -50,6 +51,7 @@ interface DefaultLiveQueryFormFields {
savedQueryId?: string | null;
ecs_mapping?: ECSMapping;
packId?: string;
timeout?: number;
}

type FormType = 'simple' | 'steps';
Expand Down Expand Up @@ -245,11 +247,11 @@ const LiveQueryFormComponent: React.FC<LiveQueryFormProps> = ({
setValue('agentSelection', defaultValue.agentSelection);
}

if (defaultValue?.alertIds?.length) {
if (defaultValue.alertIds?.length) {
setValue('alertIds', defaultValue.alertIds);
}

if (defaultValue?.packId && canRunPacks) {
if (defaultValue.packId && canRunPacks) {
setValue('queryType', 'pack');

if (!isPackDataFetched) return;
Expand All @@ -261,10 +263,11 @@ const LiveQueryFormComponent: React.FC<LiveQueryFormProps> = ({
return;
}

if (defaultValue?.query && canRunSingleQuery) {
if (defaultValue.query && canRunSingleQuery) {
setValue('query', defaultValue.query);
setValue('savedQueryId', defaultValue.savedQueryId);
setValue('ecs_mapping', defaultValue.ecs_mapping ?? {});
setValue('timeout', defaultValue.timeout ?? QUERY_TIMEOUT.DEFAULT);

return;
}
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/osquery/public/live_queries/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface LiveQueryProps {
agentPolicyIds?: string[];
onSuccess?: () => void;
query?: string;
timeout?: number;
savedQueryId?: string;
ecs_mapping?: ECSMapping;
agentsField?: boolean;
Expand Down Expand Up @@ -55,6 +56,7 @@ const LiveQueryComponent: React.FC<LiveQueryProps> = ({
hideAgentsField,
packId,
agentSelection,
timeout,
}) => {
const { data: hasActionResultsPrivileges, isLoading } = useActionResultsPrivileges();

Expand Down Expand Up @@ -93,11 +95,12 @@ const LiveQueryComponent: React.FC<LiveQueryProps> = ({
query: initialQuery,
savedQueryId,
ecs_mapping,
timeout,
packId,
};

return !isEmpty(pickBy(initialValue, (value) => !isEmpty(value))) ? initialValue : undefined;
}, [alertIds, ecs_mapping, initialAgentSelection, initialQuery, packId, savedQueryId]);
}, [alertIds, ecs_mapping, initialAgentSelection, initialQuery, packId, savedQueryId, timeout]);

if (isLoading) {
return <EuiSkeletonText lines={10} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import { useHistory } from 'react-router-dom';
import deepEqual from 'fast-deep-equal';
import type { ECSMapping } from '@kbn/osquery-io-ts-types';
import { QUERY_TIMEOUT } from '../../../../common/constants';
import { Direction } from '../../../../common/search_strategy';
import { WithHeaderLayout } from '../../../components/layouts';
import { useBreadcrumbs } from '../../../common/hooks/use_breadcrumbs';
Expand Down Expand Up @@ -56,6 +57,7 @@ const PlayButtonComponent: React.FC<PlayButtonProps> = ({ disabled = false, save
savedQueryId: savedQuery.id,
query: savedQuery.query,
ecs_mapping: savedQuery.ecs_mapping,
timeout: savedQuery.timeout ?? QUERY_TIMEOUT.DEFAULT,
},
}),
[push, savedQuery]
Expand Down
Loading