Skip to content

Commit

Permalink
[Ingest Manager] Manually build Fleet kuery with Node arguments (#76589)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Sep 14, 2020
1 parent 2994d32 commit 5256604
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/plugins/data/common/es_query/kuery/node_types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface NamedArgTypeBuildNode {
}

interface WildcardType {
wildcardSymbol: string;
buildNode: (value: string) => WildcardTypeBuildNode | KueryNode;
test: (node: any, string: string) => boolean;
toElasticsearchQuery: (node: any) => string;
Expand Down
31 changes: 16 additions & 15 deletions x-pack/plugins/ingest_manager/server/services/agents/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,19 @@ export async function getAgentActionsForCheckin(
const filter = nodeTypes.function.buildNode('and', [
nodeTypes.function.buildNode(
'not',
nodeTypes.function.buildNode(
'is',
`${AGENT_ACTION_SAVED_OBJECT_TYPE}.attributes.sent_at`,
'*'
)
),
nodeTypes.function.buildNode(
'is',
`${AGENT_ACTION_SAVED_OBJECT_TYPE}.attributes.agent_id`,
agentId
nodeTypes.function.buildNodeWithArgumentNodes('is', [
nodeTypes.literal.buildNode(`${AGENT_ACTION_SAVED_OBJECT_TYPE}.attributes.sent_at`),
nodeTypes.wildcard.buildNode(nodeTypes.wildcard.wildcardSymbol),
nodeTypes.literal.buildNode(false),
])
),
nodeTypes.function.buildNodeWithArgumentNodes('is', [
nodeTypes.literal.buildNode(`${AGENT_ACTION_SAVED_OBJECT_TYPE}.attributes.agent_id`),
nodeTypes.literal.buildNode(agentId),
nodeTypes.literal.buildNode(false),
]),
]);

const res = await soClient.find<AgentActionSOAttributes>({
type: AGENT_ACTION_SAVED_OBJECT_TYPE,
filter,
Expand Down Expand Up @@ -176,11 +177,11 @@ export async function getNewActionsSince(soClient: SavedObjectsClientContract, t
const filter = nodeTypes.function.buildNode('and', [
nodeTypes.function.buildNode(
'not',
nodeTypes.function.buildNode(
'is',
`${AGENT_ACTION_SAVED_OBJECT_TYPE}.attributes.sent_at`,
'*'
)
nodeTypes.function.buildNodeWithArgumentNodes('is', [
nodeTypes.literal.buildNode(`${AGENT_ACTION_SAVED_OBJECT_TYPE}.attributes.sent_at`),
nodeTypes.wildcard.buildNode(nodeTypes.wildcard.wildcardSymbol),
nodeTypes.literal.buildNode(false),
])
),
nodeTypes.function.buildNode(
'range',
Expand Down

0 comments on commit 5256604

Please sign in to comment.