2021-03-11 21:28:00 +02:00
|
|
|
/*Package api contains base API implementation of unified alerting
|
|
|
|
|
*
|
2021-04-09 10:55:41 +01:00
|
|
|
*Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
2021-03-11 21:28:00 +02:00
|
|
|
*
|
2021-04-09 10:55:41 +01:00
|
|
|
*Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them.
|
2021-03-11 21:28:00 +02:00
|
|
|
*/
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
2021-04-28 16:59:15 -04:00
|
|
|
"net/http"
|
|
|
|
|
|
2021-03-11 21:28:00 +02:00
|
|
|
"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-04-30 12:28:06 -04:00
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
2022-06-23 15:13:39 -05:00
|
|
|
"github.com/grafana/grafana/pkg/web"
|
2021-03-11 21:28:00 +02:00
|
|
|
)
|
|
|
|
|
|
2022-07-18 15:08:08 +08:00
|
|
|
type PrometheusApi interface {
|
2023-01-27 08:50:36 +01:00
|
|
|
RouteGetAlertStatuses(*contextmodel.ReqContext) response.Response
|
|
|
|
|
RouteGetGrafanaAlertStatuses(*contextmodel.ReqContext) response.Response
|
|
|
|
|
RouteGetGrafanaRuleStatuses(*contextmodel.ReqContext) response.Response
|
|
|
|
|
RouteGetRuleStatuses(*contextmodel.ReqContext) response.Response
|
2021-03-11 21:28:00 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-27 08:50:36 +01:00
|
|
|
func (f *PrometheusApiHandler) RouteGetAlertStatuses(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 15:08:08 +08:00
|
|
|
// Parse Path Parameters
|
2022-06-23 15:13:39 -05:00
|
|
|
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
2022-07-18 15:08:08 +08:00
|
|
|
return f.handleRouteGetAlertStatuses(ctx, datasourceUIDParam)
|
2021-12-13 10:22:57 +02:00
|
|
|
}
|
2023-01-27 08:50:36 +01:00
|
|
|
func (f *PrometheusApiHandler) RouteGetGrafanaAlertStatuses(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 15:08:08 +08:00
|
|
|
return f.handleRouteGetGrafanaAlertStatuses(ctx)
|
2022-02-04 12:42:04 -05:00
|
|
|
}
|
2023-01-27 08:50:36 +01:00
|
|
|
func (f *PrometheusApiHandler) RouteGetGrafanaRuleStatuses(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 15:08:08 +08:00
|
|
|
return f.handleRouteGetGrafanaRuleStatuses(ctx)
|
2022-02-04 12:42:04 -05:00
|
|
|
}
|
2023-01-27 08:50:36 +01:00
|
|
|
func (f *PrometheusApiHandler) RouteGetRuleStatuses(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 15:08:08 +08:00
|
|
|
// Parse Path Parameters
|
2022-06-23 15:13:39 -05:00
|
|
|
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
2022-07-18 15:08:08 +08:00
|
|
|
return f.handleRouteGetRuleStatuses(ctx, datasourceUIDParam)
|
2021-12-13 10:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
2022-07-18 15:08:08 +08:00
|
|
|
func (api *API) RegisterPrometheusApiEndpoints(srv PrometheusApi, m *metrics.API) {
|
2021-03-11 21:28:00 +02:00
|
|
|
api.RouteRegister.Group("", func(group routing.RouteRegister) {
|
2021-04-28 16:59:15 -04:00
|
|
|
group.Get(
|
2022-05-06 22:05:02 +03:00
|
|
|
toMacaronPath("/api/prometheus/{DatasourceUID}/api/v1/alerts"),
|
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-05-06 22:05:02 +03:00
|
|
|
api.authorize(http.MethodGet, "/api/prometheus/{DatasourceUID}/api/v1/alerts"),
|
2021-04-30 12:28:06 -04:00
|
|
|
metrics.Instrument(
|
2021-04-28 16:59:15 -04:00
|
|
|
http.MethodGet,
|
2022-05-06 22:05:02 +03:00
|
|
|
"/api/prometheus/{DatasourceUID}/api/v1/alerts",
|
2023-04-24 18:18:44 +02:00
|
|
|
api.Hooks.Wrap(srv.RouteGetAlertStatuses),
|
2021-04-30 12:28:06 -04:00
|
|
|
m,
|
2021-04-28 16:59:15 -04:00
|
|
|
),
|
|
|
|
|
)
|
2022-02-04 12:42:04 -05:00
|
|
|
group.Get(
|
|
|
|
|
toMacaronPath("/api/prometheus/grafana/api/v1/alerts"),
|
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/prometheus/grafana/api/v1/alerts"),
|
|
|
|
|
metrics.Instrument(
|
|
|
|
|
http.MethodGet,
|
|
|
|
|
"/api/prometheus/grafana/api/v1/alerts",
|
2023-04-24 18:18:44 +02:00
|
|
|
api.Hooks.Wrap(srv.RouteGetGrafanaAlertStatuses),
|
2022-02-04 12:42:04 -05:00
|
|
|
m,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
group.Get(
|
|
|
|
|
toMacaronPath("/api/prometheus/grafana/api/v1/rules"),
|
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/prometheus/grafana/api/v1/rules"),
|
|
|
|
|
metrics.Instrument(
|
|
|
|
|
http.MethodGet,
|
|
|
|
|
"/api/prometheus/grafana/api/v1/rules",
|
2023-04-24 18:18:44 +02:00
|
|
|
api.Hooks.Wrap(srv.RouteGetGrafanaRuleStatuses),
|
2022-02-04 12:42:04 -05:00
|
|
|
m,
|
|
|
|
|
),
|
|
|
|
|
)
|
2021-04-28 16:59:15 -04:00
|
|
|
group.Get(
|
2022-05-06 22:05:02 +03:00
|
|
|
toMacaronPath("/api/prometheus/{DatasourceUID}/api/v1/rules"),
|
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-05-06 22:05:02 +03:00
|
|
|
api.authorize(http.MethodGet, "/api/prometheus/{DatasourceUID}/api/v1/rules"),
|
2021-04-30 12:28:06 -04:00
|
|
|
metrics.Instrument(
|
2021-04-28 16:59:15 -04:00
|
|
|
http.MethodGet,
|
2022-05-06 22:05:02 +03:00
|
|
|
"/api/prometheus/{DatasourceUID}/api/v1/rules",
|
2023-04-24 18:18:44 +02:00
|
|
|
api.Hooks.Wrap(srv.RouteGetRuleStatuses),
|
2021-04-30 12:28:06 -04:00
|
|
|
m,
|
2021-04-28 16:59:15 -04:00
|
|
|
),
|
|
|
|
|
)
|
2022-03-24 17:13:47 -04:00
|
|
|
}, middleware.ReqSignedIn)
|
2021-03-11 21:28:00 +02:00
|
|
|
}
|