forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
38 lines (33 loc) · 1.09 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
package hipchat
import (
"net/url"
"github.com/pkg/errors"
)
type Config struct {
// Whether HipChat integration is enabled.
Enabled bool `toml:"enabled" override:"enabled"`
// The HipChat API URL.
URL string `toml:"url" override:"url"`
// The authentication token for this notification, can be overridden per alert.
// https://www.hipchat.com/docs/apiv2/auth for info on obtaining a token.
Token string `toml:"token" override:"token,redact"`
// The default room, can be overridden per alert.
Room string `toml:"room" override:"room"`
// Whether all alerts should automatically post to HipChat
Global bool `toml:"global" override:"global"`
// 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"`
}
func NewConfig() Config {
return Config{}
}
func (c Config) Validate() error {
if c.Enabled && 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
}