2021-04-09 04:55:41 -05:00
|
|
|
/*Package api contains base API implementation of unified alerting
|
|
|
|
*
|
|
|
|
*Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
|
|
|
*
|
|
|
|
*Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them.
|
|
|
|
*/
|
2021-12-13 02:22:57 -06:00
|
|
|
|
2021-04-09 04:55:41 -05:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2021-04-28 15:59:15 -05:00
|
|
|
"net/http"
|
|
|
|
|
2021-04-09 04:55:41 -05:00
|
|
|
"github.com/grafana/grafana/pkg/api/response"
|
|
|
|
"github.com/grafana/grafana/pkg/api/routing"
|
2022-03-24 16:13:47 -05:00
|
|
|
"github.com/grafana/grafana/pkg/middleware"
|
2021-04-09 04:55:41 -05:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2021-04-19 13:26:04 -05:00
|
|
|
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
2021-04-30 11:28:06 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
2021-12-13 02:22:57 -06:00
|
|
|
"github.com/grafana/grafana/pkg/web"
|
2021-04-09 04:55:41 -05:00
|
|
|
)
|
|
|
|
|
2021-12-13 02:22:57 -06:00
|
|
|
type RulerApiForkingService interface {
|
2022-02-04 11:42:04 -06:00
|
|
|
RouteDeleteGrafanaRuleGroupConfig(*models.ReqContext) response.Response
|
|
|
|
RouteDeleteNamespaceGrafanaRulesConfig(*models.ReqContext) response.Response
|
2021-12-13 02:22:57 -06:00
|
|
|
RouteDeleteNamespaceRulesConfig(*models.ReqContext) response.Response
|
|
|
|
RouteDeleteRuleGroupConfig(*models.ReqContext) response.Response
|
2022-02-04 11:42:04 -06:00
|
|
|
RouteGetGrafanaRuleGroupConfig(*models.ReqContext) response.Response
|
|
|
|
RouteGetGrafanaRulesConfig(*models.ReqContext) response.Response
|
|
|
|
RouteGetNamespaceGrafanaRulesConfig(*models.ReqContext) response.Response
|
2021-12-13 02:22:57 -06:00
|
|
|
RouteGetNamespaceRulesConfig(*models.ReqContext) response.Response
|
|
|
|
RouteGetRulegGroupConfig(*models.ReqContext) response.Response
|
|
|
|
RouteGetRulesConfig(*models.ReqContext) response.Response
|
2022-02-04 11:42:04 -06:00
|
|
|
RoutePostNameGrafanaRulesConfig(*models.ReqContext) response.Response
|
2021-12-13 02:22:57 -06:00
|
|
|
RoutePostNameRulesConfig(*models.ReqContext) response.Response
|
|
|
|
}
|
|
|
|
|
2022-02-04 11:42:04 -06:00
|
|
|
func (f *ForkedRulerApi) RouteDeleteGrafanaRuleGroupConfig(ctx *models.ReqContext) response.Response {
|
|
|
|
return f.forkRouteDeleteGrafanaRuleGroupConfig(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *ForkedRulerApi) RouteDeleteNamespaceGrafanaRulesConfig(ctx *models.ReqContext) response.Response {
|
|
|
|
return f.forkRouteDeleteNamespaceGrafanaRulesConfig(ctx)
|
2021-04-09 04:55:41 -05:00
|
|
|
}
|
|
|
|
|
2021-12-13 02:22:57 -06:00
|
|
|
func (f *ForkedRulerApi) RouteDeleteNamespaceRulesConfig(ctx *models.ReqContext) response.Response {
|
|
|
|
return f.forkRouteDeleteNamespaceRulesConfig(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *ForkedRulerApi) RouteDeleteRuleGroupConfig(ctx *models.ReqContext) response.Response {
|
|
|
|
return f.forkRouteDeleteRuleGroupConfig(ctx)
|
|
|
|
}
|
|
|
|
|
2022-02-04 11:42:04 -06:00
|
|
|
func (f *ForkedRulerApi) RouteGetGrafanaRuleGroupConfig(ctx *models.ReqContext) response.Response {
|
|
|
|
return f.forkRouteGetGrafanaRuleGroupConfig(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *ForkedRulerApi) RouteGetGrafanaRulesConfig(ctx *models.ReqContext) response.Response {
|
|
|
|
return f.forkRouteGetGrafanaRulesConfig(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *ForkedRulerApi) RouteGetNamespaceGrafanaRulesConfig(ctx *models.ReqContext) response.Response {
|
|
|
|
return f.forkRouteGetNamespaceGrafanaRulesConfig(ctx)
|
|
|
|
}
|
|
|
|
|
2021-12-13 02:22:57 -06:00
|
|
|
func (f *ForkedRulerApi) RouteGetNamespaceRulesConfig(ctx *models.ReqContext) response.Response {
|
|
|
|
return f.forkRouteGetNamespaceRulesConfig(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *ForkedRulerApi) RouteGetRulegGroupConfig(ctx *models.ReqContext) response.Response {
|
|
|
|
return f.forkRouteGetRulegGroupConfig(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *ForkedRulerApi) RouteGetRulesConfig(ctx *models.ReqContext) response.Response {
|
|
|
|
return f.forkRouteGetRulesConfig(ctx)
|
|
|
|
}
|
|
|
|
|
2022-02-04 11:42:04 -06:00
|
|
|
func (f *ForkedRulerApi) RoutePostNameGrafanaRulesConfig(ctx *models.ReqContext) response.Response {
|
|
|
|
conf := apimodels.PostableRuleGroupConfig{}
|
|
|
|
if err := web.Bind(ctx.Req, &conf); err != nil {
|
|
|
|
return response.Error(http.StatusBadRequest, "bad request data", err)
|
|
|
|
}
|
|
|
|
return f.forkRoutePostNameGrafanaRulesConfig(ctx, conf)
|
|
|
|
}
|
|
|
|
|
2021-12-13 02:22:57 -06:00
|
|
|
func (f *ForkedRulerApi) RoutePostNameRulesConfig(ctx *models.ReqContext) response.Response {
|
|
|
|
conf := apimodels.PostableRuleGroupConfig{}
|
|
|
|
if err := web.Bind(ctx.Req, &conf); err != nil {
|
|
|
|
return response.Error(http.StatusBadRequest, "bad request data", err)
|
|
|
|
}
|
|
|
|
return f.forkRoutePostNameRulesConfig(ctx, conf)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *API) RegisterRulerApiEndpoints(srv RulerApiForkingService, m *metrics.API) {
|
2021-04-09 04:55:41 -05:00
|
|
|
api.RouteRegister.Group("", func(group routing.RouteRegister) {
|
2022-02-04 11:42:04 -06:00
|
|
|
group.Delete(
|
|
|
|
toMacaronPath("/api/ruler/grafana/api/v1/rules/{Namespace}/{Groupname}"),
|
|
|
|
api.authorize(http.MethodDelete, "/api/ruler/grafana/api/v1/rules/{Namespace}/{Groupname}"),
|
|
|
|
metrics.Instrument(
|
|
|
|
http.MethodDelete,
|
|
|
|
"/api/ruler/grafana/api/v1/rules/{Namespace}/{Groupname}",
|
|
|
|
srv.RouteDeleteGrafanaRuleGroupConfig,
|
|
|
|
m,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
group.Delete(
|
|
|
|
toMacaronPath("/api/ruler/grafana/api/v1/rules/{Namespace}"),
|
|
|
|
api.authorize(http.MethodDelete, "/api/ruler/grafana/api/v1/rules/{Namespace}"),
|
|
|
|
metrics.Instrument(
|
|
|
|
http.MethodDelete,
|
|
|
|
"/api/ruler/grafana/api/v1/rules/{Namespace}",
|
|
|
|
srv.RouteDeleteNamespaceGrafanaRulesConfig,
|
|
|
|
m,
|
|
|
|
),
|
|
|
|
)
|
2021-04-28 15:59:15 -05:00
|
|
|
group.Delete(
|
2022-05-05 06:58:32 -05:00
|
|
|
toMacaronPath("/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}"),
|
|
|
|
api.authorize(http.MethodDelete, "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}"),
|
2021-04-30 11:28:06 -05:00
|
|
|
metrics.Instrument(
|
2021-04-28 15:59:15 -05:00
|
|
|
http.MethodDelete,
|
2022-05-05 06:58:32 -05:00
|
|
|
"/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}",
|
2021-04-28 15:59:15 -05:00
|
|
|
srv.RouteDeleteNamespaceRulesConfig,
|
2021-04-30 11:28:06 -05:00
|
|
|
m,
|
2021-04-28 15:59:15 -05:00
|
|
|
),
|
|
|
|
)
|
|
|
|
group.Delete(
|
2022-05-05 06:58:32 -05:00
|
|
|
toMacaronPath("/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}"),
|
|
|
|
api.authorize(http.MethodDelete, "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}"),
|
2021-04-30 11:28:06 -05:00
|
|
|
metrics.Instrument(
|
2021-04-28 15:59:15 -05:00
|
|
|
http.MethodDelete,
|
2022-05-05 06:58:32 -05:00
|
|
|
"/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}",
|
2021-04-28 15:59:15 -05:00
|
|
|
srv.RouteDeleteRuleGroupConfig,
|
2021-04-30 11:28:06 -05:00
|
|
|
m,
|
2021-04-28 15:59:15 -05:00
|
|
|
),
|
|
|
|
)
|
2022-02-04 11:42:04 -06:00
|
|
|
group.Get(
|
|
|
|
toMacaronPath("/api/ruler/grafana/api/v1/rules/{Namespace}/{Groupname}"),
|
|
|
|
api.authorize(http.MethodGet, "/api/ruler/grafana/api/v1/rules/{Namespace}/{Groupname}"),
|
|
|
|
metrics.Instrument(
|
|
|
|
http.MethodGet,
|
|
|
|
"/api/ruler/grafana/api/v1/rules/{Namespace}/{Groupname}",
|
|
|
|
srv.RouteGetGrafanaRuleGroupConfig,
|
|
|
|
m,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
group.Get(
|
|
|
|
toMacaronPath("/api/ruler/grafana/api/v1/rules"),
|
|
|
|
api.authorize(http.MethodGet, "/api/ruler/grafana/api/v1/rules"),
|
|
|
|
metrics.Instrument(
|
|
|
|
http.MethodGet,
|
|
|
|
"/api/ruler/grafana/api/v1/rules",
|
|
|
|
srv.RouteGetGrafanaRulesConfig,
|
|
|
|
m,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
group.Get(
|
|
|
|
toMacaronPath("/api/ruler/grafana/api/v1/rules/{Namespace}"),
|
|
|
|
api.authorize(http.MethodGet, "/api/ruler/grafana/api/v1/rules/{Namespace}"),
|
|
|
|
metrics.Instrument(
|
|
|
|
http.MethodGet,
|
|
|
|
"/api/ruler/grafana/api/v1/rules/{Namespace}",
|
|
|
|
srv.RouteGetNamespaceGrafanaRulesConfig,
|
|
|
|
m,
|
|
|
|
),
|
|
|
|
)
|
2021-04-28 15:59:15 -05:00
|
|
|
group.Get(
|
2022-05-05 06:58:32 -05:00
|
|
|
toMacaronPath("/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}"),
|
|
|
|
api.authorize(http.MethodGet, "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}"),
|
2021-04-30 11:28:06 -05:00
|
|
|
metrics.Instrument(
|
2021-04-28 15:59:15 -05:00
|
|
|
http.MethodGet,
|
2022-05-05 06:58:32 -05:00
|
|
|
"/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}",
|
2021-04-28 15:59:15 -05:00
|
|
|
srv.RouteGetNamespaceRulesConfig,
|
2021-04-30 11:28:06 -05:00
|
|
|
m,
|
2021-04-28 15:59:15 -05:00
|
|
|
),
|
|
|
|
)
|
|
|
|
group.Get(
|
2022-05-05 06:58:32 -05:00
|
|
|
toMacaronPath("/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}"),
|
|
|
|
api.authorize(http.MethodGet, "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}"),
|
2021-04-30 11:28:06 -05:00
|
|
|
metrics.Instrument(
|
2021-04-28 15:59:15 -05:00
|
|
|
http.MethodGet,
|
2022-05-05 06:58:32 -05:00
|
|
|
"/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}",
|
2021-04-28 15:59:15 -05:00
|
|
|
srv.RouteGetRulegGroupConfig,
|
2021-04-30 11:28:06 -05:00
|
|
|
m,
|
2021-04-28 15:59:15 -05:00
|
|
|
),
|
|
|
|
)
|
|
|
|
group.Get(
|
2022-05-05 06:58:32 -05:00
|
|
|
toMacaronPath("/api/ruler/{DatasourceUID}/api/v1/rules"),
|
|
|
|
api.authorize(http.MethodGet, "/api/ruler/{DatasourceUID}/api/v1/rules"),
|
2021-04-30 11:28:06 -05:00
|
|
|
metrics.Instrument(
|
2021-04-28 15:59:15 -05:00
|
|
|
http.MethodGet,
|
2022-05-05 06:58:32 -05:00
|
|
|
"/api/ruler/{DatasourceUID}/api/v1/rules",
|
2021-04-28 15:59:15 -05:00
|
|
|
srv.RouteGetRulesConfig,
|
2021-04-30 11:28:06 -05:00
|
|
|
m,
|
2021-04-28 15:59:15 -05:00
|
|
|
),
|
|
|
|
)
|
2022-02-04 11:42:04 -06:00
|
|
|
group.Post(
|
|
|
|
toMacaronPath("/api/ruler/grafana/api/v1/rules/{Namespace}"),
|
|
|
|
api.authorize(http.MethodPost, "/api/ruler/grafana/api/v1/rules/{Namespace}"),
|
|
|
|
metrics.Instrument(
|
|
|
|
http.MethodPost,
|
|
|
|
"/api/ruler/grafana/api/v1/rules/{Namespace}",
|
|
|
|
srv.RoutePostNameGrafanaRulesConfig,
|
|
|
|
m,
|
|
|
|
),
|
|
|
|
)
|
2021-04-28 15:59:15 -05:00
|
|
|
group.Post(
|
2022-05-05 06:58:32 -05:00
|
|
|
toMacaronPath("/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}"),
|
|
|
|
api.authorize(http.MethodPost, "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}"),
|
2021-04-30 11:28:06 -05:00
|
|
|
metrics.Instrument(
|
2021-04-28 15:59:15 -05:00
|
|
|
http.MethodPost,
|
2022-05-05 06:58:32 -05:00
|
|
|
"/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}",
|
2021-04-28 15:59:15 -05:00
|
|
|
srv.RoutePostNameRulesConfig,
|
2021-04-30 11:28:06 -05:00
|
|
|
m,
|
2021-04-28 15:59:15 -05:00
|
|
|
),
|
|
|
|
)
|
2022-03-24 16:13:47 -05:00
|
|
|
}, middleware.ReqSignedIn)
|
2021-04-09 04:55:41 -05:00
|
|
|
}
|