From 88c8fcca331e0a9f510ee658ac312a373daebacc Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Thu, 11 Apr 2024 11:16:59 -0400 Subject: [PATCH] More adjustments. --- filebeat/autodiscover/defaults_aix.go | 4 ++-- filebeat/tests/system/test_autodiscover.py | 19 +++++++++++++++++-- heartbeat/include/fields.go | 2 -- heartbeat/monitors/active/http/http.go | 3 +-- heartbeat/monitors/active/http/http_test.go | 4 ---- heartbeat/monitors/active/icmp/icmp.go | 3 +-- heartbeat/monitors/active/icmp/icmp_test.go | 4 ---- heartbeat/monitors/active/tcp/tcp.go | 3 +-- heartbeat/monitors/active/tcp/tcp_test.go | 4 ---- libbeat/asset/asset.go | 1 + metricbeat/include/list_init.go | 3 ++- .../tests/system/test_0065_unmatched_http.py | 2 +- x-pack/auditbeat/cmd/root.go | 14 +++++--------- x-pack/osquerybeat/cmd/root.go | 2 +- 14 files changed, 32 insertions(+), 36 deletions(-) diff --git a/filebeat/autodiscover/defaults_aix.go b/filebeat/autodiscover/defaults_aix.go index c666d50fb0e6..713b13ca8b3d 100644 --- a/filebeat/autodiscover/defaults_aix.go +++ b/filebeat/autodiscover/defaults_aix.go @@ -19,7 +19,7 @@ package autodiscover -// Initialize initializes the configuration defaults for autodiscover for filebeat. -func Initialize() { +// InitializeModule initializes this module. +func InitializeModule() { // does nothing on aix } diff --git a/filebeat/tests/system/test_autodiscover.py b/filebeat/tests/system/test_autodiscover.py index c5b8026ddb18..8f89f21b374d 100644 --- a/filebeat/tests/system/test_autodiscover.py +++ b/filebeat/tests/system/test_autodiscover.py @@ -24,8 +24,23 @@ def test_docker(self): autodiscover={ 'docker': { 'cleanup_timeout': '0s', - 'templates': f''' - condition: - equals.docker.container.name: {container.name} config: - type: log paths: - %s/${{data.docker.container.name}}.log ''' % self.working_dir, }, },) proc = self.start_beat() self._test(container) self.wait_until(lambda: self.log_contains('Stopping runner: input')) proc.check_kill_and_wait() + 'templates': f''' + - condition: + equals.docker.container.name: {container.name} + config: + - type: log + paths: + - %s/${{data.docker.container.name}}.log + ''' % self.working_dir, + }, + }, + ) + + proc = self.start_beat() + self._test(container) + + self.wait_until(lambda: self.log_contains('Stopping runner: input')) + proc.check_kill_and_wait() @unittest.skipIf(not INTEGRATION_TESTS or os.getenv("TESTING_ENVIRONMENT") == "2x", diff --git a/heartbeat/include/fields.go b/heartbeat/include/fields.go index 01a6d8e5e39f..4a975fc88203 100644 --- a/heartbeat/include/fields.go +++ b/heartbeat/include/fields.go @@ -17,8 +17,6 @@ // Code generated by beats/dev-tools/cmd/asset/asset.go - DO NOT EDIT. -//go:build !agentbeat - package include import ( diff --git a/heartbeat/monitors/active/http/http.go b/heartbeat/monitors/active/http/http.go index c16087d4e8f0..ad9a9df98c0c 100644 --- a/heartbeat/monitors/active/http/http.go +++ b/heartbeat/monitors/active/http/http.go @@ -33,8 +33,7 @@ import ( "github.com/elastic/elastic-agent-libs/useragent" ) -// InitializeModule initializes this module. -func InitializeModule() { +func init() { plugin.Register("http", create, "synthetics/http") } diff --git a/heartbeat/monitors/active/http/http_test.go b/heartbeat/monitors/active/http/http_test.go index e37ca85f0f59..20575210ac96 100644 --- a/heartbeat/monitors/active/http/http_test.go +++ b/heartbeat/monitors/active/http/http_test.go @@ -59,10 +59,6 @@ import ( btesting "github.com/elastic/beats/v7/libbeat/testing" ) -func TestMain(m *testing.M) { - InitializeModule() -} - func sendSimpleTLSRequest(t *testing.T, testURL string, useUrls bool) *beat.Event { return sendTLSRequest(t, testURL, useUrls, nil) } diff --git a/heartbeat/monitors/active/icmp/icmp.go b/heartbeat/monitors/active/icmp/icmp.go index 3901b320737f..5bb3504014ac 100644 --- a/heartbeat/monitors/active/icmp/icmp.go +++ b/heartbeat/monitors/active/icmp/icmp.go @@ -37,8 +37,7 @@ import ( var debugf = logp.MakeDebug("icmp") -// InitializeModule initializes this module. -func InitializeModule() { +func init() { plugin.Register("icmp", create, "synthetics/icmp") } diff --git a/heartbeat/monitors/active/icmp/icmp_test.go b/heartbeat/monitors/active/icmp/icmp_test.go index a2dfd316f665..59ffc257505d 100644 --- a/heartbeat/monitors/active/icmp/icmp_test.go +++ b/heartbeat/monitors/active/icmp/icmp_test.go @@ -37,10 +37,6 @@ import ( "github.com/elastic/beats/v7/libbeat/beat" ) -func TestMain(m *testing.M) { - InitializeModule() -} - func TestICMPFields(t *testing.T) { host := "localhost" hostURL := &url.URL{Scheme: "icmp", Host: host} diff --git a/heartbeat/monitors/active/tcp/tcp.go b/heartbeat/monitors/active/tcp/tcp.go index afe779e8e420..57305203b3aa 100644 --- a/heartbeat/monitors/active/tcp/tcp.go +++ b/heartbeat/monitors/active/tcp/tcp.go @@ -41,8 +41,7 @@ import ( "github.com/elastic/elastic-agent-libs/transport/tlscommon" ) -// InitializeModule initializes this module. -func InitializeModule() { +func init() { plugin.Register("tcp", create, "synthetics/tcp") } diff --git a/heartbeat/monitors/active/tcp/tcp_test.go b/heartbeat/monitors/active/tcp/tcp_test.go index 8194fcf64e54..c5cc0dd614e6 100644 --- a/heartbeat/monitors/active/tcp/tcp_test.go +++ b/heartbeat/monitors/active/tcp/tcp_test.go @@ -40,10 +40,6 @@ import ( btesting "github.com/elastic/beats/v7/libbeat/testing" ) -func TestMain(m *testing.M) { - InitializeModule() -} - func testTCPCheck(t *testing.T, host string, port uint16) *beat.Event { config := mapstr.M{ "hosts": host, diff --git a/libbeat/asset/asset.go b/libbeat/asset/asset.go index 76dfaa3ee194..e26a4881618c 100644 --- a/libbeat/asset/asset.go +++ b/libbeat/asset/asset.go @@ -59,6 +59,7 @@ func init() { func Asset{{ .GoTypeName }}() string { return "{{ .Data }}" } + `)) type Data struct { diff --git a/metricbeat/include/list_init.go b/metricbeat/include/list_init.go index fbfa58a65c5c..037e00b28915 100644 --- a/metricbeat/include/list_init.go +++ b/metricbeat/include/list_init.go @@ -21,9 +21,10 @@ package include import ( // Import packages to perform 'func InitializeModule()' when in-use. - m1 "github.com/elastic/beats/v7/metricbeat/autodiscover/appender/kubernetes/token" m0 "github.com/elastic/beats/v7/metricbeat/autodiscover/builder/hints" + m1 "github.com/elastic/beats/v7/metricbeat/autodiscover/appender/kubernetes/token" m2 "github.com/elastic/beats/v7/metricbeat/processor/add_kubernetes_metadata" + // Import packages that perform 'func init()'. ) diff --git a/packetbeat/tests/system/test_0065_unmatched_http.py b/packetbeat/tests/system/test_0065_unmatched_http.py index 2cfeb41d3480..f8c7ec810b01 100644 --- a/packetbeat/tests/system/test_0065_unmatched_http.py +++ b/packetbeat/tests/system/test_0065_unmatched_http.py @@ -4,7 +4,7 @@ def check_event(event, expected): for key in expected: assert key in event, "key '{0}' not found in event".format(key) - assert event[key] == expected[key], \ + assert event[key] == expected[key],\ "key '{0}' has value '{1}', expected '{2}'".format(key, event[key], expected[key]) diff --git a/x-pack/auditbeat/cmd/root.go b/x-pack/auditbeat/cmd/root.go index 0b1f4e1e5664..4e229c849224 100644 --- a/x-pack/auditbeat/cmd/root.go +++ b/x-pack/auditbeat/cmd/root.go @@ -21,15 +21,10 @@ import ( "github.com/elastic/beats/v7/x-pack/auditbeat/include" "github.com/elastic/beats/v7/x-pack/libbeat/management" - // Register includes. + // Register base auditbeat includes. _ "github.com/elastic/beats/v7/auditbeat/include" - // Register modules. - _ "github.com/elastic/beats/v7/auditbeat/module/auditd" - _ "github.com/elastic/beats/v7/auditbeat/module/file_integrity" - - // Register Auditbeat x-pack modules. - _ "github.com/elastic/beats/v7/x-pack/auditbeat/include" + // Register libbeat x-pack modules. _ "github.com/elastic/beats/v7/x-pack/libbeat/include" ) @@ -47,9 +42,10 @@ func auditbeatCfg(rawIn *proto.UnitExpectedConfig, agentInfo *client.AgentInfo) return nil, fmt.Errorf("error creating input list from raw expected config: %w", err) } - // not running in agentbeat; extract the type field that has - // "audit/auditd", treat this as the module config key + // Extract the type field that has "audit/auditd", treat this + // as the module config key module := strings.Split(rawIn.Type, "/")[1] + for iter := range modules { modules[iter]["module"] = module } diff --git a/x-pack/osquerybeat/cmd/root.go b/x-pack/osquerybeat/cmd/root.go index fc79ffe46166..73584ec06f12 100644 --- a/x-pack/osquerybeat/cmd/root.go +++ b/x-pack/osquerybeat/cmd/root.go @@ -9,7 +9,6 @@ import ( "github.com/spf13/cobra" - "github.com/elastic/beats/v7/x-pack/libbeat/management" "github.com/elastic/elastic-agent-client/v7/pkg/client" "github.com/elastic/elastic-agent-client/v7/pkg/proto" "github.com/elastic/elastic-agent-libs/logp" @@ -23,6 +22,7 @@ import ( "github.com/elastic/beats/v7/libbeat/processors" "github.com/elastic/beats/v7/libbeat/publisher/processing" _ "github.com/elastic/beats/v7/x-pack/libbeat/include" + "github.com/elastic/beats/v7/x-pack/libbeat/management" "github.com/elastic/beats/v7/x-pack/osquerybeat/beater" _ "github.com/elastic/beats/v7/x-pack/osquerybeat/include" "github.com/elastic/beats/v7/x-pack/osquerybeat/internal/config"