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