Alerting: Add provisioning endpoint to fetch all rules (#59989)

* Domain layer api for fetching all rules

* Add endpoint for getting all rules
This commit is contained in:
Alexander Weaver
2022-12-13 11:54:08 +01:00
committed by GitHub
parent d6bd3c4fb6
commit e97b43cd58
10 changed files with 163 additions and 18 deletions
@@ -53,6 +53,7 @@ type MuteTimingService interface {
}
type AlertRuleService interface {
GetAlertRules(ctx context.Context, orgID int64) ([]*alerting_models.AlertRule, error)
GetAlertRule(ctx context.Context, orgID int64, ruleUID string) (alerting_models.AlertRule, alerting_models.Provenance, error)
CreateAlertRule(ctx context.Context, rule alerting_models.AlertRule, provenance alerting_models.Provenance, userID int64) (alerting_models.AlertRule, error)
UpdateAlertRule(ctx context.Context, rule alerting_models.AlertRule, provenance alerting_models.Provenance) (alerting_models.AlertRule, error)
@@ -247,6 +248,14 @@ func (srv *ProvisioningSrv) RouteDeleteMuteTiming(c *models.ReqContext, name str
return response.JSON(http.StatusNoContent, nil)
}
func (srv *ProvisioningSrv) RouteGetAlertRules(c *models.ReqContext) response.Response {
rules, err := srv.alertRules.GetAlertRules(c.Req.Context(), c.OrgID)
if err != nil {
return ErrResp(http.StatusInternalServerError, err, "")
}
return response.JSON(http.StatusOK, definitions.NewAlertRules(rules))
}
func (srv *ProvisioningSrv) RouteRouteGetAlertRule(c *models.ReqContext, UID string) response.Response {
rule, provenace, err := srv.alertRules.GetAlertRule(c.Req.Context(), c.OrgID, UID)
if err != nil {