-
Notifications
You must be signed in to change notification settings - Fork 493
/
config.go
63 lines (49 loc) · 1.84 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
58
59
60
61
62
63
package bigpanda
import (
"net/url"
"github.com/pkg/errors"
)
const (
defaultBigPandaAlertApi = "https://api.bigpanda.io/data/v2/alerts"
defaultAutoAttributes = "tags,fields"
)
type Config struct {
// Whether BigPanda integration is enabled.
Enabled bool `toml:"enabled" override:"enabled"`
// Whether all alerts should automatically post to BigPanda.
Global bool `toml:"global" override:"global"`
// Each integration must have an App Key in BigPanda to identify it as a unique source.
AppKey string `toml:"app-key" override:"app-key"`
// Each integration must have an App Key in BigPanda to identify it as a unique source.
Token string `toml:"token" override:"token,redact"`
// Whether all alerts should automatically use stateChangesOnly mode.
// Only applies if global is also set.
StateChangesOnly bool `toml:"state-changes-only" override:"state-changes-only"`
// Whether to skip the tls verification
InsecureSkipVerify bool `toml:"insecure-skip-verify" override:"insecure-skip-verify"`
// BigPanda Alert API URL, if not specified https://api.bigpanda.io/data/v2/alerts is used.
URL string `toml:"url" override:"url"`
// Option to control tags and fields serialization into payload (for backward compatibility).
AutoAttributes string `toml:"auto-attributes" override:"auto-attributes"`
}
func NewConfig() Config {
return Config{
URL: defaultBigPandaAlertApi,
AutoAttributes: defaultAutoAttributes,
}
}
func (c Config) Validate() error {
if c.Enabled && c.URL == "" {
return errors.New("must specify the BigPanda webhook URL")
}
if c.Enabled && c.AppKey == "" {
return errors.New("must specify BigPanda app-key")
}
if _, err := url.Parse(c.URL); err != nil {
return errors.Wrapf(err, "invalid url %q", c.URL)
}
if c.Enabled && c.Token == "" {
return errors.New("must specify BigPanda token")
}
return nil
}