Add check for undefined name in a mute time interval

Signed-off-by: Ben Ridley <benridley29@gmail.com>
This commit is contained in:
Ben Ridley 2020-10-14 21:26:16 +11:00
parent 44e9aa9762
commit ad385c275f

View File

@ -226,6 +226,18 @@ type MuteTimeInterval struct {
TimeIntervals []timeinterval.TimeInterval `yaml:"time_intervals"`
}
// UnmarshalYAML implements the yaml.Unmarshaler interface for MuteTimeInterval
func (mt *MuteTimeInterval) UnmarshalYAML(unmarshal func(interface{}) error) error {
type plain MuteTimeInterval
if err := unmarshal((*plain)(mt)); err != nil {
return err
}
if mt.Name == "" {
return fmt.Errorf("missing name in mute time interval")
}
return nil
}
// Config is the top-level configuration for Alertmanager's config files.
type Config struct {
Global *GlobalConfig `yaml:"global,omitempty" json:"global,omitempty"`