Alerting: validate that the receiver exist when updating routing tree (#51561) (#51758)

* 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

(cherry picked from commit e64cde8727)

Co-authored-by: Jean-Philippe Quéméner <JohnnyQQQQ@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2022-07-05 12:47:11 -04:00
committed by GitHub
co-authored by Jean-Philippe Quéméner
parent 2f76963700
commit 7f5dec12bd
4 changed files with 103 additions and 3 deletions
@@ -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 {