@@ -7,13 +7,16 @@ package application
7
7
import (
8
8
"context"
9
9
"fmt"
10
+ "time"
10
11
11
12
"github.com/elastic/beats/v7/x-pack/agent/pkg/agent/errors"
12
13
"github.com/elastic/beats/v7/x-pack/agent/pkg/core/logger"
13
14
"github.com/elastic/beats/v7/x-pack/agent/pkg/fleetapi"
14
15
"github.com/elastic/beats/v7/x-pack/agent/pkg/scheduler"
15
16
)
16
17
18
+ const fleetTimeFormat = "2006-01-02T15:04:05.99999-07:00"
19
+
17
20
type actionAcker struct {
18
21
log * logger.Logger
19
22
dispatcher dispatcher
@@ -38,36 +41,38 @@ func newActionAcker(
38
41
39
42
func (f * actionAcker ) Ack (ctx context.Context , action fleetapi.Action ) error {
40
43
// checkin
44
+ agentID := f .agentInfo .AgentID ()
41
45
cmd := fleetapi .NewAckCmd (f .agentInfo , f .client )
42
46
req := & fleetapi.AckRequest {
43
- Actions : []string {
44
- action . ID ( ),
47
+ Events : []fleetapi. AckEvent {
48
+ constructEvent ( action , agentID ),
45
49
},
46
50
}
47
51
48
52
_ , err := cmd .Execute (ctx , req )
49
53
if err != nil {
50
- return errors .New (err , fmt .Sprintf ("acknowledge action '%s' failed" , action .ID ()), errors .TypeNetwork )
54
+ return errors .New (err , fmt .Sprintf ("acknowledge action '%s' for agent '%s' failed" , action .ID (), agentID ), errors .TypeNetwork )
51
55
}
52
56
53
57
return nil
54
58
}
55
59
56
60
func (f * actionAcker ) AckBatch (ctx context.Context , actions []fleetapi.Action ) error {
57
61
// checkin
58
- ids := make ([]string , 0 , len (actions ))
62
+ agentID := f .agentInfo .AgentID ()
63
+ events := make ([]fleetapi.AckEvent , 0 , len (actions ))
59
64
for _ , action := range actions {
60
- ids = append (ids , action . ID ( ))
65
+ events = append (events , constructEvent ( action , agentID ))
61
66
}
62
67
63
68
cmd := fleetapi .NewAckCmd (f .agentInfo , f .client )
64
69
req := & fleetapi.AckRequest {
65
- Actions : ids ,
70
+ Events : events ,
66
71
}
67
72
68
73
_ , err := cmd .Execute (ctx , req )
69
74
if err != nil {
70
- return errors .New (err , fmt .Sprintf ("acknowledge %d actions '%v' failed" , len (actions ), actions ), errors .TypeNetwork )
75
+ return errors .New (err , fmt .Sprintf ("acknowledge %d actions '%v' for agent '%s' failed" , len (actions ), actions , agentID ), errors .TypeNetwork )
71
76
}
72
77
73
78
return nil
@@ -77,6 +82,17 @@ func (f *actionAcker) Commit(ctx context.Context) error {
77
82
return nil
78
83
}
79
84
85
+ func constructEvent (action fleetapi.Action , agentID string ) fleetapi.AckEvent {
86
+ return fleetapi.AckEvent {
87
+ EventType : "ACTION_RESULT" ,
88
+ SubType : "ACKNOWLEDGED" ,
89
+ Timestamp : time .Now ().Format (fleetTimeFormat ),
90
+ ActionID : action .ID (),
91
+ AgentID : agentID ,
92
+ Message : fmt .Sprintf ("Action '%s' ot type '%s' acknowledged." , action .ID (), action .Type ()),
93
+ }
94
+ }
95
+
80
96
type noopAcker struct {}
81
97
82
98
func newNoopAcker () * noopAcker {
0 commit comments