| 
									
										
										
										
											2021-08-06 20:06:56 +08: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-25 05:13:47 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/middleware" | 
					
						
							| 
									
										
										
										
											2023-01-27 15:50:36 +08:00
										 |  |  | 	contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" | 
					
						
							| 
									
										
										
										
											2021-08-06 20:06:56 +08:00
										 |  |  | 	apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/services/ngalert/metrics" | 
					
						
							| 
									
										
										
										
											2021-12-13 16:22:57 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/web" | 
					
						
							| 
									
										
										
										
											2021-08-06 20:06:56 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-18 15:08:08 +08:00
										 |  |  | type ConfigurationApi interface { | 
					
						
							| 
									
										
										
										
											2023-01-27 15:50:36 +08: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 16:22:57 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-27 15:50:36 +08: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 16:22:57 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-01-27 15:50:36 +08: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 16:22:57 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-01-27 15:50:36 +08: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 16:22:57 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-01-27 15:50:36 +08:00
										 |  |  | func (f *ConfigurationApiHandler) RouteGetStatus(ctx *contextmodel.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2022-09-15 02:03:10 +08:00
										 |  |  | 	return f.handleRouteGetStatus(ctx) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-01-27 15:50:36 +08:00
										 |  |  | func (f *ConfigurationApiHandler) RoutePostNGalertConfig(ctx *contextmodel.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2022-07-18 15:08:08 +08:00
										 |  |  | 	// Parse Request Body
 | 
					
						
							| 
									
										
										
										
											2021-12-13 16:22:57 +08: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 16:22:57 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-18 15:08:08 +08:00
										 |  |  | func (api *API) RegisterConfigurationApiEndpoints(srv ConfigurationApi, m *metrics.API) { | 
					
						
							| 
									
										
										
										
											2021-08-06 20:06:56 +08:00
										 |  |  | 	api.RouteRegister.Group("", func(group routing.RouteRegister) { | 
					
						
							|  |  |  | 		group.Delete( | 
					
						
							|  |  |  | 			toMacaronPath("/api/v1/ngalert/admin_config"), | 
					
						
							| 
									
										
										
										
											2022-02-05 01:42:04 +08:00
										 |  |  | 			api.authorize(http.MethodDelete, "/api/v1/ngalert/admin_config"), | 
					
						
							| 
									
										
										
										
											2021-08-06 20:06:56 +08:00
										 |  |  | 			metrics.Instrument( | 
					
						
							|  |  |  | 				http.MethodDelete, | 
					
						
							|  |  |  | 				"/api/v1/ngalert/admin_config", | 
					
						
							|  |  |  | 				srv.RouteDeleteNGalertConfig, | 
					
						
							|  |  |  | 				m, | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 		) | 
					
						
							| 
									
										
										
										
											2021-08-13 20:14:36 +08:00
										 |  |  | 		group.Get( | 
					
						
							|  |  |  | 			toMacaronPath("/api/v1/ngalert/alertmanagers"), | 
					
						
							| 
									
										
										
										
											2022-02-05 01:42:04 +08:00
										 |  |  | 			api.authorize(http.MethodGet, "/api/v1/ngalert/alertmanagers"), | 
					
						
							| 
									
										
										
										
											2021-08-13 20:14:36 +08:00
										 |  |  | 			metrics.Instrument( | 
					
						
							|  |  |  | 				http.MethodGet, | 
					
						
							|  |  |  | 				"/api/v1/ngalert/alertmanagers", | 
					
						
							|  |  |  | 				srv.RouteGetAlertmanagers, | 
					
						
							|  |  |  | 				m, | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 		) | 
					
						
							| 
									
										
										
										
											2021-08-06 20:06:56 +08:00
										 |  |  | 		group.Get( | 
					
						
							|  |  |  | 			toMacaronPath("/api/v1/ngalert/admin_config"), | 
					
						
							| 
									
										
										
										
											2022-02-05 01:42:04 +08:00
										 |  |  | 			api.authorize(http.MethodGet, "/api/v1/ngalert/admin_config"), | 
					
						
							| 
									
										
										
										
											2021-08-06 20:06:56 +08:00
										 |  |  | 			metrics.Instrument( | 
					
						
							|  |  |  | 				http.MethodGet, | 
					
						
							|  |  |  | 				"/api/v1/ngalert/admin_config", | 
					
						
							|  |  |  | 				srv.RouteGetNGalertConfig, | 
					
						
							|  |  |  | 				m, | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 		) | 
					
						
							| 
									
										
										
										
											2022-09-15 02:03:10 +08:00
										 |  |  | 		group.Get( | 
					
						
							|  |  |  | 			toMacaronPath("/api/v1/ngalert"), | 
					
						
							|  |  |  | 			api.authorize(http.MethodGet, "/api/v1/ngalert"), | 
					
						
							|  |  |  | 			metrics.Instrument( | 
					
						
							|  |  |  | 				http.MethodGet, | 
					
						
							|  |  |  | 				"/api/v1/ngalert", | 
					
						
							|  |  |  | 				srv.RouteGetStatus, | 
					
						
							|  |  |  | 				m, | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 		) | 
					
						
							| 
									
										
										
										
											2021-08-06 20:06:56 +08:00
										 |  |  | 		group.Post( | 
					
						
							|  |  |  | 			toMacaronPath("/api/v1/ngalert/admin_config"), | 
					
						
							| 
									
										
										
										
											2022-02-05 01:42:04 +08:00
										 |  |  | 			api.authorize(http.MethodPost, "/api/v1/ngalert/admin_config"), | 
					
						
							| 
									
										
										
										
											2021-08-06 20:06:56 +08:00
										 |  |  | 			metrics.Instrument( | 
					
						
							|  |  |  | 				http.MethodPost, | 
					
						
							|  |  |  | 				"/api/v1/ngalert/admin_config", | 
					
						
							|  |  |  | 				srv.RoutePostNGalertConfig, | 
					
						
							|  |  |  | 				m, | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 		) | 
					
						
							| 
									
										
										
										
											2022-03-25 05:13:47 +08:00
										 |  |  | 	}, middleware.ReqSignedIn) | 
					
						
							| 
									
										
										
										
											2021-08-06 20:06:56 +08:00
										 |  |  | } |