2015-09-25 14:14:30 +00:00
|
|
|
// Copyright 2015 Prometheus Team
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2015-11-20 14:10:38 +00:00
|
|
|
"errors"
|
2015-09-25 14:14:30 +00:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2015-10-09 09:06:04 +00:00
|
|
|
"path/filepath"
|
2015-09-25 14:14:30 +00:00
|
|
|
"regexp"
|
|
|
|
"strings"
|
2015-11-27 14:41:22 +00:00
|
|
|
"time"
|
2015-09-25 14:14:30 +00:00
|
|
|
|
|
|
|
"github.com/prometheus/common/model"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
2016-04-15 03:12:47 +00:00
|
|
|
var patAuthLine = regexp.MustCompile(`((?:api_key|service_key|api_url|token|user_key|password|secret):\s+)(".+"|'.+'|[^\s]+)`)
|
2015-12-03 11:40:50 +00:00
|
|
|
|
|
|
|
// Secret is a string that must not be revealed on marshaling.
|
|
|
|
type Secret string
|
|
|
|
|
|
|
|
// MarshalYAML implements the yaml.Marshaler interface.
|
|
|
|
func (s Secret) MarshalYAML() (interface{}, error) {
|
|
|
|
return "<hidden>", nil
|
|
|
|
}
|
|
|
|
|
2015-09-25 14:14:30 +00:00
|
|
|
// Load parses the YAML input s into a Config.
|
|
|
|
func Load(s string) (*Config, error) {
|
|
|
|
cfg := &Config{}
|
|
|
|
err := yaml.Unmarshal([]byte(s), cfg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-11-20 14:10:38 +00:00
|
|
|
// Check if we have a root route. We cannot check for it in the
|
|
|
|
// UnmarshalYAML method because it won't be called if the input is empty
|
|
|
|
// (e.g. the config file is empty or only contains whitespace).
|
|
|
|
if cfg.Route == nil {
|
|
|
|
return nil, errors.New("no route provided in config")
|
|
|
|
}
|
|
|
|
|
2015-09-25 14:14:30 +00:00
|
|
|
cfg.original = s
|
|
|
|
return cfg, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// LoadFile parses the given YAML file into a Config.
|
|
|
|
func LoadFile(filename string) (*Config, error) {
|
|
|
|
content, err := ioutil.ReadFile(filename)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-10-09 09:06:04 +00:00
|
|
|
cfg, err := Load(string(content))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resolveFilepaths(filepath.Dir(filename), cfg)
|
|
|
|
return cfg, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// resolveFilepaths joins all relative paths in a configuration
|
|
|
|
// with a given base directory.
|
|
|
|
func resolveFilepaths(baseDir string, cfg *Config) {
|
|
|
|
join := func(fp string) string {
|
|
|
|
if len(fp) > 0 && !filepath.IsAbs(fp) {
|
|
|
|
fp = filepath.Join(baseDir, fp)
|
|
|
|
}
|
|
|
|
return fp
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tf := range cfg.Templates {
|
|
|
|
cfg.Templates[i] = join(tf)
|
|
|
|
}
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Config is the top-level configuration for Alertmanager's config files.
|
|
|
|
type Config struct {
|
2015-11-10 13:08:20 +00:00
|
|
|
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"`
|
2015-09-25 14:14:30 +00:00
|
|
|
|
|
|
|
// Catches all undefined fields and must be empty after parsing.
|
|
|
|
XXX map[string]interface{} `yaml:",inline"`
|
|
|
|
|
|
|
|
// original is the input from which the config was parsed.
|
|
|
|
original string
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkOverflow(m map[string]interface{}, ctx string) error {
|
|
|
|
if len(m) > 0 {
|
|
|
|
var keys []string
|
|
|
|
for k := range m {
|
|
|
|
keys = append(keys, k)
|
|
|
|
}
|
|
|
|
return fmt.Errorf("unknown fields in %s: %s", ctx, strings.Join(keys, ", "))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Config) String() string {
|
2015-12-03 11:40:50 +00:00
|
|
|
var s string
|
2015-09-25 14:14:30 +00:00
|
|
|
if c.original != "" {
|
2015-12-03 11:40:50 +00:00
|
|
|
s = c.original
|
|
|
|
} else {
|
|
|
|
b, err := yaml.Marshal(c)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Sprintf("<error creating config string: %s>", err)
|
|
|
|
}
|
|
|
|
s = string(b)
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
2015-12-03 11:40:50 +00:00
|
|
|
return patAuthLine.ReplaceAllString(s, "${1}<hidden>")
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
// We want to set c to the defaults and then overwrite it with the input.
|
|
|
|
// To make unmarshal fill the plain data struct rather than calling UnmarshalYAML
|
|
|
|
// again, we have to hide it using a type indirection.
|
|
|
|
type plain Config
|
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-10-17 08:02:32 +00:00
|
|
|
// If a global block was open but empty the default global config is overwritten.
|
|
|
|
// We have to restore it here.
|
|
|
|
if c.Global == nil {
|
|
|
|
c.Global = &GlobalConfig{}
|
|
|
|
*c.Global = DefaultGlobalConfig
|
|
|
|
}
|
|
|
|
|
2015-09-25 14:14:30 +00:00
|
|
|
names := map[string]struct{}{}
|
|
|
|
|
2015-11-10 13:08:20 +00:00
|
|
|
for _, rcv := range c.Receivers {
|
|
|
|
if _, ok := names[rcv.Name]; ok {
|
|
|
|
return fmt.Errorf("notification config name %q is not unique", rcv.Name)
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
2015-11-10 13:08:20 +00:00
|
|
|
for _, ec := range rcv.EmailConfigs {
|
2015-10-17 08:02:32 +00:00
|
|
|
if ec.Smarthost == "" {
|
2015-10-29 13:34:24 +00:00
|
|
|
if c.Global.SMTPSmarthost == "" {
|
|
|
|
return fmt.Errorf("no global SMTP smarthost set")
|
2015-10-17 08:02:32 +00:00
|
|
|
}
|
2015-10-29 13:34:24 +00:00
|
|
|
ec.Smarthost = c.Global.SMTPSmarthost
|
2015-10-17 08:02:32 +00:00
|
|
|
}
|
2015-10-29 13:34:24 +00:00
|
|
|
if ec.From == "" {
|
|
|
|
if c.Global.SMTPFrom == "" {
|
2015-11-20 14:10:38 +00:00
|
|
|
return fmt.Errorf("no global SMTP from set")
|
2015-10-19 14:52:54 +00:00
|
|
|
}
|
2015-10-29 13:34:24 +00:00
|
|
|
ec.From = c.Global.SMTPFrom
|
2015-10-19 14:52:54 +00:00
|
|
|
}
|
2016-04-15 03:12:47 +00:00
|
|
|
if ec.AuthUsername == "" {
|
|
|
|
ec.AuthUsername = c.Global.SMTPAuthUsername
|
|
|
|
}
|
|
|
|
if ec.AuthPassword == "" {
|
|
|
|
ec.AuthPassword = c.Global.SMTPAuthPassword
|
|
|
|
}
|
|
|
|
if ec.AuthSecret == "" {
|
|
|
|
ec.AuthSecret = c.Global.SMTPAuthSecret
|
|
|
|
}
|
|
|
|
if ec.AuthIdentity == "" {
|
|
|
|
ec.AuthIdentity = c.Global.SMTPAuthIdentity
|
|
|
|
}
|
2015-10-17 08:02:32 +00:00
|
|
|
}
|
2015-11-10 13:08:20 +00:00
|
|
|
for _, sc := range rcv.SlackConfigs {
|
2015-12-03 11:40:50 +00:00
|
|
|
if sc.APIURL == "" {
|
|
|
|
if c.Global.SlackAPIURL == "" {
|
|
|
|
return fmt.Errorf("no global Slack API URL set")
|
2015-10-17 08:02:32 +00:00
|
|
|
}
|
2015-12-03 11:40:50 +00:00
|
|
|
sc.APIURL = c.Global.SlackAPIURL
|
2015-10-17 08:02:32 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-05 19:52:08 +00:00
|
|
|
for _, hc := range rcv.HipchatConfigs {
|
|
|
|
if hc.APIURL == "" {
|
|
|
|
if c.Global.HipchatURL == "" {
|
|
|
|
return fmt.Errorf("no global Hipchat API URL set")
|
|
|
|
}
|
|
|
|
hc.APIURL = c.Global.HipchatURL
|
|
|
|
}
|
|
|
|
if !strings.HasSuffix(hc.APIURL, "/") {
|
|
|
|
hc.APIURL += "/"
|
|
|
|
}
|
|
|
|
if hc.AuthToken == "" {
|
|
|
|
if c.Global.HipchatAuthToken == "" {
|
|
|
|
return fmt.Errorf("no global Hipchat Auth Token set")
|
|
|
|
}
|
|
|
|
hc.AuthToken = c.Global.HipchatAuthToken
|
|
|
|
}
|
|
|
|
}
|
2015-11-10 13:08:20 +00:00
|
|
|
for _, pdc := range rcv.PagerdutyConfigs {
|
2015-10-19 09:44:46 +00:00
|
|
|
if pdc.URL == "" {
|
2015-10-19 09:45:52 +00:00
|
|
|
if c.Global.PagerdutyURL == "" {
|
2015-10-19 09:44:46 +00:00
|
|
|
return fmt.Errorf("no global PagerDuty URL set")
|
|
|
|
}
|
2015-10-19 09:45:52 +00:00
|
|
|
pdc.URL = c.Global.PagerdutyURL
|
2015-10-19 09:44:46 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-24 22:29:25 +00:00
|
|
|
for _, ogc := range rcv.OpsGenieConfigs {
|
|
|
|
if ogc.APIHost == "" {
|
|
|
|
if c.Global.OpsGenieAPIHost == "" {
|
|
|
|
return fmt.Errorf("no global OpsGenie URL set")
|
|
|
|
}
|
|
|
|
ogc.APIHost = c.Global.OpsGenieAPIHost
|
|
|
|
}
|
|
|
|
if !strings.HasSuffix(ogc.APIHost, "/") {
|
|
|
|
ogc.APIHost += "/"
|
|
|
|
}
|
|
|
|
}
|
2016-07-03 15:33:44 +00:00
|
|
|
for _, voc := range rcv.VictorOpsConfigs {
|
|
|
|
if voc.APIURL == "" {
|
|
|
|
if c.Global.VictorOpsAPIURL == "" {
|
|
|
|
return fmt.Errorf("no global VictorOps URL set")
|
|
|
|
}
|
|
|
|
voc.APIURL = c.Global.VictorOpsAPIURL
|
|
|
|
}
|
|
|
|
if !strings.HasSuffix(voc.APIURL, "/") {
|
|
|
|
voc.APIURL += "/"
|
|
|
|
}
|
|
|
|
}
|
2015-11-10 13:08:20 +00:00
|
|
|
names[rcv.Name] = struct{}{}
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
2016-01-26 11:52:43 +00:00
|
|
|
|
|
|
|
// The root route must not have any matchers as it is the fallback node
|
|
|
|
// for all alerts.
|
2016-01-28 12:44:21 +00:00
|
|
|
if c.Route == nil {
|
|
|
|
return fmt.Errorf("No routes provided")
|
|
|
|
}
|
2016-06-04 08:05:54 +00:00
|
|
|
if len(c.Route.Receiver) == 0 {
|
|
|
|
return fmt.Errorf("Root route must specify a default receiver")
|
|
|
|
}
|
2016-01-26 11:52:43 +00:00
|
|
|
if len(c.Route.Match) > 0 || len(c.Route.MatchRE) > 0 {
|
|
|
|
return fmt.Errorf("Root route must not have any matchers")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate that all receivers used in the routing tree are defined.
|
|
|
|
if err := checkReceiver(c.Route, names); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-09-25 14:14:30 +00:00
|
|
|
return checkOverflow(c.XXX, "config")
|
|
|
|
}
|
|
|
|
|
2016-01-26 11:52:43 +00:00
|
|
|
// checkReceiver returns an error if a node in the routing tree
|
|
|
|
// references a receiver not in the given map.
|
|
|
|
func checkReceiver(r *Route, receivers map[string]struct{}) error {
|
2016-06-04 08:05:54 +00:00
|
|
|
if r.Receiver == "" {
|
|
|
|
return nil
|
|
|
|
}
|
2016-01-26 11:52:43 +00:00
|
|
|
if _, ok := receivers[r.Receiver]; !ok {
|
|
|
|
return fmt.Errorf("Undefined receiver %q used in route", r.Receiver)
|
|
|
|
}
|
|
|
|
for _, sr := range r.Routes {
|
|
|
|
if err := checkReceiver(sr, receivers); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-11-12 11:57:20 +00:00
|
|
|
// DefaultGlobalConfig provides global default values.
|
2015-10-19 09:44:46 +00:00
|
|
|
var DefaultGlobalConfig = GlobalConfig{
|
2015-11-27 14:41:22 +00:00
|
|
|
ResolveTimeout: model.Duration(5 * time.Minute),
|
|
|
|
|
2015-11-24 22:29:25 +00:00
|
|
|
PagerdutyURL: "https://events.pagerduty.com/generic/2010-04-15/create_event.json",
|
2016-01-05 19:52:08 +00:00
|
|
|
HipchatURL: "https://api.hipchat.com/",
|
2015-11-24 22:29:25 +00:00
|
|
|
OpsGenieAPIHost: "https://api.opsgenie.com/",
|
2016-07-03 15:33:44 +00:00
|
|
|
VictorOpsAPIURL: "https://alert.victorops.com/integrations/generic/20131114/alert/",
|
2015-10-19 09:44:46 +00:00
|
|
|
}
|
2015-10-17 08:02:32 +00:00
|
|
|
|
2015-11-12 11:57:20 +00:00
|
|
|
// GlobalConfig defines configuration parameters that are valid globally
|
|
|
|
// unless overwritten.
|
2015-10-17 08:02:32 +00:00
|
|
|
type GlobalConfig struct {
|
2015-11-27 14:41:22 +00:00
|
|
|
// ResolveTimeout is the time after which an alert is declared resolved
|
|
|
|
// if it has not been updated.
|
|
|
|
ResolveTimeout model.Duration `yaml:"resolve_timeout"`
|
|
|
|
|
2016-01-05 19:52:08 +00:00
|
|
|
SMTPFrom string `yaml:"smtp_from"`
|
|
|
|
SMTPSmarthost string `yaml:"smtp_smarthost"`
|
2016-04-15 03:12:47 +00:00
|
|
|
SMTPAuthUsername string `yaml:"smtp_auth_username"`
|
|
|
|
SMTPAuthPassword Secret `yaml:"smtp_auth_password"`
|
|
|
|
SMTPAuthSecret Secret `yaml:"smtp_auth_secret"`
|
|
|
|
SMTPAuthIdentity string `yaml:"smtp_auth_identity"`
|
2016-01-05 19:52:08 +00:00
|
|
|
SlackAPIURL Secret `yaml:"slack_api_url"`
|
|
|
|
PagerdutyURL string `yaml:"pagerduty_url"`
|
|
|
|
HipchatURL string `yaml:"hipchat_url"`
|
|
|
|
HipchatAuthToken Secret `yaml:"hipchat_auth_token"`
|
|
|
|
OpsGenieAPIHost string `yaml:"opsgenie_api_host"`
|
2016-07-03 15:33:44 +00:00
|
|
|
VictorOpsAPIURL string `yaml:"victorops_api_url"`
|
2015-10-17 08:02:32 +00:00
|
|
|
}
|
|
|
|
|
2015-11-12 11:57:20 +00:00
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
2015-10-17 08:02:32 +00:00
|
|
|
func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
*c = DefaultGlobalConfig
|
|
|
|
type plain GlobalConfig
|
|
|
|
return unmarshal((*plain)(c))
|
|
|
|
}
|
|
|
|
|
2015-09-25 14:14:30 +00:00
|
|
|
// A Route is a node that contains definitions of how to handle alerts.
|
|
|
|
type Route struct {
|
2015-11-10 12:47:04 +00:00
|
|
|
Receiver string `yaml:"receiver,omitempty"`
|
|
|
|
GroupBy []model.LabelName `yaml:"group_by,omitempty"`
|
2015-09-25 14:14:30 +00:00
|
|
|
|
|
|
|
Match map[string]string `yaml:"match,omitempty"`
|
|
|
|
MatchRE map[string]Regexp `yaml:"match_re,omitempty"`
|
|
|
|
Continue bool `yaml:"continue,omitempty"`
|
|
|
|
Routes []*Route `yaml:"routes,omitempty"`
|
|
|
|
|
2015-10-08 08:50:37 +00:00
|
|
|
GroupWait *model.Duration `yaml:"group_wait,omitempty"`
|
|
|
|
GroupInterval *model.Duration `yaml:"group_interval,omitempty"`
|
2015-12-03 11:40:50 +00:00
|
|
|
RepeatInterval *model.Duration `yaml:"repeat_interval,omitempty"`
|
2015-10-08 08:50:37 +00:00
|
|
|
|
2015-09-25 14:14:30 +00:00
|
|
|
// Catches all undefined fields and must be empty after parsing.
|
|
|
|
XXX map[string]interface{} `yaml:",inline"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (r *Route) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
type plain Route
|
|
|
|
if err := unmarshal((*plain)(r)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for k := range r.Match {
|
|
|
|
if !model.LabelNameRE.MatchString(k) {
|
|
|
|
return fmt.Errorf("invalid label name %q", k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for k := range r.MatchRE {
|
|
|
|
if !model.LabelNameRE.MatchString(k) {
|
|
|
|
return fmt.Errorf("invalid label name %q", k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
groupBy := map[model.LabelName]struct{}{}
|
|
|
|
|
|
|
|
for _, ln := range r.GroupBy {
|
|
|
|
if _, ok := groupBy[ln]; ok {
|
|
|
|
return fmt.Errorf("duplicated label %q in group_by", ln)
|
|
|
|
}
|
|
|
|
groupBy[ln] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return checkOverflow(r.XXX, "route")
|
|
|
|
}
|
|
|
|
|
2015-11-12 11:57:20 +00:00
|
|
|
// InhibitRule defines an inhibition rule that mutes alerts that match the
|
|
|
|
// target labels if an alert matching the source labels exists.
|
|
|
|
// Both alerts have to have a set of labels being equal.
|
2015-09-25 14:14:30 +00:00
|
|
|
type InhibitRule struct {
|
2015-11-12 11:57:20 +00:00
|
|
|
// SourceMatch defines a set of labels that have to equal the given
|
|
|
|
// value for source alerts.
|
|
|
|
SourceMatch map[string]string `yaml:"source_match"`
|
|
|
|
// SourceMatchRE defines pairs like SourceMatch but does regular expression
|
|
|
|
// matching.
|
2015-09-25 14:14:30 +00:00
|
|
|
SourceMatchRE map[string]Regexp `yaml:"source_match_re"`
|
2015-11-12 11:57:20 +00:00
|
|
|
// TargetMatch defines a set of labels that have to equal the given
|
|
|
|
// value for target alerts.
|
|
|
|
TargetMatch map[string]string `yaml:"target_match"`
|
|
|
|
// TargetMatchRE defines pairs like TargetMatch but does regular expression
|
|
|
|
// matching.
|
2015-09-25 14:14:30 +00:00
|
|
|
TargetMatchRE map[string]Regexp `yaml:"target_match_re"`
|
2015-11-12 11:57:20 +00:00
|
|
|
// A set of labels that must be equal between the source and target alert
|
|
|
|
// for them to be a match.
|
|
|
|
Equal model.LabelNames `yaml:"equal"`
|
2015-09-25 14:14:30 +00:00
|
|
|
|
|
|
|
// Catches all undefined fields and must be empty after parsing.
|
|
|
|
XXX map[string]interface{} `yaml:",inline"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (r *InhibitRule) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
type plain InhibitRule
|
|
|
|
if err := unmarshal((*plain)(r)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for k := range r.SourceMatch {
|
|
|
|
if !model.LabelNameRE.MatchString(k) {
|
|
|
|
return fmt.Errorf("invalid label name %q", k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for k := range r.SourceMatchRE {
|
|
|
|
if !model.LabelNameRE.MatchString(k) {
|
|
|
|
return fmt.Errorf("invalid label name %q", k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for k := range r.TargetMatch {
|
|
|
|
if !model.LabelNameRE.MatchString(k) {
|
|
|
|
return fmt.Errorf("invalid label name %q", k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for k := range r.TargetMatchRE {
|
|
|
|
if !model.LabelNameRE.MatchString(k) {
|
|
|
|
return fmt.Errorf("invalid label name %q", k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return checkOverflow(r.XXX, "inhibit rule")
|
|
|
|
}
|
|
|
|
|
2015-11-12 11:57:20 +00:00
|
|
|
// Receiver configuration provides configuration on how to contact a receiver.
|
2015-11-10 13:08:20 +00:00
|
|
|
type Receiver struct {
|
2015-11-12 11:57:20 +00:00
|
|
|
// A unique identifier for this receiver.
|
2015-09-25 14:14:30 +00:00
|
|
|
Name string `yaml:"name"`
|
|
|
|
|
2015-12-03 11:40:50 +00:00
|
|
|
EmailConfigs []*EmailConfig `yaml:"email_configs,omitempty"`
|
|
|
|
PagerdutyConfigs []*PagerdutyConfig `yaml:"pagerduty_configs,omitempty"`
|
2016-01-05 19:52:08 +00:00
|
|
|
HipchatConfigs []*HipchatConfig `yaml:"hipchat_configs,omitempty"`
|
2015-12-03 11:40:50 +00:00
|
|
|
SlackConfigs []*SlackConfig `yaml:"slack_configs,omitempty"`
|
|
|
|
WebhookConfigs []*WebhookConfig `yaml:"webhook_configs,omitempty"`
|
|
|
|
OpsGenieConfigs []*OpsGenieConfig `yaml:"opsgenie_configs,omitempty"`
|
2016-02-26 08:35:00 +00:00
|
|
|
PushoverConfigs []*PushoverConfig `yaml:"pushover_configs,omitempty"`
|
2016-07-03 15:33:44 +00:00
|
|
|
VictorOpsConfigs []*VictorOpsConfig `yaml:"victorops_configs,omitempty"`
|
2015-09-25 14:14:30 +00:00
|
|
|
|
|
|
|
// Catches all undefined fields and must be empty after parsing.
|
|
|
|
XXX map[string]interface{} `yaml:",inline"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
2015-11-10 13:08:20 +00:00
|
|
|
func (c *Receiver) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
type plain Receiver
|
2015-09-25 14:14:30 +00:00
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if c.Name == "" {
|
2015-11-10 13:08:20 +00:00
|
|
|
return fmt.Errorf("missing name in receiver")
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
2015-11-10 13:08:20 +00:00
|
|
|
return checkOverflow(c.XXX, "receiver config")
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
|
|
|
|
2015-11-26 17:19:46 +00:00
|
|
|
// Regexp encapsulates a regexp.Regexp and makes it YAML marshalable.
|
2015-09-25 14:14:30 +00:00
|
|
|
type Regexp struct {
|
2015-11-05 09:25:25 +00:00
|
|
|
*regexp.Regexp
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (re *Regexp) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
var s string
|
|
|
|
if err := unmarshal(&s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-11-19 07:51:52 +00:00
|
|
|
regex, err := regexp.Compile("^(?:" + s + ")$")
|
2015-09-25 14:14:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-11-05 09:25:25 +00:00
|
|
|
re.Regexp = regex
|
2015-09-25 14:14:30 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalYAML implements the yaml.Marshaler interface.
|
|
|
|
func (re *Regexp) MarshalYAML() (interface{}, error) {
|
|
|
|
if re != nil {
|
|
|
|
return re.String(), nil
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|