forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
54 lines (47 loc) · 1.72 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
package slack
import (
"net/url"
"github.com/pkg/errors"
)
const DefaultUsername = "kapacitor"
type Config struct {
// Whether Slack integration is enabled.
Enabled bool `toml:"enabled" override:"enabled"`
// The Slack webhook URL, can be obtained by adding Incoming Webhook integration.
URL string `toml:"url" override:"url,redact"`
// The default channel, can be overridden per alert.
Channel string `toml:"channel" override:"channel"`
// The username of the Slack bot.
// Default: kapacitor
Username string `toml:"username" override:"username"`
// IconEmoji uses an emoji instead of the normal icon for the message.
// The contents should be the name of an emoji surrounded with ':', i.e. ':chart_with_upwards_trend:'
IconEmoji string `toml:"icon-emoji" override:"icon-emoji"`
// Whether all alerts should automatically post to slack
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"`
// Path to CA file
SSLCA string `toml:"ssl-ca" override:"ssl-ca"`
// Path to host cert file
SSLCert string `toml:"ssl-cert" override:"ssl-cert"`
// Path to cert key file
SSLKey string `toml:"ssl-key" override:"ssl-key"`
// Use SSL but skip chain & host verification
InsecureSkipVerify bool `toml:"insecure-skip-verify" override:"insecure-skip-verify"`
}
func NewConfig() Config {
return Config{
Username: DefaultUsername,
}
}
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
}