Skip to content

Commit

Permalink
[Elastic Agent] Add fleet.host.id for sending to endpoint. (elastic#2…
Browse files Browse the repository at this point in the history
…1042)

* Add fleet.host.id for sending to endpoint.

* Add changelog entry.
  • Loading branch information
blakerouse authored Sep 14, 2020
1 parent c2efa09 commit b67442e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
- Users of the Docker image can now pass `FLEET_ENROLL_INSECURE=1` to include the `--insecure` flag with the `elastic-agent enroll` command {issue}20312[20312] {pull}20713[20713]
- Add support for dynamic inputs with providers and `{{variable|"default"}}` substitution. {pull}20839[20839]
- Add support for EQL based condition on inputs {pull}20994[20994]
- Send `fleet.host.id` to Endpoint Security {pull}21042[21042]
10 changes: 8 additions & 2 deletions x-pack/elastic-agent/pkg/agent/application/fleet_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ package application
import (
"fmt"

"github.com/elastic/go-sysinfo/types"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/transpiler"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/config"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger"
)

func injectFleet(cfg *config.Config) func(*logger.Logger, *transpiler.AST) error {
func injectFleet(cfg *config.Config, hostInfo types.HostInfo) func(*logger.Logger, *transpiler.AST) error {
return func(logger *logger.Logger, rootAst *transpiler.AST) error {
config, err := cfg.ToMapStr()
if err != nil {
Expand All @@ -37,7 +39,11 @@ func injectFleet(cfg *config.Config) func(*logger.Logger, *transpiler.AST) error
return fmt.Errorf("failed to get agent key from fleet config")
}

fleet := transpiler.NewDict([]transpiler.Node{agent, token, kbn})
host := transpiler.NewKey("host", transpiler.NewDict([]transpiler.Node{
transpiler.NewKey("id", transpiler.NewStrVal(hostInfo.UniqueID)),
}))

fleet := transpiler.NewDict([]transpiler.Node{agent, token, kbn, host})
err = transpiler.Insert(rootAst, fleet, "fleet")
if err != nil {
return err
Expand Down
11 changes: 10 additions & 1 deletion x-pack/elastic-agent/pkg/agent/application/managed_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"net/http"
"net/url"

"github.com/elastic/go-sysinfo"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/filters"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/info"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/configuration"
Expand Down Expand Up @@ -113,6 +115,13 @@ func newManaged(
errors.M(errors.MetaKeyURI, cfg.Fleet.Kibana.Host))
}

sysInfo, err := sysinfo.Host()
if err != nil {
return nil, errors.New(err,
"fail to get system information",
errors.TypeUnexpected)
}

managedApplication := &Managed{
log: log,
agentInfo: agentInfo,
Expand Down Expand Up @@ -160,7 +169,7 @@ func newManaged(
router,
&configModifiers{
Decorators: []decoratorFunc{injectMonitoring},
Filters: []filterFunc{filters.StreamChecker, injectFleet(config)},
Filters: []filterFunc{filters.StreamChecker, injectFleet(config, sysInfo.Info())},
},
monitor,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ revision: 5
fleet:
agent:
id: fleet-agent-id
host:
id: host-agent-id
api:
access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw
kibana:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Endpoint Host
fleet:
agent:
id: fleet-agent-id
host:
id: host-agent-id
access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw
kibana:
protocol: https
Expand Down

0 comments on commit b67442e

Please sign in to comment.