2021-08-06 13:06:56 +01: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 (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/api/response"
|
|
|
|
|
"github.com/grafana/grafana/pkg/api/routing"
|
2022-03-24 17:13:47 -04:00
|
|
|
"github.com/grafana/grafana/pkg/middleware"
|
2023-08-29 12:43:33 +02:00
|
|
|
"github.com/grafana/grafana/pkg/middleware/requestmeta"
|
2023-01-27 08:50:36 +01:00
|
|
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
2021-08-06 13:06:56 +01:00
|
|
|
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
2021-12-13 10:22:57 +02:00
|
|
|
"github.com/grafana/grafana/pkg/web"
|
2021-08-06 13:06:56 +01:00
|
|
|
)
|
|
|
|
|
|
2022-07-18 15:08:08 +08:00
|
|
|
type ConfigurationApi interface {
|
2023-01-27 08:50:36 +01:00
|
|
|
RouteDeleteNGalertConfig(*contextmodel.ReqContext) response.Response
|
|
|
|
|
RouteGetAlertmanagers(*contextmodel.ReqContext) response.Response
|
|
|
|
|
RouteGetNGalertConfig(*contextmodel.ReqContext) response.Response
|
|
|
|
|
RouteGetStatus(*contextmodel.ReqContext) response.Response
|
|
|
|
|
RoutePostNGalertConfig(*contextmodel.ReqContext) response.Response
|
2021-12-13 10:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-27 08:50:36 +01:00
|
|
|
func (f *ConfigurationApiHandler) RouteDeleteNGalertConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 15:08:08 +08:00
|
|
|
return f.handleRouteDeleteNGalertConfig(ctx)
|
2021-12-13 10:22:57 +02:00
|
|
|
}
|
2023-01-27 08:50:36 +01:00
|
|
|
func (f *ConfigurationApiHandler) RouteGetAlertmanagers(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 15:08:08 +08:00
|
|
|
return f.handleRouteGetAlertmanagers(ctx)
|
2021-12-13 10:22:57 +02:00
|
|
|
}
|
2023-01-27 08:50:36 +01:00
|
|
|
func (f *ConfigurationApiHandler) RouteGetNGalertConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 15:08:08 +08:00
|
|
|
return f.handleRouteGetNGalertConfig(ctx)
|
2021-12-13 10:22:57 +02:00
|
|
|
}
|
2023-01-27 08:50:36 +01:00
|
|
|
func (f *ConfigurationApiHandler) RouteGetStatus(ctx *contextmodel.ReqContext) response.Response {
|
2022-09-14 14:03:10 -04:00
|
|
|
return f.handleRouteGetStatus(ctx)
|
|
|
|
|
}
|
2023-01-27 08:50:36 +01:00
|
|
|
func (f *ConfigurationApiHandler) RoutePostNGalertConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 15:08:08 +08:00
|
|
|
// Parse Request Body
|
2021-12-13 10:22:57 +02:00
|
|
|
conf := apimodels.PostableNGalertConfig{}
|
|
|
|
|
if err := web.Bind(ctx.Req, &conf); err != nil {
|
|
|
|
|
return response.Error(http.StatusBadRequest, "bad request data", err)
|
|
|
|
|
}
|
2022-07-18 15:08:08 +08:00
|
|
|
return f.handleRoutePostNGalertConfig(ctx, conf)
|
2021-12-13 10:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
2022-07-18 15:08:08 +08:00
|
|
|
func (api *API) RegisterConfigurationApiEndpoints(srv ConfigurationApi, m *metrics.API) {
|
2021-08-06 13:06:56 +01:00
|
|
|
api.RouteRegister.Group("", func(group routing.RouteRegister) {
|
|
|
|
|
group.Delete(
|
|
|
|
|
toMacaronPath("/api/v1/ngalert/admin_config"),
|
2023-08-29 12:43:33 +02:00
|
|
|
requestmeta.SetOwner(requestmeta.TeamAlerting),
|
2023-09-29 14:56:48 +02:00
|
|
|
requestmeta.SetSLOGroup(requestmeta.SLOGroupHighSlow),
|
2022-02-04 12:42:04 -05:00
|
|
|
api.authorize(http.MethodDelete, "/api/v1/ngalert/admin_config"),
|
2021-08-06 13:06:56 +01:00
|
|
|
metrics.Instrument(
|
|
|
|
|
http.MethodDelete,
|
|
|
|
|
"/api/v1/ngalert/admin_config",
|
2023-04-24 18:18:44 +02:00
|
|
|
api.Hooks.Wrap(srv.RouteDeleteNGalertConfig),
|
2021-08-06 13:06:56 +01:00
|
|
|
m,
|
|
|
|
|
),
|
|
|
|
|
)
|
2021-08-13 13:14:36 +01:00
|
|
|
group.Get(
|
|
|
|
|
toMacaronPath("/api/v1/ngalert/alertmanagers"),
|
2023-08-29 12:43:33 +02:00
|
|
|
requestmeta.SetOwner(requestmeta.TeamAlerting),
|
2023-09-29 14:56:48 +02:00
|
|
|
requestmeta.SetSLOGroup(requestmeta.SLOGroupHighSlow),
|
2022-02-04 12:42:04 -05:00
|
|
|
api.authorize(http.MethodGet, "/api/v1/ngalert/alertmanagers"),
|
2021-08-13 13:14:36 +01:00
|
|
|
metrics.Instrument(
|
|
|
|
|
http.MethodGet,
|
|
|
|
|
"/api/v1/ngalert/alertmanagers",
|
2023-04-24 18:18:44 +02:00
|
|
|
api.Hooks.Wrap(srv.RouteGetAlertmanagers),
|
2021-08-13 13:14:36 +01:00
|
|
|
m,
|
|
|
|
|
),
|
|
|
|
|
)
|
2021-08-06 13:06:56 +01:00
|
|
|
group.Get(
|
|
|
|
|
toMacaronPath("/api/v1/ngalert/admin_config"),
|
2023-08-29 12:43:33 +02:00
|
|
|
requestmeta.SetOwner(requestmeta.TeamAlerting),
|
2023-09-29 14:56:48 +02:00
|
|
|
requestmeta.SetSLOGroup(requestmeta.SLOGroupHighSlow),
|
2022-02-04 12:42:04 -05:00
|
|
|
api.authorize(http.MethodGet, "/api/v1/ngalert/admin_config"),
|
2021-08-06 13:06:56 +01:00
|
|
|
metrics.Instrument(
|
|
|
|
|
http.MethodGet,
|
|
|
|
|
"/api/v1/ngalert/admin_config",
|
2023-04-24 18:18:44 +02:00
|
|
|
api.Hooks.Wrap(srv.RouteGetNGalertConfig),
|
2021-08-06 13:06:56 +01:00
|
|
|
m,
|
|
|
|
|
),
|
|
|
|
|
)
|
2022-09-14 14:03:10 -04:00
|
|
|
group.Get(
|
|
|
|
|
toMacaronPath("/api/v1/ngalert"),
|
2023-08-29 12:43:33 +02:00
|
|
|
requestmeta.SetOwner(requestmeta.TeamAlerting),
|
2023-09-29 14:56:48 +02:00
|
|
|
requestmeta.SetSLOGroup(requestmeta.SLOGroupHighSlow),
|
2022-09-14 14:03:10 -04:00
|
|
|
api.authorize(http.MethodGet, "/api/v1/ngalert"),
|
|
|
|
|
metrics.Instrument(
|
|
|
|
|
http.MethodGet,
|
|
|
|
|
"/api/v1/ngalert",
|
2023-04-24 18:18:44 +02:00
|
|
|
api.Hooks.Wrap(srv.RouteGetStatus),
|
2022-09-14 14:03:10 -04:00
|
|
|
m,
|
|
|
|
|
),
|
|
|
|
|
)
|
2021-08-06 13:06:56 +01:00
|
|
|
group.Post(
|
|
|
|
|
toMacaronPath("/api/v1/ngalert/admin_config"),
|
2023-08-29 12:43:33 +02:00
|
|
|
requestmeta.SetOwner(requestmeta.TeamAlerting),
|
2023-09-29 14:56:48 +02:00
|
|
|
requestmeta.SetSLOGroup(requestmeta.SLOGroupHighSlow),
|
2022-02-04 12:42:04 -05:00
|
|
|
api.authorize(http.MethodPost, "/api/v1/ngalert/admin_config"),
|
2021-08-06 13:06:56 +01:00
|
|
|
metrics.Instrument(
|
|
|
|
|
http.MethodPost,
|
|
|
|
|
"/api/v1/ngalert/admin_config",
|
2023-04-24 18:18:44 +02:00
|
|
|
api.Hooks.Wrap(srv.RoutePostNGalertConfig),
|
2021-08-06 13:06:56 +01:00
|
|
|
m,
|
|
|
|
|
),
|
|
|
|
|
)
|
2022-03-24 17:13:47 -04:00
|
|
|
}, middleware.ReqSignedIn)
|
2021-08-06 13:06:56 +01:00
|
|
|
}
|