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 (
|
|
|
|
"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) {
|
|
|
|
if src.Type == "influx-enterprise" {
|
|
|
|
return enterprise.NewClientWithURL(src.URL, src.Username, src.Password, false, logger)
|
|
|
|
}
|
|
|
|
return &influx.Client{
|
|
|
|
Logger: logger,
|
|
|
|
}, nil
|
|
|
|
}
|