Alerting: send alerts to external, internal, or both alertmanagers (#40341)

* (WIP) send alerts to external, internal, or both alertmanagers

* Modify admin configuration endpoint, update swagger docs

* Integration test for admin config updated

* Code review changes

* Fix alertmanagers choice not changing bug, add unit test

* Add AlertmanagersChoice as enum in swagger, code review changes

* Fix API and tests errors

* Change enum from int to string, use 'SendAlertsTo' instead of 'AlertmanagerChoice' where necessary

* Fix tests to reflect last changes

* Keep senders running when alerts are handled just internally

* Check if any external AM has been discovered before sending alerts, update tests

* remove duplicate data from logs

* update comment

* represent alertmanagers choice as an int instead of a string

* default alertmanagers choice to all alertmanagers, test cases

* update definitions and generate spec
This commit is contained in:
Santiago
2022-02-01 20:36:55 -03:00
committed by GitHub
parent 21796c61ba
commit 04d93751b8
10 changed files with 388 additions and 84 deletions
+12 -1
View File
@@ -55,7 +55,8 @@ func (srv AdminSrv) RouteGetNGalertConfig(c *models.ReqContext) response.Respons
}
resp := apimodels.GettableNGalertConfig{
Alertmanagers: cfg.Alertmanagers,
Alertmanagers: cfg.Alertmanagers,
AlertmanagersChoice: apimodels.AlertmanagersChoice(cfg.SendAlertsTo.String()),
}
return response.JSON(http.StatusOK, resp)
}
@@ -65,8 +66,18 @@ func (srv AdminSrv) RoutePostNGalertConfig(c *models.ReqContext, body apimodels.
return accessForbiddenResp()
}
sendAlertsTo, err := ngmodels.StringToAlertmanagersChoice(string(body.AlertmanagersChoice))
if err != nil {
return response.Error(400, "Invalid alertmanager choice specified", nil)
}
if sendAlertsTo == ngmodels.ExternalAlertmanagers && len(body.Alertmanagers) == 0 {
return response.Error(400, "At least one Alertmanager must be provided to choose this option", nil)
}
cfg := &ngmodels.AdminConfiguration{
Alertmanagers: body.Alertmanagers,
SendAlertsTo: sendAlertsTo,
OrgID: c.OrgId,
}