/
config.go
57 lines (48 loc) · 1.37 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
54
55
56
57
package pushover
import (
"net/url"
"github.com/pkg/errors"
)
// DefaultPushoverURL is the default URL for the Pushover API.
const (
DefaultPushoverURL = "https://api.pushover.net/1/messages.json"
)
// Config is the [pushover] configuration as defined in the Kapacitor configuration file.
type Config struct {
// Whether Pushover integration is enabled.
Enabled bool `toml:"enabled" override:"enabled"`
// The Pushover API token.
Token string `toml:"token" override:"token,redact"`
// The User/Group that will be alerted.
UserKey string `toml:"user-key" override:"user-key,redact"`
// The URL for the Pushover API.
// Default: DefaultPushoverAPI
URL string `toml:"url" override:"url"`
}
// NewConfig returns a new Pushover configuration with the URL set to be
// the default pushover URL.
func NewConfig() Config {
return Config{
URL: DefaultPushoverURL,
}
}
// Validate ensures that all configuration options are valid. The
// Token, User, and URL parameters must be specified to be considered
// valid.
func (c Config) Validate() error {
if c.Enabled {
if c.Token == "" {
return errors.New("must specify token")
}
if c.UserKey == "" {
return errors.New("must specify user key")
}
if c.URL == "" {
return errors.New("must specify url")
}
if _, err := url.Parse(c.URL); err != nil {
return errors.Wrapf(err, "invalid URL %q", c.URL)
}
}
return nil
}