@@ -22,6 +22,8 @@ import (
2222 "text/template"
2323 "time"
2424
25+ "github.com/prometheus/alertmanager/secrets"
26+
2527 commoncfg "github.com/prometheus/common/config"
2628 "github.com/prometheus/common/model"
2729 "github.com/prometheus/sigv4"
@@ -328,22 +330,22 @@ type PagerdutyConfig struct {
328330
329331 HTTPConfig * commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
330332
331- ServiceKey Secret `yaml:"service_key,omitempty" json:"service_key,omitempty"`
332- ServiceKeyFile string `yaml:"service_key_file,omitempty" json:"service_key_file,omitempty"`
333- RoutingKey Secret `yaml:"routing_key,omitempty" json:"routing_key,omitempty"`
334- RoutingKeyFile string `yaml:"routing_key_file,omitempty" json:"routing_key_file,omitempty"`
335- URL * URL `yaml:"url,omitempty" json:"url,omitempty"`
336- Client string `yaml:"client,omitempty" json:"client,omitempty"`
337- ClientURL string `yaml:"client_url,omitempty" json:"client_url,omitempty"`
338- Description string `yaml:"description,omitempty" json:"description,omitempty"`
339- Details map [string ]string `yaml:"details,omitempty" json:"details,omitempty"`
340- Images []PagerdutyImage `yaml:"images,omitempty" json:"images,omitempty"`
341- Links []PagerdutyLink `yaml:"links,omitempty" json:"links,omitempty"`
342- Source string `yaml:"source,omitempty" json:"source,omitempty"`
343- Severity string `yaml:"severity,omitempty" json:"severity,omitempty"`
344- Class string `yaml:"class,omitempty" json:"class,omitempty"`
345- Component string `yaml:"component,omitempty" json:"component,omitempty"`
346- Group string `yaml:"group,omitempty" json:"group,omitempty"`
333+ ServiceKey secrets. GenericSecret `yaml:"service_key,omitempty" json:"service_key,omitempty"`
334+ ServiceKeyFile string `yaml:"service_key_file,omitempty" json:"service_key_file,omitempty"`
335+ RoutingKey secrets. GenericSecret `yaml:"routing_key,omitempty" json:"routing_key,omitempty"`
336+ RoutingKeyFile string `yaml:"routing_key_file,omitempty" json:"routing_key_file,omitempty"`
337+ URL * URL `yaml:"url,omitempty" json:"url,omitempty"`
338+ Client string `yaml:"client,omitempty" json:"client,omitempty"`
339+ ClientURL string `yaml:"client_url,omitempty" json:"client_url,omitempty"`
340+ Description string `yaml:"description,omitempty" json:"description,omitempty"`
341+ Details map [string ]string `yaml:"details,omitempty" json:"details,omitempty"`
342+ Images []PagerdutyImage `yaml:"images,omitempty" json:"images,omitempty"`
343+ Links []PagerdutyLink `yaml:"links,omitempty" json:"links,omitempty"`
344+ Source string `yaml:"source,omitempty" json:"source,omitempty"`
345+ Severity string `yaml:"severity,omitempty" json:"severity,omitempty"`
346+ Class string `yaml:"class,omitempty" json:"class,omitempty"`
347+ Component string `yaml:"component,omitempty" json:"component,omitempty"`
348+ Group string `yaml:"group,omitempty" json:"group,omitempty"`
347349}
348350
349351// PagerdutyLink is a link.
@@ -359,20 +361,24 @@ type PagerdutyImage struct {
359361 Href string `yaml:"href,omitempty" json:"href,omitempty"`
360362}
361363
364+ func (c * PagerdutyConfig ) isKeyZero () bool {
365+ return c .ServiceKey .IsZero () && c .RoutingKey .IsZero ()
366+ }
367+
362368// UnmarshalYAML implements the yaml.Unmarshaler interface.
363369func (c * PagerdutyConfig ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
364370 * c = DefaultPagerdutyConfig
365371 type plain PagerdutyConfig
366372 if err := unmarshal ((* plain )(c )); err != nil {
367373 return err
368374 }
369- if c .RoutingKey == "" && c . ServiceKey == "" && c .RoutingKeyFile == "" && c .ServiceKeyFile == "" {
375+ if c .isKeyZero () && c .RoutingKeyFile == "" && c .ServiceKeyFile == "" {
370376 return errors .New ("missing service or routing key in PagerDuty config" )
371377 }
372- if len ( c .RoutingKey ) > 0 && len (c .RoutingKeyFile ) > 0 {
378+ if ! c .RoutingKey . IsZero () && len (c .RoutingKeyFile ) > 0 {
373379 return errors .New ("at most one of routing_key & routing_key_file must be configured" )
374380 }
375- if len ( c .ServiceKey ) > 0 && len (c .ServiceKeyFile ) > 0 {
381+ if ! c .ServiceKey . IsZero () && len (c .ServiceKeyFile ) > 0 {
376382 return errors .New ("at most one of service_key & service_key_file must be configured" )
377383 }
378384 if c .Details == nil {
0 commit comments