forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
36 lines (30 loc) · 887 Bytes
/
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
package pagerduty
import (
"net/url"
"github.com/pkg/errors"
)
const DefaultPagerDutyAPIURL = "https://events.pagerduty.com/generic/2010-04-15/create_event.json"
type Config struct {
// Whether PagerDuty integration is enabled.
Enabled bool `toml:"enabled" override:"enabled"`
// The PagerDuty API URL, should not need to be changed.
URL string `toml:"url" override:"url"`
// The PagerDuty service key.
ServiceKey string `toml:"service-key" override:"service-key,redact"`
// Whether every alert should automatically go to PagerDuty
Global bool `toml:"global" override:"global"`
}
func NewConfig() Config {
return Config{
URL: DefaultPagerDutyAPIURL,
}
}
func (c Config) Validate() error {
if c.URL == "" {
return errors.New("url cannot be empty")
}
if _, err := url.Parse(c.URL); err != nil {
return errors.Wrapf(err, "invalid URL %q", c.URL)
}
return nil
}