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.
|
|
|
|
*/
|
|
|
|
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"
|
2023-01-27 01:50:36 -06:00
|
|
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
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
|
|
|
)
|
|
|
|
|
2022-07-18 02:08:08 -05:00
|
|
|
type RulerApi interface {
|
2023-01-27 01:50:36 -06:00
|
|
|
RouteDeleteGrafanaRuleGroupConfig(*contextmodel.ReqContext) response.Response
|
|
|
|
RouteDeleteNamespaceGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
|
|
|
|
RouteDeleteNamespaceRulesConfig(*contextmodel.ReqContext) response.Response
|
|
|
|
RouteDeleteRuleGroupConfig(*contextmodel.ReqContext) response.Response
|
|
|
|
RouteGetGrafanaRuleGroupConfig(*contextmodel.ReqContext) response.Response
|
|
|
|
RouteGetGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
|
|
|
|
RouteGetNamespaceGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
|
|
|
|
RouteGetNamespaceRulesConfig(*contextmodel.ReqContext) response.Response
|
|
|
|
RouteGetRulegGroupConfig(*contextmodel.ReqContext) response.Response
|
|
|
|
RouteGetRulesConfig(*contextmodel.ReqContext) response.Response
|
|
|
|
RoutePostNameGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
|
|
|
|
RoutePostNameRulesConfig(*contextmodel.ReqContext) response.Response
|
2021-12-13 02:22:57 -06:00
|
|
|
}
|
|
|
|
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *RulerApiHandler) RouteDeleteGrafanaRuleGroupConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Path Parameters
|
2022-06-23 15:13:39 -05:00
|
|
|
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
|
|
|
groupnameParam := web.Params(ctx.Req)[":Groupname"]
|
2022-07-18 02:08:08 -05:00
|
|
|
return f.handleRouteDeleteGrafanaRuleGroupConfig(ctx, namespaceParam, groupnameParam)
|
2022-02-04 11:42:04 -06:00
|
|
|
}
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *RulerApiHandler) RouteDeleteNamespaceGrafanaRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Path Parameters
|
2022-06-23 15:13:39 -05:00
|
|
|
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
2022-07-18 02:08:08 -05:00
|
|
|
return f.handleRouteDeleteNamespaceGrafanaRulesConfig(ctx, namespaceParam)
|
2021-04-09 04:55:41 -05:00
|
|
|
}
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *RulerApiHandler) RouteDeleteNamespaceRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Path Parameters
|
2022-06-23 15:13:39 -05:00
|
|
|
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
|
|
|
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
2022-07-18 02:08:08 -05:00
|
|
|
return f.handleRouteDeleteNamespaceRulesConfig(ctx, datasourceUIDParam, namespaceParam)
|
2021-12-13 02:22:57 -06:00
|
|
|
}
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *RulerApiHandler) RouteDeleteRuleGroupConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Path Parameters
|
2022-06-23 15:13:39 -05:00
|
|
|
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
|
|
|
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
|
|
|
groupnameParam := web.Params(ctx.Req)[":Groupname"]
|
2022-07-18 02:08:08 -05:00
|
|
|
return f.handleRouteDeleteRuleGroupConfig(ctx, datasourceUIDParam, namespaceParam, groupnameParam)
|
2021-12-13 02:22:57 -06:00
|
|
|
}
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *RulerApiHandler) RouteGetGrafanaRuleGroupConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Path Parameters
|
2022-06-23 15:13:39 -05:00
|
|
|
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
|
|
|
groupnameParam := web.Params(ctx.Req)[":Groupname"]
|
2022-07-18 02:08:08 -05:00
|
|
|
return f.handleRouteGetGrafanaRuleGroupConfig(ctx, namespaceParam, groupnameParam)
|
2022-02-04 11:42:04 -06:00
|
|
|
}
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *RulerApiHandler) RouteGetGrafanaRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 02:08:08 -05:00
|
|
|
return f.handleRouteGetGrafanaRulesConfig(ctx)
|
2022-02-04 11:42:04 -06:00
|
|
|
}
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *RulerApiHandler) RouteGetNamespaceGrafanaRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Path Parameters
|
2022-06-23 15:13:39 -05:00
|
|
|
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
2022-07-18 02:08:08 -05:00
|
|
|
return f.handleRouteGetNamespaceGrafanaRulesConfig(ctx, namespaceParam)
|
2022-02-04 11:42:04 -06:00
|
|
|
}
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *RulerApiHandler) RouteGetNamespaceRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Path Parameters
|
2022-06-23 15:13:39 -05:00
|
|
|
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
|
|
|
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
2022-07-18 02:08:08 -05:00
|
|
|
return f.handleRouteGetNamespaceRulesConfig(ctx, datasourceUIDParam, namespaceParam)
|
2021-12-13 02:22:57 -06:00
|
|
|
}
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *RulerApiHandler) RouteGetRulegGroupConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Path Parameters
|
2022-06-23 15:13:39 -05:00
|
|
|
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
|
|
|
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
|
|
|
groupnameParam := web.Params(ctx.Req)[":Groupname"]
|
2022-07-18 02:08:08 -05:00
|
|
|
return f.handleRouteGetRulegGroupConfig(ctx, datasourceUIDParam, namespaceParam, groupnameParam)
|
2021-12-13 02:22:57 -06:00
|
|
|
}
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *RulerApiHandler) RouteGetRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Path Parameters
|
2022-06-23 15:13:39 -05:00
|
|
|
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
2022-07-18 02:08:08 -05:00
|
|
|
return f.handleRouteGetRulesConfig(ctx, datasourceUIDParam)
|
2021-12-13 02:22:57 -06:00
|
|
|
}
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *RulerApiHandler) RoutePostNameGrafanaRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Path Parameters
|
2022-06-23 15:13:39 -05:00
|
|
|
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Request Body
|
2022-02-04 11:42:04 -06:00
|
|
|
conf := apimodels.PostableRuleGroupConfig{}
|
|
|
|
if err := web.Bind(ctx.Req, &conf); err != nil {
|
|
|
|
return response.Error(http.StatusBadRequest, "bad request data", err)
|
|
|
|
}
|
2022-07-18 02:08:08 -05:00
|
|
|
return f.handleRoutePostNameGrafanaRulesConfig(ctx, conf, namespaceParam)
|
2022-02-04 11:42:04 -06:00
|
|
|
}
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *RulerApiHandler) RoutePostNameRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Path Parameters
|
2022-06-23 15:13:39 -05:00
|
|
|
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
|
|
|
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Request Body
|
2021-12-13 02:22:57 -06:00
|
|
|
conf := apimodels.PostableRuleGroupConfig{}
|
|
|
|
if err := web.Bind(ctx.Req, &conf); err != nil {
|
|
|
|
return response.Error(http.StatusBadRequest, "bad request data", err)
|
|
|
|
}
|
2022-07-18 02:08:08 -05:00
|
|
|
return f.handleRoutePostNameRulesConfig(ctx, conf, datasourceUIDParam, namespaceParam)
|
2021-12-13 02:22:57 -06:00
|
|
|
}
|
|
|
|
|
2022-07-18 02:08:08 -05:00
|
|
|
func (api *API) RegisterRulerApiEndpoints(srv RulerApi, 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
|
|
|
}
|