-
Notifications
You must be signed in to change notification settings - Fork 495
/
config.go
58 lines (45 loc) · 1.58 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
package bigpanda
import (
"github.com/pkg/errors"
"net/url"
)
const (
defaultBigPandaAlertApi = "https://api.bigpanda.io/data/v2/alerts"
)
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"`
}
func NewConfig() Config {
return Config{
URL: defaultBigPandaAlertApi,
}
}
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
}