2016-10-25 15:20:06 +00:00
|
|
|
package server
|
2016-09-30 20:39:27 +00:00
|
|
|
|
2017-02-24 03:54:20 +00:00
|
|
|
import (
|
2017-02-24 20:48:42 +00:00
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
|
2017-02-24 03:54:20 +00:00
|
|
|
"github.com/influxdata/chronograf"
|
|
|
|
"github.com/influxdata/chronograf/enterprise"
|
|
|
|
"github.com/influxdata/chronograf/influx"
|
|
|
|
)
|
2016-09-30 20:39:27 +00:00
|
|
|
|
2016-10-28 16:27:06 +00:00
|
|
|
// Service handles REST calls to the persistence
|
|
|
|
type Service struct {
|
2017-02-24 03:54:20 +00:00
|
|
|
SourcesStore chronograf.SourcesStore
|
|
|
|
ServersStore chronograf.ServersStore
|
|
|
|
LayoutStore chronograf.LayoutStore
|
|
|
|
AlertRulesStore chronograf.AlertRulesStore
|
|
|
|
UsersStore chronograf.UsersStore
|
|
|
|
DashboardsStore chronograf.DashboardsStore
|
|
|
|
TimeSeriesClient TimeSeriesClient
|
|
|
|
Logger chronograf.Logger
|
|
|
|
UseAuth bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// TimeSeriesClient returns the correct client for a time series database.
|
|
|
|
type TimeSeriesClient interface {
|
|
|
|
New(chronograf.Source, chronograf.Logger) (chronograf.TimeSeries, error)
|
2016-09-30 20:39:27 +00:00
|
|
|
}
|
2016-11-19 17:41:06 +00:00
|
|
|
|
|
|
|
// ErrorMessage is the error response format for all service errors
|
|
|
|
type ErrorMessage struct {
|
|
|
|
Code int `json:"code"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
}
|
2017-02-24 03:54:20 +00:00
|
|
|
|
|
|
|
// TimeSeries returns a new client connected to a time series database
|
|
|
|
func (s *Service) TimeSeries(src chronograf.Source) (chronograf.TimeSeries, error) {
|
|
|
|
return s.TimeSeriesClient.New(src, s.Logger)
|
|
|
|
}
|
|
|
|
|
|
|
|
// InfluxClient returns a new client to connect to OSS or Enterprise
|
|
|
|
type InfluxClient struct{}
|
|
|
|
|
|
|
|
// New creates a client to connect to OSS or enterprise
|
|
|
|
func (c *InfluxClient) New(src chronograf.Source, logger chronograf.Logger) (chronograf.TimeSeries, error) {
|
2017-02-24 20:48:42 +00:00
|
|
|
if src.Type == "influx-enterprise" && src.MetaURL != "" {
|
|
|
|
dataNode := &influx.Client{
|
|
|
|
Logger: logger,
|
|
|
|
}
|
|
|
|
if err := dataNode.Connect(context.TODO(), &src); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
tls := strings.Contains(src.MetaURL, "https")
|
|
|
|
return enterprise.NewClientWithTimeSeries(logger, src.MetaURL, src.Username, src.Password, tls, dataNode)
|
2017-02-24 03:54:20 +00:00
|
|
|
}
|
|
|
|
return &influx.Client{
|
|
|
|
Logger: logger,
|
|
|
|
}, nil
|
|
|
|
}
|