diff --git a/agent.go b/agent.go index 54e4bd346..5a87f39e4 100644 --- a/agent.go +++ b/agent.go @@ -1,6 +1,7 @@ package tivan import ( + "fmt" "log" "net/url" "os" @@ -82,16 +83,13 @@ func (agent *Agent) Connect() error { func (a *Agent) LoadPlugins() ([]string, error) { var names []string - var pluginNames []string + for _, name := range a.Config.PluginsDeclared() { + creator, ok := plugins.Plugins[name] + if !ok { + return nil, fmt.Errorf("Undefined but requested plugin: %s", name) + } - for name, _ := range plugins.Plugins { - pluginNames = append(pluginNames, name) - } - - sort.Strings(pluginNames) - - for _, name := range pluginNames { - plugin := plugins.Plugins[name]() + plugin := creator() err := a.Config.Apply(name, plugin) if err != nil { @@ -128,6 +126,35 @@ func (a *Agent) crank() error { return err } +func (a *Agent) TestAllPlugins() error { + var names []string + + for name, _ := range plugins.Plugins { + names = append(names, name) + } + + sort.Strings(names) + + var acc BatchPoints + acc.Debug = true + + fmt.Printf("* Testing all plugins with default configuration\n") + + for _, name := range names { + plugin := plugins.Plugins[name]() + + fmt.Printf("* Plugin: %s\n", name) + + acc.Prefix = name + "_" + err := plugin.Gather(&acc) + if err != nil { + return err + } + } + + return nil +} + func (a *Agent) Test() error { var acc BatchPoints diff --git a/cmd/tivan/tivan.go b/cmd/tivan/tivan.go index 6cb5e4733..6a11657a0 100644 --- a/cmd/tivan/tivan.go +++ b/cmd/tivan/tivan.go @@ -56,7 +56,12 @@ func main() { } if *fTest { - err = ag.Test() + if *fConfig != "" { + err = ag.Test() + } else { + err = ag.TestAllPlugins() + } + if err != nil { log.Fatal(err) } diff --git a/config.go b/config.go index 57dbd5af0..5c4a3e591 100644 --- a/config.go +++ b/config.go @@ -50,6 +50,18 @@ func (c *Config) Apply(name string, v interface{}) error { return nil } +func (c *Config) PluginsDeclared() []string { + var plugins []string + + for name, _ := range c.plugins { + plugins = append(plugins, name) + } + + sort.Strings(plugins) + + return plugins +} + func DefaultConfig() *Config { return &Config{} }