Alerting: New API endpoint GET /api/v1/ngalert (#55134)

* declare new endpoint /api/v1/ngalert
* add authorization for new path
* add request handler for the new path
This commit is contained in:
Yuriy Tseretyan
2022-09-14 14:03:10 -04:00
committed by GitHub
parent ca2139e9ce
commit 8a62020211
9 changed files with 142 additions and 1 deletions

View File

@@ -143,3 +143,22 @@ func (srv ConfigSrv) externalAlertmanagers(ctx context.Context, orgID int64) ([]
}
return alertmanagers, nil
}
func (srv ConfigSrv) RouteGetAlertingStatus(c *models.ReqContext) response.Response {
sendsAlertsTo := ngmodels.InternalAlertmanager
cfg, err := srv.store.GetAdminConfiguration(c.OrgID)
if err != nil && !errors.Is(err, store.ErrNoAdminConfiguration) {
msg := "failed to fetch configuration from the database"
srv.log.Error(msg, "err", err)
return ErrResp(http.StatusInternalServerError, err, msg)
}
if cfg != nil {
sendsAlertsTo = cfg.SendAlertsTo
}
resp := apimodels.AlertingStatus{
AlertmanagersChoice: apimodels.AlertmanagersChoice(sendsAlertsTo.String()),
}
return response.JSON(http.StatusOK, resp)
}