File tree Expand file tree Collapse file tree
plugins/ingest_manager/server
test/ingest_manager_api_integration/apis/settings Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -132,6 +132,8 @@ export const createAgentPolicyHandler: RequestHandler<
132132 } ) ;
133133 }
134134
135+ await agentPolicyService . createFleetPolicyChangeAction ( soClient , agentPolicy . id ) ;
136+
135137 const body : CreateAgentPolicyResponse = {
136138 item : agentPolicy ,
137139 } ;
@@ -185,6 +187,7 @@ export const copyAgentPolicyHandler: RequestHandler<
185187 user : user || undefined ,
186188 }
187189 ) ;
190+
188191 const body : CopyAgentPolicyResponse = { item : agentPolicy } ;
189192 return response . ok ( {
190193 body,
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ import { agentPolicyUpdateEventHandler } from './agent_policy_update';
3434import { getSettings } from './settings' ;
3535import { normalizeKuery , escapeSearchQueryPhrase } from './saved_object' ;
3636import { getFullAgentPolicyKibanaConfig } from '../../common/services/full_agent_policy_kibana_config' ;
37+ import { isAgentsSetup } from './agents/setup' ;
3738
3839const SAVED_OBJECT_TYPE = AGENT_POLICY_SAVED_OBJECT_TYPE ;
3940
@@ -287,6 +288,8 @@ class AgentPolicyService {
287288 throw new Error ( 'Copied agent policy not found' ) ;
288289 }
289290
291+ await this . createFleetPolicyChangeAction ( soClient , newAgentPolicy . id ) ;
292+
290293 return updatedAgentPolicy ;
291294 }
292295
@@ -433,6 +436,11 @@ class AgentPolicyService {
433436 soClient : SavedObjectsClientContract ,
434437 agentPolicyId : string
435438 ) {
439+ // If Agents is not setup skip the creation of POLICY_CHANGE agent actions
440+ // the action will be created during the fleet setup
441+ if ( ! ( await isAgentsSetup ( soClient ) ) ) {
442+ return ;
443+ }
436444 const policy = await agentPolicyService . getFullAgentPolicy ( soClient , agentPolicyId ) ;
437445 if ( ! policy || ! policy . revision ) {
438446 return ;
Original file line number Diff line number Diff line change @@ -81,6 +81,24 @@ export default function (providerContext: FtrProviderContext) {
8181 } ) ;
8282 createdAgentPolicyIds . push ( testPolicyRes . item . id ) ;
8383
84+ const beforeRes = await esClient . search ( {
85+ index : '.kibana' ,
86+ body : {
87+ query : {
88+ bool : {
89+ must : [
90+ {
91+ terms : {
92+ type : [ 'fleet-agent-actions' ] ,
93+ } ,
94+ } ,
95+ { match : { 'fleet-agent-actions.policy_id' : testPolicyRes . item . id } } ,
96+ ] ,
97+ } ,
98+ } ,
99+ } ,
100+ } ) ;
101+
84102 await supertest
85103 . put ( `/api/fleet/settings` )
86104 . set ( 'kbn-xsrf' , 'xxxx' )
@@ -105,7 +123,7 @@ export default function (providerContext: FtrProviderContext) {
105123 } ,
106124 } ) ;
107125
108- expect ( res . hits . hits . length ) . equal ( 2 ) ;
126+ expect ( res . hits . hits . length ) . equal ( beforeRes . hits . hits . length + 1 ) ;
109127 } ) ;
110128 } ) ;
111129}
You can’t perform that action at this time.
0 commit comments