From 6ff0cd94c5ebb5603ec43ad4c9a1fd7ee3a51dad Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Mon, 19 Oct 2015 11:44:46 +0200 Subject: [PATCH] Finalize PagerDuty config --- config/config.go | 17 ++++++++++++++--- config/notifies.go | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index e9abc9ca..64bd3216 100644 --- a/config/config.go +++ b/config/config.go @@ -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 { diff --git a/config/notifies.go b/config/notifies.go index 306fa5a0..c12dc445 100644 --- a/config/notifies.go +++ b/config/notifies.go @@ -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