@@ -22,6 +22,8 @@ import (
22
22
"text/template"
23
23
"time"
24
24
25
+ "github.com/prometheus/alertmanager/secrets"
26
+
25
27
commoncfg "github.com/prometheus/common/config"
26
28
"github.com/prometheus/common/model"
27
29
"github.com/prometheus/sigv4"
@@ -328,22 +330,22 @@ type PagerdutyConfig struct {
328
330
329
331
HTTPConfig * commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
330
332
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"`
347
349
}
348
350
349
351
// PagerdutyLink is a link.
@@ -359,20 +361,24 @@ type PagerdutyImage struct {
359
361
Href string `yaml:"href,omitempty" json:"href,omitempty"`
360
362
}
361
363
364
+ func (c * PagerdutyConfig ) isKeyZero () bool {
365
+ return c .ServiceKey .IsZero () && c .RoutingKey .IsZero ()
366
+ }
367
+
362
368
// UnmarshalYAML implements the yaml.Unmarshaler interface.
363
369
func (c * PagerdutyConfig ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
364
370
* c = DefaultPagerdutyConfig
365
371
type plain PagerdutyConfig
366
372
if err := unmarshal ((* plain )(c )); err != nil {
367
373
return err
368
374
}
369
- if c .RoutingKey == "" && c . ServiceKey == "" && c .RoutingKeyFile == "" && c .ServiceKeyFile == "" {
375
+ if c .isKeyZero () && c .RoutingKeyFile == "" && c .ServiceKeyFile == "" {
370
376
return errors .New ("missing service or routing key in PagerDuty config" )
371
377
}
372
- if len ( c .RoutingKey ) > 0 && len (c .RoutingKeyFile ) > 0 {
378
+ if ! c .RoutingKey . IsZero () && len (c .RoutingKeyFile ) > 0 {
373
379
return errors .New ("at most one of routing_key & routing_key_file must be configured" )
374
380
}
375
- if len ( c .ServiceKey ) > 0 && len (c .ServiceKeyFile ) > 0 {
381
+ if ! c .ServiceKey . IsZero () && len (c .ServiceKeyFile ) > 0 {
376
382
return errors .New ("at most one of service_key & service_key_file must be configured" )
377
383
}
378
384
if c .Details == nil {
0 commit comments