-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Missing commits from the initial merges of the agent -> master
- Loading branch information
Showing
11 changed files
with
201 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package fleet | ||
|
||
import ( | ||
xmanagement "github.com/elastic/beats/v7/x-pack/libbeat/management" | ||
) | ||
|
||
// Config for central management | ||
type Config struct { | ||
Enabled bool `config:"enabled" yaml:"enabled"` | ||
Mode string `config:"mode" yaml:"mode"` | ||
Blacklist xmanagement.ConfigBlacklistSettings `config:"blacklist" yaml:"blacklist"` | ||
} | ||
|
||
func defaultConfig() *Config { | ||
return &Config{ | ||
Mode: xmanagement.ModeCentralManagement, | ||
Blacklist: xmanagement.ConfigBlacklistSettings{ | ||
Patterns: map[string]string{ | ||
"output": "console|file", | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package fleet | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/elastic/beats/v7/libbeat/common" | ||
|
||
"github.com/elastic/beats/v7/libbeat/common/reload" | ||
) | ||
|
||
func TestConfigBlocks(t *testing.T) { | ||
input := ` | ||
filebeat: | ||
inputs: | ||
- type: log | ||
paths: | ||
- /var/log/hello1.log | ||
- /var/log/hello2.log | ||
output: | ||
elasticsearch: | ||
hosts: | ||
- localhost:9200` | ||
|
||
var cfg common.MapStr | ||
uconfig, err := common.NewConfigFrom(input) | ||
if err != nil { | ||
t.Fatalf("Config blocks unsuccessfully generated: %+v", err) | ||
} | ||
|
||
err = uconfig.Unpack(&cfg) | ||
if err != nil { | ||
t.Fatalf("Config blocks unsuccessfully generated: %+v", err) | ||
} | ||
|
||
reg := reload.NewRegistry() | ||
reg.Register("output", &dummyReloadable{}) | ||
reg.Register("filebeat.inputs", &dummyReloadable{}) | ||
|
||
cm := &Manager{ | ||
registry: reg, | ||
} | ||
blocks, err := cm.toConfigBlocks(cfg) | ||
if err != nil { | ||
t.Fatalf("Config blocks unsuccessfully generated: %+v", err) | ||
} | ||
|
||
if len(blocks) != 2 { | ||
t.Fatalf("Expected 2 block have %d: %+v", len(blocks), blocks) | ||
} | ||
} | ||
|
||
type dummyReloadable struct{} | ||
|
||
func (dummyReloadable) Reload(config *reload.ConfigWithMeta) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package fleet | ||
|
||
import ( | ||
"github.com/elastic/beats/v7/libbeat/common" | ||
"github.com/elastic/beats/v7/libbeat/feature" | ||
"github.com/elastic/beats/v7/libbeat/management" | ||
xmanagement "github.com/elastic/beats/v7/x-pack/libbeat/management" | ||
) | ||
|
||
func init() { | ||
management.Register("x-pack-fleet", NewFleetManagerPlugin, feature.Beta) | ||
} | ||
|
||
// NewFleetManagerPlugin creates a plugin function returning factory if configuration matches the criteria | ||
func NewFleetManagerPlugin(config *common.Config) management.FactoryFunc { | ||
c := defaultConfig() | ||
if config.Enabled() { | ||
if err := config.Unpack(&c); err != nil { | ||
return nil | ||
} | ||
|
||
if c.Mode == xmanagement.ModeFleet { | ||
return NewFleetManager | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package management | ||
|
||
import ( | ||
"github.com/elastic/beats/v7/libbeat/common" | ||
"github.com/elastic/beats/v7/libbeat/feature" | ||
"github.com/elastic/beats/v7/libbeat/management" | ||
) | ||
|
||
func init() { | ||
management.Register("x-pack", NewManagerPlugin, feature.Beta) | ||
} | ||
|
||
// NewManagerPlugin creates a plugin function returning factory if configuration matches the criteria | ||
func NewManagerPlugin(config *common.Config) management.FactoryFunc { | ||
c := defaultConfig() | ||
if config.Enabled() { | ||
if err := config.Unpack(&c); err != nil { | ||
return nil | ||
} | ||
|
||
if c.Mode == ModeCentralManagement { | ||
return NewConfigManager | ||
} | ||
} | ||
|
||
return nil | ||
} |