2021-03-11 13:28:00 -06:00
|
|
|
/*Package api contains base API implementation of unified alerting
|
|
|
|
*
|
2021-04-09 04:55:41 -05:00
|
|
|
*Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
2021-03-11 13:28:00 -06:00
|
|
|
*
|
2021-04-09 04:55:41 -05:00
|
|
|
*Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them.
|
2021-03-11 13:28:00 -06:00
|
|
|
*/
|
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2021-04-28 15:59:15 -05:00
|
|
|
"net/http"
|
|
|
|
|
2021-03-11 13:28:00 -06: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-03-11 13:28:00 -06:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2021-04-30 11:28:06 -05: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 13:28:00 -06:00
|
|
|
)
|
|
|
|
|
2022-07-18 02:08:08 -05:00
|
|
|
type PrometheusApi interface {
|
2021-12-13 02:22:57 -06:00
|
|
|
RouteGetAlertStatuses(*models.ReqContext) response.Response
|
2022-02-04 11:42:04 -06:00
|
|
|
RouteGetGrafanaAlertStatuses(*models.ReqContext) response.Response
|
|
|
|
RouteGetGrafanaRuleStatuses(*models.ReqContext) response.Response
|
2021-03-11 13:28:00 -06:00
|
|
|
RouteGetRuleStatuses(*models.ReqContext) response.Response
|
|
|
|
}
|
|
|
|
|
2022-07-18 02:08:08 -05:00
|
|
|
func (f *PrometheusApiHandler) RouteGetAlertStatuses(ctx *models.ReqContext) response.Response {
|
|
|
|
// 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.handleRouteGetAlertStatuses(ctx, datasourceUIDParam)
|
2021-12-13 02:22:57 -06:00
|
|
|
}
|
2022-07-18 02:08:08 -05:00
|
|
|
func (f *PrometheusApiHandler) RouteGetGrafanaAlertStatuses(ctx *models.ReqContext) response.Response {
|
|
|
|
return f.handleRouteGetGrafanaAlertStatuses(ctx)
|
2022-02-04 11:42:04 -06:00
|
|
|
}
|
2022-07-18 02:08:08 -05:00
|
|
|
func (f *PrometheusApiHandler) RouteGetGrafanaRuleStatuses(ctx *models.ReqContext) response.Response {
|
|
|
|
return f.handleRouteGetGrafanaRuleStatuses(ctx)
|
2022-02-04 11:42:04 -06:00
|
|
|
}
|
2022-07-18 02:08:08 -05:00
|
|
|
func (f *PrometheusApiHandler) RouteGetRuleStatuses(ctx *models.ReqContext) response.Response {
|
|
|
|
// 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.handleRouteGetRuleStatuses(ctx, datasourceUIDParam)
|
2021-12-13 02:22:57 -06:00
|
|
|
}
|
|
|
|
|
2022-07-18 02:08:08 -05:00
|
|
|
func (api *API) RegisterPrometheusApiEndpoints(srv PrometheusApi, m *metrics.API) {
|
2021-03-11 13:28:00 -06:00
|
|
|
api.RouteRegister.Group("", func(group routing.RouteRegister) {
|
2021-04-28 15:59:15 -05:00
|
|
|
group.Get(
|
2022-05-06 14:05:02 -05:00
|
|
|
toMacaronPath("/api/prometheus/{DatasourceUID}/api/v1/alerts"),
|
|
|
|
api.authorize(http.MethodGet, "/api/prometheus/{DatasourceUID}/api/v1/alerts"),
|
2021-04-30 11:28:06 -05:00
|
|
|
metrics.Instrument(
|
2021-04-28 15:59:15 -05:00
|
|
|
http.MethodGet,
|
2022-05-06 14:05:02 -05:00
|
|
|
"/api/prometheus/{DatasourceUID}/api/v1/alerts",
|
2021-04-28 15:59:15 -05:00
|
|
|
srv.RouteGetAlertStatuses,
|
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/prometheus/grafana/api/v1/alerts"),
|
|
|
|
api.authorize(http.MethodGet, "/api/prometheus/grafana/api/v1/alerts"),
|
|
|
|
metrics.Instrument(
|
|
|
|
http.MethodGet,
|
|
|
|
"/api/prometheus/grafana/api/v1/alerts",
|
|
|
|
srv.RouteGetGrafanaAlertStatuses,
|
|
|
|
m,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
group.Get(
|
|
|
|
toMacaronPath("/api/prometheus/grafana/api/v1/rules"),
|
|
|
|
api.authorize(http.MethodGet, "/api/prometheus/grafana/api/v1/rules"),
|
|
|
|
metrics.Instrument(
|
|
|
|
http.MethodGet,
|
|
|
|
"/api/prometheus/grafana/api/v1/rules",
|
|
|
|
srv.RouteGetGrafanaRuleStatuses,
|
|
|
|
m,
|
|
|
|
),
|
|
|
|
)
|
2021-04-28 15:59:15 -05:00
|
|
|
group.Get(
|
2022-05-06 14:05:02 -05:00
|
|
|
toMacaronPath("/api/prometheus/{DatasourceUID}/api/v1/rules"),
|
|
|
|
api.authorize(http.MethodGet, "/api/prometheus/{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-06 14:05:02 -05:00
|
|
|
"/api/prometheus/{DatasourceUID}/api/v1/rules",
|
2021-04-28 15:59:15 -05:00
|
|
|
srv.RouteGetRuleStatuses,
|
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-03-11 13:28:00 -06:00
|
|
|
}
|