Alerting: validate that the receiver exist when updating routing tree (#51561)
* Alerting: validate that the receiver exist when updating routing tree * rename interface * add missing file * change constructor * fix e2e tests * only import package once * add unit test for bug * wording * close response body * Update pkg/services/ngalert/api/tooling/definitions/alertmanager_validation.go * refactor to remove database roundtrip
This commit is contained in:
@@ -101,6 +101,19 @@ func (r *Route) Validate() error {
|
||||
return r.validateChild()
|
||||
}
|
||||
|
||||
func (r *Route) ValidateReceivers(receivers map[string]struct{}) error {
|
||||
if _, exists := receivers[r.Receiver]; !exists {
|
||||
return fmt.Errorf("receiver '%s' does not exist", r.Receiver)
|
||||
}
|
||||
for _, children := range r.Routes {
|
||||
err := children.ValidateReceivers(receivers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mt *MuteTimeInterval) Validate() error {
|
||||
s, err := yaml.Marshal(mt.MuteTimeInterval)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user