From a3cfd52c51f1403dad83893e8ab6879e36eeef4d Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Tue, 24 Nov 2020 16:10:19 -0700 Subject: [PATCH 1/4] Update kibana config to include username and password --- libbeat/cmd/export/dashboard.go | 11 ++++++++++- libbeat/cmd/instance/beat.go | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libbeat/cmd/export/dashboard.go b/libbeat/cmd/export/dashboard.go index 9cd63f03366..afe4c9cd7ba 100644 --- a/libbeat/cmd/export/dashboard.go +++ b/libbeat/cmd/export/dashboard.go @@ -49,7 +49,16 @@ func GenDashboardCmd(settings instance.Settings) *cobra.Command { b.Config.Kibana = common.NewConfig() } - client, err := kibana.NewKibanaClient(b.Config.Kibana) + // Initialize kibana config. If username and password is set in + // elasticsearch output config but not in kibana, initKibanaConfig + // will attach the username and password into kibana config as a + // part of the initialization. + initConfig, err := instance.InitKibanaConfig(b.Config) + if err != nil { + fatalf("error InitKibanaConfig: %v", err) + } + + client, err := kibana.NewKibanaClient(initConfig) if err != nil { fatalf("Error creating Kibana client: %+v.\n", err) } diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index b873ddebf95..8bc2bae7188 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -774,9 +774,9 @@ func (b *Beat) loadDashboards(ctx context.Context, force bool) error { // Initialize kibana config. If username and password is set in elasticsearch output config but not in kibana, // initKibanaConfig will attach the username and password into kibana config as a part of the initialization. - kibanaConfig, err := initKibanaConfig(b.Config) + kibanaConfig, err := InitKibanaConfig(b.Config) if err != nil { - return fmt.Errorf("error initKibanaConfig: %v", err) + return fmt.Errorf("error InitKibanaConfig: %v", err) } client, err := kibana.NewKibanaClient(kibanaConfig) @@ -1041,7 +1041,7 @@ func LoadKeystore(cfg *common.Config, name string) (keystore.Keystore, error) { return keystore.Factory(keystoreCfg, defaultPathConfig) } -func initKibanaConfig(beatConfig beatConfig) (*common.Config, error) { +func InitKibanaConfig(beatConfig beatConfig) (*common.Config, error) { var esConfig *common.Config if beatConfig.Output.Name() == "elasticsearch" { esConfig = beatConfig.Output.Config() From 45b337de194e5a022debb47068e6776586d679a6 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Tue, 24 Nov 2020 16:20:04 -0700 Subject: [PATCH 2/4] add changelog --- CHANGELOG-developer.next.asciidoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-developer.next.asciidoc b/CHANGELOG-developer.next.asciidoc index 0756e36fdf5..edec465f854 100644 --- a/CHANGELOG-developer.next.asciidoc +++ b/CHANGELOG-developer.next.asciidoc @@ -57,6 +57,7 @@ The list below covers the major changes between 7.0.0-rc2 and master only. - Stop using `mage:import` in community beats. This was ignoring the vendorized beats directory for some mage targets, using the code available in GOPATH, this causes inconsistencies and compilation problems if the version of the code in the GOPATH is different to the vendored one. Use of `mage:import` will continue to be unsupported in custom beats till beats is migrated to go modules, or mage supports vendored dependencies. {issue}13998[13998] {pull}14162[14162] - Metricbeat module builders call host parser only once when instantiating light modules. {pull}20149[20149] +- Fix export dashboard command when running against Elastic Cloud hosted Kibana. {pull}22746[22746] ==== Added @@ -102,4 +103,4 @@ The list below covers the major changes between 7.0.0-rc2 and master only. - Update Go version to 1.14.7. {pull}20508[20508] - Add packaging for docker image based on UBI minimal 8. {pull}20576[20576] - Make the mage binary used by the build process in the docker container to be statically compiled. {pull}20827[20827] -- Update ecszap to v0.3.0 for using ECS 1.6.0 in logs {pull}22267[22267] \ No newline at end of file +- Update ecszap to v0.3.0 for using ECS 1.6.0 in logs {pull}22267[22267] From 6e6bf441c9455daa0bb9bf822750c0060e5ebd8b Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Tue, 24 Nov 2020 17:15:12 -0700 Subject: [PATCH 3/4] Fix beat_test.go --- libbeat/cmd/instance/beat_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbeat/cmd/instance/beat_test.go b/libbeat/cmd/instance/beat_test.go index e302bed1711..efe61ad1ecb 100644 --- a/libbeat/cmd/instance/beat_test.go +++ b/libbeat/cmd/instance/beat_test.go @@ -82,7 +82,7 @@ func TestInitKibanaConfig(t *testing.T) { err = cfg.Unpack(&b.Config) assert.NoError(t, err) - kibanaConfig, err := initKibanaConfig(b.Config) + kibanaConfig, err := InitKibanaConfig(b.Config) assert.NoError(t, err) username, err := kibanaConfig.String("username", -1) password, err := kibanaConfig.String("password", -1) From 78083012cf6298e42c5a9063b7861e06cae78b2d Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Wed, 25 Nov 2020 09:37:38 -0700 Subject: [PATCH 4/4] Remove return error from InitKibanaConfig function --- libbeat/cmd/export/dashboard.go | 5 +---- libbeat/cmd/instance/beat.go | 9 +++------ libbeat/cmd/instance/beat_test.go | 3 +-- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/libbeat/cmd/export/dashboard.go b/libbeat/cmd/export/dashboard.go index afe4c9cd7ba..5d3a782f1ad 100644 --- a/libbeat/cmd/export/dashboard.go +++ b/libbeat/cmd/export/dashboard.go @@ -53,10 +53,7 @@ func GenDashboardCmd(settings instance.Settings) *cobra.Command { // elasticsearch output config but not in kibana, initKibanaConfig // will attach the username and password into kibana config as a // part of the initialization. - initConfig, err := instance.InitKibanaConfig(b.Config) - if err != nil { - fatalf("error InitKibanaConfig: %v", err) - } + initConfig := instance.InitKibanaConfig(b.Config) client, err := kibana.NewKibanaClient(initConfig) if err != nil { diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index 8bc2bae7188..0ec0bacc769 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -774,10 +774,7 @@ func (b *Beat) loadDashboards(ctx context.Context, force bool) error { // Initialize kibana config. If username and password is set in elasticsearch output config but not in kibana, // initKibanaConfig will attach the username and password into kibana config as a part of the initialization. - kibanaConfig, err := InitKibanaConfig(b.Config) - if err != nil { - return fmt.Errorf("error InitKibanaConfig: %v", err) - } + kibanaConfig := InitKibanaConfig(b.Config) client, err := kibana.NewKibanaClient(kibanaConfig) if err != nil { @@ -1041,7 +1038,7 @@ func LoadKeystore(cfg *common.Config, name string) (keystore.Keystore, error) { return keystore.Factory(keystoreCfg, defaultPathConfig) } -func InitKibanaConfig(beatConfig beatConfig) (*common.Config, error) { +func InitKibanaConfig(beatConfig beatConfig) *common.Config { var esConfig *common.Config if beatConfig.Output.Name() == "elasticsearch" { esConfig = beatConfig.Output.Config() @@ -1064,7 +1061,7 @@ func InitKibanaConfig(beatConfig beatConfig) (*common.Config, error) { kibanaConfig.SetString("password", -1, password) } } - return kibanaConfig, nil + return kibanaConfig } func initPaths(cfg *common.Config) error { diff --git a/libbeat/cmd/instance/beat_test.go b/libbeat/cmd/instance/beat_test.go index efe61ad1ecb..a0db00c853c 100644 --- a/libbeat/cmd/instance/beat_test.go +++ b/libbeat/cmd/instance/beat_test.go @@ -82,8 +82,7 @@ func TestInitKibanaConfig(t *testing.T) { err = cfg.Unpack(&b.Config) assert.NoError(t, err) - kibanaConfig, err := InitKibanaConfig(b.Config) - assert.NoError(t, err) + kibanaConfig := InitKibanaConfig(b.Config) username, err := kibanaConfig.String("username", -1) password, err := kibanaConfig.String("password", -1) protocol, err := kibanaConfig.String("protocol", -1)