forked from influxdata/kapacitor
/
config.go
53 lines (47 loc) · 1.49 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package influxdb
import (
"net/url"
"time"
"github.com/influxdata/kapacitor/services/stats"
"github.com/influxdata/kapacitor/services/udp"
"github.com/influxdb/influxdb/toml"
)
const (
// Maximum time to try and connect to InfluxDB during startup.
DefaultStartUpTimeout = time.Minute * 5
)
type Config struct {
Enabled bool `toml:"enabled"`
URLs []string `toml:"urls"`
Username string `toml:"username"`
Password string `toml:"password"`
Timeout toml.Duration `toml:"timeout"`
Subscriptions map[string][]string `toml:"subscriptions"`
ExcludedSubscriptions map[string][]string `toml:"excluded-subscriptions"`
UDPBuffer int `toml:"udp-buffer"`
UDPReadBuffer int `toml:"udp-read-buffer"`
StartUpTimeout toml.Duration `toml:"startup-timeout"`
}
func NewConfig() Config {
return Config{
Enabled: true,
URLs: []string{"http://localhost:8086"},
Username: "",
Password: "",
Subscriptions: make(map[string][]string),
ExcludedSubscriptions: map[string][]string{
stats.DefaultDatabse: []string{stats.DefaultRetentionPolicy},
},
UDPBuffer: udp.DefaultBuffer,
StartUpTimeout: toml.Duration(DefaultStartUpTimeout),
}
}
func (c Config) Validate() error {
for _, u := range c.URLs {
_, err := url.Parse(u)
if err != nil {
return err
}
}
return nil
}