diff --git a/agent/agent.go b/agent/agent.go index 41a5552c5..999c278fa 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -19,7 +19,8 @@ import ( // Agent runs telegraf and collects data based on the given config type Agent struct { - Config *config.Config + Config *config.Config + Version string } // NewAgent returns an Agent struct based off the given Config @@ -329,7 +330,7 @@ func (a *Agent) Run(shutdown chan struct{}) error { } ticker := time.NewTicker(a.Config.Agent.Interval.Duration) - ent := enterprise.NewEnterprise(a.Config.Agent.Enterprise, a.Config.Agent.Hostname, shutdown) + ent := enterprise.NewEnterprise(a.Config.Agent.Enterprise, a.Config.Agent.Hostname, a.Version, shutdown) go ent.Open() wg.Add(1) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index a65c5607c..7c9a1c4cb 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -174,6 +174,7 @@ func main() { } ag, err := agent.NewAgent(c) + ag.Version = Version if err != nil { log.Fatal(err) } diff --git a/services/enterprise/enterprise.go b/services/enterprise/enterprise.go index 999c9334e..58ced754c 100644 --- a/services/enterprise/enterprise.go +++ b/services/enterprise/enterprise.go @@ -21,18 +21,20 @@ type Service struct { hosts []*client.Host logger *log.Logger hostname string + version string adminPort string shutdown chan struct{} } -func NewEnterprise(c Config, hostname string, shutdown chan struct{}) *Service { +func NewEnterprise(c Config, hostname, version string, shutdown chan struct{}) *Service { return &Service{ hosts: c.Hosts, hostname: hostname, logger: log.New(os.Stdout, "[enterprise]", log.Ldate|log.Ltime), adminPort: fmt.Sprintf(":%d", c.AdminPort), shutdown: shutdown, + version: version, } } @@ -60,7 +62,7 @@ func (s *Service) registerProduct(cl *client.Client) (token string, secret strin Host: s.hostname, ClusterID: "8675309", Name: "telegraf", - Version: "0.10.1.dev", + Version: s.version, AdminURL: "http://" + s.hostname + s.adminPort, } diff --git a/services/enterprise/enterprise_test.go b/services/enterprise/enterprise_test.go index 92c2cb45e..ae9fc3df9 100644 --- a/services/enterprise/enterprise_test.go +++ b/services/enterprise/enterprise_test.go @@ -47,7 +47,7 @@ func Test_RegistersWithEnterprise(t *testing.T) { shutdown := make(chan struct{}) defer close(shutdown) - e := enterprise.NewEnterprise(c, expected, shutdown) + e := enterprise.NewEnterprise(c, expected, "test", shutdown) e.Open() timeout := time.After(1 * time.Millisecond) @@ -80,7 +80,7 @@ func Test_StartsAdminInterface(t *testing.T) { shutdown := make(chan struct{}) defer close(shutdown) - e := enterprise.NewEnterprise(c, hostname, shutdown) + e := enterprise.NewEnterprise(c, hostname, "test", shutdown) e.Open() timeout := time.After(1 * time.Millisecond) @@ -113,7 +113,7 @@ func Test_ClosesAdminInterface(t *testing.T) { } shutdown := make(chan struct{}) - e := enterprise.NewEnterprise(c, hostname, shutdown) + e := enterprise.NewEnterprise(c, hostname, "test", shutdown) e.Open() timeout := time.After(1 * time.Millisecond)