Adjust config fields to 'receiver'

This commit is contained in:
Fabian Reinartz 2015-11-10 14:08:20 +01:00
parent 6a99dfaa90
commit dc656a44ea
8 changed files with 54 additions and 54 deletions

View File

@ -100,7 +100,7 @@ route:
# catch alerts that are related to a list of services.
- match_re:
service: ^(foo1|foo2|baz)$
send_to: team-X-mails
receiver: team-X-mails
# The service has a sub-route for critical alerts, any alerts
# that do not match, i.e. severity != critical, fall-back to the
@ -108,23 +108,23 @@ route:
routes:
- match:
severity: critical
send_to: team-X-pager
receiver: team-X-pager
- match:
service: files
send_to: team-Y-mails
receiver: team-Y-mails
routes:
- match:
severity: critical
send_to: team-Y-pager
receiver: team-Y-pager
# This route handles all alerts coming from a database service. If there's
# no team to handle it, it defaults to the DB team.
- match:
service: database
send_to: team-DB-pager
receiver: team-DB-pager
# Also group alerts by affected database.
group_by: [alertname, cluster, database]
continue: false
@ -132,12 +132,12 @@ route:
routes:
- match:
owner: team-X
send_to: team-X-pager
receiver: team-X-pager
- match:
owner: team-Y
send_to: team-Y-pager
receiver: team-Y-pager
# Inhibition rules allow to mute a set of alerts given that another alert is
# firing.
@ -152,7 +152,7 @@ inhibit_rules:
equal: ['alertname']
notification_configs:
receivers:
- name: 'team-X-mails'
email_configs:
- email: 'team-X+alerts@example.org'

View File

