From 28f52b6a25416400edced5d57fb375ffbdc0e86e Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Tue, 20 Oct 2020 15:34:10 -0400 Subject: [PATCH] [Fleet] Fix POLICY_CHANGE action creation for new policy --- .../ingest_manager/server/routes/agent_policy/handlers.ts | 3 +++ .../ingest_manager/server/services/agent_policy.ts | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/x-pack/plugins/ingest_manager/server/routes/agent_policy/handlers.ts b/x-pack/plugins/ingest_manager/server/routes/agent_policy/handlers.ts index 311b3bbf7f13b..645ae8880fa61 100644 --- a/x-pack/plugins/ingest_manager/server/routes/agent_policy/handlers.ts +++ b/x-pack/plugins/ingest_manager/server/routes/agent_policy/handlers.ts @@ -132,6 +132,8 @@ export const createAgentPolicyHandler: RequestHandler< }); } + await agentPolicyService.createFleetPolicyChangeAction(soClient, agentPolicy.id); + const body: CreateAgentPolicyResponse = { item: agentPolicy, }; @@ -185,6 +187,7 @@ export const copyAgentPolicyHandler: RequestHandler< user: user || undefined, } ); + const body: CopyAgentPolicyResponse = { item: agentPolicy }; return response.ok({ body, diff --git a/x-pack/plugins/ingest_manager/server/services/agent_policy.ts b/x-pack/plugins/ingest_manager/server/services/agent_policy.ts index 75c16df483a76..3b55f7e458141 100644 --- a/x-pack/plugins/ingest_manager/server/services/agent_policy.ts +++ b/x-pack/plugins/ingest_manager/server/services/agent_policy.ts @@ -34,6 +34,7 @@ import { agentPolicyUpdateEventHandler } from './agent_policy_update'; import { getSettings } from './settings'; import { normalizeKuery, escapeSearchQueryPhrase } from './saved_object'; import { getFullAgentPolicyKibanaConfig } from '../../common/services/full_agent_policy_kibana_config'; +import { isAgentsSetup } from './agents/setup'; const SAVED_OBJECT_TYPE = AGENT_POLICY_SAVED_OBJECT_TYPE; @@ -287,6 +288,8 @@ class AgentPolicyService { throw new Error('Copied agent policy not found'); } + await this.createFleetPolicyChangeAction(soClient, newAgentPolicy.id); + return updatedAgentPolicy; } @@ -433,6 +436,11 @@ class AgentPolicyService { soClient: SavedObjectsClientContract, agentPolicyId: string ) { + // If Agents is not setup skip the creation of POLICY_CHANGE agent actions + // the action will be created during the fleet setup + if (!isAgentsSetup(soClient)) { + return; + } const policy = await agentPolicyService.getFullAgentPolicy(soClient, agentPolicyId); if (!policy || !policy.revision) { return;