From 730835da54ed7b7fc5ca0eb3989210f2ad028a18 Mon Sep 17 00:00:00 2001 From: Aleksandr Maus Date: Thu, 21 Oct 2021 15:42:02 -0400 Subject: [PATCH] Add action_response field into .fleet-actions-results (#796) --- cmd/fleet/handleAck.go | 15 ++++++++------- cmd/fleet/schema.go | 29 +++++++++++++++-------------- internal/pkg/es/mapping.go | 11 +++++++++++ internal/pkg/model/schema.go | 7 +++++++ model/schema.json | 5 +++++ 5 files changed, 46 insertions(+), 21 deletions(-) diff --git a/cmd/fleet/handleAck.go b/cmd/fleet/handleAck.go index 2c43c138d..79b88bc4c 100644 --- a/cmd/fleet/handleAck.go +++ b/cmd/fleet/handleAck.go @@ -163,13 +163,14 @@ func (ack *AckT) handleAckEvents(ctx context.Context, agent *model.Agent, events } acr := model.ActionResult{ - ActionId: ev.ActionId, - AgentId: agent.Id, - StartedAt: ev.StartedAt, - CompletedAt: ev.CompletedAt, - ActionData: ev.ActionData, - Data: ev.Data, - Error: ev.Error, + ActionId: ev.ActionId, + AgentId: agent.Id, + StartedAt: ev.StartedAt, + CompletedAt: ev.CompletedAt, + ActionData: ev.ActionData, + ActionResponse: ev.ActionResponse, + Data: ev.Data, + Error: ev.Error, } if _, err := dl.CreateActionResult(ctx, ack.bulk, acr); err != nil { return errors.Wrap(err, "create action result") diff --git a/cmd/fleet/schema.go b/cmd/fleet/schema.go index f8f300b46..c2b03bc5e 100644 --- a/cmd/fleet/schema.go +++ b/cmd/fleet/schema.go @@ -102,20 +102,21 @@ type ActionResp struct { } type Event struct { - Type string `json:"type"` - SubType string `json:"subtype"` - AgentId string `json:"agent_id"` - ActionId string `json:"action_id"` - PolicyId string `json:"policy_id"` - StreamId string `json:"stream_id"` - Timestamp string `json:"timestamp"` - Message string `json:"message"` - Payload json.RawMessage `json:"payload,omitempty"` - StartedAt string `json:"started_at"` - CompletedAt string `json:"completed_at"` - ActionData json.RawMessage `json:"action_data,omitempty"` - Data json.RawMessage `json:"data,omitempty"` - Error string `json:"error,omitempty"` + Type string `json:"type"` + SubType string `json:"subtype"` + AgentId string `json:"agent_id"` + ActionId string `json:"action_id"` + PolicyId string `json:"policy_id"` + StreamId string `json:"stream_id"` + Timestamp string `json:"timestamp"` + Message string `json:"message"` + Payload json.RawMessage `json:"payload,omitempty"` + StartedAt string `json:"started_at"` + CompletedAt string `json:"completed_at"` + ActionData json.RawMessage `json:"action_data,omitempty"` + ActionResponse json.RawMessage `json:"action_response,omitempty"` + Data json.RawMessage `json:"data,omitempty"` + Error string `json:"error,omitempty"` } type StatusResponse struct { diff --git a/internal/pkg/es/mapping.go b/internal/pkg/es/mapping.go index ccc0a6b51..deb9a52d9 100644 --- a/internal/pkg/es/mapping.go +++ b/internal/pkg/es/mapping.go @@ -46,6 +46,13 @@ const ( MappingActionData = `{ "properties": { + } +}` + + // ActionResponse The custom action response payload. + MappingActionResponse = `{ + "properties": { + } }` @@ -59,6 +66,10 @@ const ( "action_id": { "type": "keyword" }, + "action_response": { + "enabled" : false, + "type": "object" + }, "agent_id": { "type": "keyword" }, diff --git a/internal/pkg/model/schema.go b/internal/pkg/model/schema.go index 58728bae9..c1cf8160a 100644 --- a/internal/pkg/model/schema.go +++ b/internal/pkg/model/schema.go @@ -65,6 +65,10 @@ type Action struct { type ActionData struct { } +// ActionResponse The custom action response payload. +type ActionResponse struct { +} + // ActionResult An Elastic Agent action results type ActionResult struct { ESDocument @@ -75,6 +79,9 @@ type ActionResult struct { // The action id. ActionId string `json:"action_id,omitempty"` + // The custom action response payload. + ActionResponse json.RawMessage `json:"action_response,omitempty"` + // The agent id. AgentId string `json:"agent_id,omitempty"` diff --git a/model/schema.json b/model/schema.json index eaf3e872c..1af57c407 100644 --- a/model/schema.json +++ b/model/schema.json @@ -97,6 +97,11 @@ "type": "object", "format": "raw" }, + "action_response": { + "description": "The custom action response payload.", + "type": "object", + "format": "raw" + }, "error": { "description": "The action error message.", "type": "string"