diff --git a/config/notifiers.go b/config/notifiers.go index 7b6f719720..da561730af 100644 --- a/config/notifiers.go +++ b/config/notifiers.go @@ -217,6 +217,7 @@ type PagerdutyConfig struct { Details map[string]string `yaml:"details,omitempty" json:"details,omitempty"` Images []PagerdutyImage `yaml:"images,omitempty" json:"images,omitempty"` Links []PagerdutyLink `yaml:"links,omitempty" json:"links,omitempty"` + Source string `yaml:"source,omitempty" json:"source,omitempty"` Severity string `yaml:"severity,omitempty" json:"severity,omitempty"` Class string `yaml:"class,omitempty" json:"class,omitempty"` Component string `yaml:"component,omitempty" json:"component,omitempty"` @@ -249,6 +250,9 @@ func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(interface{}) error) error if c.Details == nil { c.Details = make(map[string]string) } + if c.Source == "" { + c.Source = c.Client + } for k, v := range DefaultPagerdutyDetails { if _, ok := c.Details[k]; !ok { c.Details[k] = v diff --git a/config/notifiers_test.go b/config/notifiers_test.go index 889abab627..0d38623163 100644 --- a/config/notifiers_test.go +++ b/config/notifiers_test.go @@ -17,6 +17,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + "gopkg.in/yaml.v2" ) @@ -146,6 +148,40 @@ details: } } +func TestPagerDutySource(t *testing.T) { + for _, tc := range []struct { + title string + in string + + expectedSource string + }{ + { + title: "check source field is backward compatible", + in: ` +routing_key: 'xyz' +client: 'alert-manager-client' +`, + expectedSource: "alert-manager-client", + }, + { + title: "check source field is set", + in: ` +routing_key: 'xyz' +client: 'alert-manager-client' +source: 'alert-manager-source' +`, + expectedSource: "alert-manager-source", + }, + } { + t.Run(tc.title, func(t *testing.T) { + var cfg PagerdutyConfig + err := yaml.UnmarshalStrict([]byte(tc.in), &cfg) + require.NoError(t, err) + require.Equal(t, tc.expectedSource, cfg.Source) + }) + } +} + func TestWebhookURLIsPresent(t *testing.T) { in := `{}` var cfg WebhookConfig diff --git a/docs/configuration.md b/docs/configuration.md index c1871ef2b2..c76f33a1aa 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -660,6 +660,9 @@ service_key: # Severity of the incident. [ severity: | default = 'error' ] +# Unique location of the affected system. +[ source: | default = client ] + # A set of arbitrary key/value pairs that provide further detail # about the incident. [ details: { : , ... } | default = { diff --git a/notify/pagerduty/pagerduty.go b/notify/pagerduty/pagerduty.go index 6c6465f544..32cd6b418f 100644 --- a/notify/pagerduty/pagerduty.go +++ b/notify/pagerduty/pagerduty.go @@ -219,7 +219,7 @@ func (n *Notifier) notifyV2( Links: make([]pagerDutyLink, 0, len(n.conf.Links)), Payload: &pagerDutyPayload{ Summary: summary, - Source: tmpl(n.conf.Client), + Source: tmpl(n.conf.Source), Severity: tmpl(n.conf.Severity), CustomDetails: details, Class: tmpl(n.conf.Class),