diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 97d30fef375..685132335cc 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -179,6 +179,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di - The node name can be discovered automatically by machine-id matching when beat deployed outside kubernetes cluster. {pull}6146[6146] - Panics will be written to the logger before exiting. {pull}6199[6199] - Add builder support for autodiscover and annotations builder {pull}6408[6408] +- Add plugin support for autodiscover builders, providers {pull}6457[6457] *Auditbeat* diff --git a/libbeat/autodiscover/builder/plugin.go b/libbeat/autodiscover/builder/plugin.go new file mode 100644 index 00000000000..1db99b1b020 --- /dev/null +++ b/libbeat/autodiscover/builder/plugin.go @@ -0,0 +1,31 @@ +package builder + +import ( + "errors" + + "github.com/elastic/beats/libbeat/autodiscover" + p "github.com/elastic/beats/libbeat/plugin" +) + +type builderPlugin struct { + name string + builder autodiscover.BuilderConstructor +} + +var pluginKey = "libbeat.autodiscover.builder" + +// Plugin accepts a BuilderConstructor to be registered as a plugin +func Plugin(name string, b autodiscover.BuilderConstructor) map[string][]interface{} { + return p.MakePlugin(pluginKey, builderPlugin{name, b}) +} + +func init() { + p.MustRegisterLoader(pluginKey, func(ifc interface{}) error { + b, ok := ifc.(builderPlugin) + if !ok { + return errors.New("plugin does not match processor plugin type") + } + + return autodiscover.Registry.AddBuilder(b.name, b.builder) + }) +} diff --git a/libbeat/autodiscover/providers/plugin.go b/libbeat/autodiscover/providers/plugin.go new file mode 100644 index 00000000000..cfdc88a73e7 --- /dev/null +++ b/libbeat/autodiscover/providers/plugin.go @@ -0,0 +1,31 @@ +package providers + +import ( + "errors" + + "github.com/elastic/beats/libbeat/autodiscover" + p "github.com/elastic/beats/libbeat/plugin" +) + +type providerPlugin struct { + name string + provider autodiscover.ProviderBuilder +} + +var pluginKey = "libbeat.autodiscover.provider" + +// Plugin accepts a ProviderBuilder to be registered as a plugin +func Plugin(name string, provider autodiscover.ProviderBuilder) map[string][]interface{} { + return p.MakePlugin(pluginKey, providerPlugin{name, provider}) +} + +func init() { + p.MustRegisterLoader(pluginKey, func(ifc interface{}) error { + prov, ok := ifc.(providerPlugin) + if !ok { + return errors.New("plugin does not match processor plugin type") + } + + return autodiscover.Registry.AddProvider(prov.name, prov.provider) + }) +}