Finalize PagerDuty config

This commit is contained in:
Fabian Reinartz 2015-10-19 11:44:46 +02:00
parent 22e1e9ca72
commit 6ff0cd94c5
2 changed files with 28 additions and 5 deletions

View File

@ -141,16 +141,27 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
sc.URL = c.Global.SlackURL
}
}
for _, pdc := range nc.PagerdutyConfigs {
if pdc.URL == "" {
if c.Global.PagerDutyURL == "" {
return fmt.Errorf("no global PagerDuty URL set")
}
pdc.URL = c.Global.PagerDutyURL
}
}
names[nc.Name] = struct{}{}
}
return checkOverflow(c.XXX, "config")
}
var DefaultGlobalConfig = GlobalConfig{}
var DefaultGlobalConfig = GlobalConfig{
PagerdutyURL: "https://events.pagerduty.com/generic/2010-04-15/create_event.json",
}
type GlobalConfig struct {
Smarthost string `yaml:"smarthost"`
SlackURL string `yaml:"slack_url"`
Smarthost string `yaml:"smarthost"`
SlackURL string `yaml:"slack_url"`
PagerDutyURL string `yaml:"pagerduty_url"`
}
func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {

View File

@ -43,20 +43,32 @@ var (
HTML: "email.default.html",
},
}
DefaultPagerDutyConfig = PagerDutyConfig{
Templates: PagerDutyTemplates{
Description: "pagerduty.default.description",
},
}
)
// Configuration for notification via PagerDuty.
type PagerdutyConfig struct {
// PagerDuty service key, see:
// http://developer.pagerduty.com/documentation/integration/events
ServiceKey string `yaml:"service_key"`
URL string `yaml:"url"`
Templates PagerDutyTemplates `yaml:"templates"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
}
type PagerDutyTemplates struct {
Description string
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultPagerDutyConfig
type plain PagerdutyConfig
if err := unmarshal((*plain)(c)); err != nil {
return err