Add PagerDuty source field (PD-CEF) (#3106)
* Add new source field to PD config * Update documentation Signed-off-by: Oktarian Tilney-Bassett <oktariantilneybassett@improbable.io>
This commit is contained in:
parent
78b5a27d40
commit
d034f116d5
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -660,6 +660,9 @@ service_key: <tmpl_secret>
|
|||
# Severity of the incident.
|
||||
[ severity: <tmpl_string> | default = 'error' ]
|
||||
|
||||
# Unique location of the affected system.
|
||||
[ source: <tmpl_string> | default = client ]
|
||||
|
||||
# A set of arbitrary key/value pairs that provide further detail
|
||||
# about the incident.
|
||||
[ details: { <string>: <tmpl_string>, ... } | default = {
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue