-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Patryk Kopyciński <[email protected]>
- Loading branch information
1 parent
8834c99
commit b194c3b
Showing
26 changed files
with
1,323 additions
and
532 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
x-pack/plugins/osquery/public/agents/use_agent_policy_agent_ids.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { map } from 'lodash'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { useQuery } from 'react-query'; | ||
|
||
import { AGENT_SAVED_OBJECT_TYPE, Agent } from '../../../fleet/common'; | ||
import { useErrorToast } from '../common/hooks/use_error_toast'; | ||
import { useKibana } from '../common/lib/kibana'; | ||
|
||
interface UseAgentPolicyAgentIdsProps { | ||
agentPolicyId: string | undefined; | ||
silent?: boolean; | ||
skip?: boolean; | ||
} | ||
|
||
export const useAgentPolicyAgentIds = ({ | ||
agentPolicyId, | ||
silent, | ||
skip, | ||
}: UseAgentPolicyAgentIdsProps) => { | ||
const { http } = useKibana().services; | ||
const setErrorToast = useErrorToast(); | ||
|
||
return useQuery<{ agents: Agent[] }, unknown, string[]>( | ||
['agentPolicyAgentIds', agentPolicyId], | ||
() => { | ||
const kuery = `${AGENT_SAVED_OBJECT_TYPE}.policy_id:${agentPolicyId}`; | ||
|
||
return http.get(`/internal/osquery/fleet_wrapper/agents`, { | ||
query: { | ||
kuery, | ||
perPage: 10000, | ||
}, | ||
}); | ||
}, | ||
{ | ||
select: (data) => map(data?.agents, 'id') || ([] as string[]), | ||
enabled: !skip || !agentPolicyId, | ||
onSuccess: () => setErrorToast(), | ||
onError: (error) => | ||
!silent && | ||
setErrorToast(error as Error, { | ||
title: i18n.translate('xpack.osquery.agents.fetchError', { | ||
defaultMessage: 'Error while fetching agents', | ||
}), | ||
}), | ||
refetchOnMount: false, | ||
refetchOnReconnect: false, | ||
refetchOnWindowFocus: false, | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import { EuiFlexGroup, EuiFlexItem, EuiButton, EuiSpacer } from '@elastic/eui'; | |
import { produce } from 'immer'; | ||
import React, { useCallback, useMemo, useState } from 'react'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { satisfies } from 'semver'; | ||
|
||
import { | ||
OsqueryManagerPackagePolicyInputStream, | ||
|
@@ -23,6 +24,7 @@ import { OsqueryPackUploader } from './pack_uploader'; | |
import { getSupportedPlatforms } from '../queries/platforms/helpers'; | ||
|
||
interface QueriesFieldProps { | ||
handleNameChange: (name: string) => void; | ||
field: FieldHook<OsqueryManagerPackagePolicyInput[]>; | ||
integrationPackageVersion?: string | undefined; | ||
scheduledQueryGroupId: string; | ||
|
@@ -82,6 +84,7 @@ const getNewStream = (payload: GetNewStreamProps) => | |
|
||
const QueriesFieldComponent: React.FC<QueriesFieldProps> = ({ | ||
field, | ||
handleNameChange, | ||
integrationPackageVersion, | ||
scheduledQueryGroupId, | ||
}) => { | ||
|
@@ -208,13 +211,18 @@ const QueriesFieldComponent: React.FC<QueriesFieldProps> = ({ | |
}, [setValue, tableSelectedItems]); | ||
|
||
const handlePackUpload = useCallback( | ||
(newQueries) => { | ||
(newQueries, packName) => { | ||
/* Osquery scheduled packs are supported since [email protected] */ | ||
const isOsqueryPackSupported = integrationPackageVersion | ||
? satisfies(integrationPackageVersion, '>=0.5.0') | ||
: false; | ||
|
||
setValue( | ||
produce((draft) => { | ||
forEach(newQueries, (newQuery, newQueryId) => { | ||
draft[0].streams.push( | ||
getNewStream({ | ||
id: newQueryId, | ||
id: isOsqueryPackSupported ? newQueryId : `pack_${packName}_${newQueryId}`, | ||
interval: newQuery.interval, | ||
query: newQuery.query, | ||
version: newQuery.version, | ||
|
@@ -227,8 +235,12 @@ const QueriesFieldComponent: React.FC<QueriesFieldProps> = ({ | |
return draft; | ||
}) | ||
); | ||
|
||
if (isOsqueryPackSupported) { | ||
handleNameChange(packName); | ||
} | ||
}, | ||
[scheduledQueryGroupId, setValue] | ||
[handleNameChange, integrationPackageVersion, scheduledQueryGroupId, setValue] | ||
); | ||
|
||
const tableData = useMemo(() => (field.value.length ? field.value[0].streams : []), [ | ||
|
@@ -277,7 +289,6 @@ const QueriesFieldComponent: React.FC<QueriesFieldProps> = ({ | |
<EuiSpacer /> | ||
{field.value && field.value[0].streams?.length ? ( | ||
<ScheduledQueryGroupQueriesTable | ||
editMode={true} | ||
data={tableData} | ||
onEditClick={handleEditClick} | ||
onDeleteClick={handleDeleteClick} | ||
|
Oops, something went wrong.