telegraf/services/enterprise/enterprise.go

48 lines
873 B
Go
Raw Normal View History

2016-02-10 19:54:34 +00:00
package enterprise
import (
"log"
"os"
"github.com/influxdata/enterprise-client/v2"
)
type Config struct {
Hosts []*client.Host
}
type Service struct {
2016-02-10 20:42:07 +00:00
hosts []*client.Host
logger *log.Logger
hostname string
2016-02-10 19:54:34 +00:00
}
2016-02-10 20:42:07 +00:00
func NewEnterprise(c Config, hostname string) *Service {
2016-02-10 19:54:34 +00:00
return &Service{
2016-02-10 20:42:07 +00:00
hosts: c.Hosts,
hostname: hostname,
logger: log.New(os.Stdout, "[enterprise]", log.Ldate|log.Ltime),
2016-02-10 19:54:34 +00:00
}
}
func (s *Service) Open() {
cl, err := client.New(s.hosts)
if err != nil {
s.logger.Printf("Unable to contact one or more Enterprise hosts. err: %s", err.Error())
return
}
go s.registerProduct(cl)
}
func (s *Service) registerProduct(cl *client.Client) {
p := client.Product{
ProductID: "telegraf",
2016-02-10 20:42:07 +00:00
Host: s.hostname,
2016-02-10 19:54:34 +00:00
}
_, err := cl.Register(&p)
if err != nil {
s.logger.Println("Unable to register Telegraf with Enterprise")
}
}