-
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.
Add plugin support for autodiscover builders, providers
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) | ||
} |
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 @@ | ||
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) | ||
}) | ||
} |