@ -68,11 +68,11 @@ func resolveFilepaths(baseDir string, cfg *Config) {
// Config is the top-level configuration for Alertmanager's config files.
type Config struct {
Global *GlobalConfig `yaml:"global,omitempty"`
Route *Route `yaml:"route,omitempty"`
InhibitRules []*InhibitRule `yaml:"inhibit_rules,omitempty"`
NotificationConfigs []*NotificationConfig `yaml:"notification_configs,omitempty"`
Templates []string `yaml:"templates"`
Global *GlobalConfig `yaml:"global,omitempty"`
Route *Route `yaml:"route,omitempty"`
InhibitRules []*InhibitRule `yaml:"inhibit_rules,omitempty"`
Receivers []*Receiver `yaml:"receivers,omitempty"`
Templates []string `yaml:"templates"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
@ -122,11 +122,11 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
names := map[string]struct{}{}
for _, nc := range c.NotificationConfigs {
if _, ok := names[nc.Name]; ok {
return fmt.Errorf("notification config name %q is not unique", nc.Name)
for _, rcv := range c.Receivers {
if _, ok := names[rcv.Name]; ok {
return fmt.Errorf("notification config name %q is not unique", rcv.Name)
}
for _, ec := range nc.EmailConfigs {
for _, ec := range rcv.EmailConfigs {
if ec.Smarthost == "" {
if c.Global.Smarthost == "" {
return fmt.Errorf("no global mail smarthost set")
@ -140,7 +140,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
ec.Sender = c.Global.SMTPSender
}
}
for _, sc := range nc.SlackConfigs {
for _, sc := range rcv.SlackConfigs {
if sc.URL == "" {
if c.Global.SlackURL == "" {
return fmt.Errorf("no global Slack URL set")
@ -148,7 +148,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
sc.URL = c.Global.SlackURL
}
}
for _, pdc := range nc.PagerdutyConfigs {
for _, pdc := range rcv.PagerdutyConfigs {
if pdc.URL == "" {
if c.Global.PagerdutyURL == "" {
return fmt.Errorf("no global PagerDuty URL set")
@ -156,7 +156,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
pdc.URL = c.Global.PagerdutyURL
}
}
names[nc.Name] = struct{}{}
names[rcv.Name] = struct{}{}
}
return checkOverflow(c.XXX, "config")
}
@ -283,9 +283,9 @@ func (r *InhibitRule) UnmarshalYAML(unmarshal func(interface{}) error) error {
return checkOverflow(r.XXX, "inhibit rule")
}
// Notification configuration definition.
type NotificationConfig struct {
// Name of this NotificationConfig. Referenced from AggregationRule.
// Receiver configuration provides configuration on how to contact
// a receiver.
type Receiver struct {
Name string `yaml:"name"`
PagerdutyConfigs []*PagerdutyConfig `yaml:"pagerduty_configs"`
@ -301,15 +301,15 @@ type NotificationConfig struct {
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *NotificationConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
type plain NotificationConfig
func (c *Receiver) UnmarshalYAML(unmarshal func(interface{}) error) error {
type plain Receiver
if err := unmarshal((*plain)(c)); err != nil {
return err
}
if c.Name == "" {
return fmt.Errorf("missing name in notification config")
return fmt.Errorf("missing name in receiver")
}
return checkOverflow(c.XXX, "notification config")
return checkOverflow(c.XXX, "receiver config")
}
// Regexp encapsulates a regexp.Regexp and makes it YAML marshallable.

View File

@ -73,10 +73,10 @@ func main() {
return disp.Groups()
})
build := func(nconf []*config.NotificationConfig) notify.Notifier {
build := func(rcvs []*config.Receiver) notify.Notifier {
var (
router = notify.Router{}
fanouts = notify.Build(nconf, tmpl)
fanouts = notify.Build(rcvs, tmpl)
)
for name, fo := range fanouts {
for i, n := range fo {
@ -123,7 +123,7 @@ func main() {
disp.Stop()
inhibitor = NewInhibitor(alerts, conf.InhibitRules, marker)
disp = NewDispatcher(alerts, NewRoute(conf.Route, nil), build(conf.NotificationConfigs), marker)
disp = NewDispatcher(alerts, NewRoute(conf.Route, nil), build(conf.Receivers), marker)
go disp.Run()

View File

@ -35,8 +35,8 @@ import (
"github.com/prometheus/alertmanager/types"
)
// Build creates a fanout notifier for each notification configuration.
func Build(confs []*config.NotificationConfig, tmpl *template.Template) map[string]Fanout {
// Build creates a fanout notifier for each receiver.
func Build(confs []*config.Receiver, tmpl *template.Template) map[string]Fanout {
res := map[string]Fanout{}
for _, nc := range confs {

View File

@ -26,25 +26,25 @@ import (
func TestRouteMatch(t *testing.T) {
in := `
send_to: 'notify-def'
receiver: 'notify-def'
routes:
- match:
owner: 'team-A'
send_to: 'notify-A'
receiver: 'notify-A'
routes:
- match:
env: 'testing'
send_to: 'notify-testing'
receiver: 'notify-testing'
group_by: []
- match:
env: "production"
send_to: 'notify-productionA'
receiver: 'notify-productionA'
group_wait: 1m
continue: true
@ -52,7 +52,7 @@ routes:
- match_re:
env: "^produ.*$"
send_to: 'notify-productionB'
receiver: 'notify-productionB'
group_wait: 30s
group_interval: 5m
repeat_interval: 1h
@ -65,7 +65,7 @@ routes:
group_by: ['foo', 'bar']
group_wait: 2m
send_resolved: false
send_to: 'notify-BC'
receiver: 'notify-BC'
`
var ctree config.Route

View File

@ -26,13 +26,13 @@ func TestInhibiting(t *testing.T) {
conf := `
route:
send_to: "default"
receiver: "default"
group_by: []
group_wait: 1s
group_interval: 1s
repeat_interval: 1s
notification_configs:
receivers:
- name: "default"
webhook_configs:
- url: 'http://%s'

View File

@ -31,13 +31,13 @@ func TestMergeAlerts(t *testing.T) {
conf := `
route:
send_to: "default"
receiver: "default"
group_by: []
group_wait: 1s
group_interval: 1s
repeat_interval: 1s
notification_configs:
receivers:
- name: "default"
webhook_configs:
- url: 'http://%s'
@ -103,13 +103,13 @@ func TestRepeat(t *testing.T) {
conf := `
route:
send_to: "default"
receiver: "default"
group_by: []
group_wait: 1s
group_interval: 1s
repeat_interval: 1s
notification_configs:
receivers:
- name: "default"
webhook_configs:
- url: 'http://%s'
@ -161,13 +161,13 @@ func TestRetry(t *testing.T) {
// notifications. Sending to the succeeding one must eventually succeed.
conf := `
route:
send_to: "default"
receiver: "default"
group_by: []
group_wait: 1s
group_interval: 1s
repeat_interval: 3s
notification_configs:
receivers:
- name: "default"
webhook_configs:
- url: 'http://%s'
@ -205,14 +205,14 @@ func TestBatching(t *testing.T) {
conf := `
route:
send_to: "default"
receiver: "default"
group_by: []
group_wait: 1s
group_interval: 1s
repeat_interval: 5s
notification_configs:
- name: "default"
receivers:
- name: "default"
webhook_configs:
- url: 'http://%s'
`

View File

@ -26,13 +26,13 @@ func TestSilencing(t *testing.T) {
conf := `
route:
send_to: "default"
receiver: "default"
group_by: []
group_wait: 1s
group_interval: 1s
repeat_interval: 1s
notification_configs:
receivers:
- name: "default"
webhook_configs:
- url: 'http://%s'
@ -78,13 +78,13 @@ func TestSilenceDelete(t *testing.T) {
conf := `
route:
send_to: "default"
receiver: "default"
group_by: []
group_wait: 1s
group_interval: 1s
repeat_interval: 1s
notification_configs:
receivers:
- name: "default"
webhook_configs:
- url: 'http://%s'