2016-04-26 23:36:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								package  api  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  (  
						 
					
						
							
								
									
										
										
										
											2021-10-07 22:33:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"context" 
							 
						 
					
						
							
								
									
										
										
										
											2020-10-20 19:53:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"errors" 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-21 16:29:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"fmt" 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"net/http" 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-01 20:36:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"strconv" 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-21 16:29:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-27 19:02:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/api/dtos" 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/api/response" 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-20 22:13:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/alerting" 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									alertmodels  "github.com/grafana/grafana/pkg/services/alerting/models" 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									contextmodel  "github.com/grafana/grafana/pkg/services/contexthandler/model" 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-18 20:52:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/dashboards" 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:23:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/datasources" 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-30 21:41:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/guardian" 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-21 01:58:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/ngalert/notifier/channels_config" 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-18 03:47:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/notifications" 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-01 20:36:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/search" 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-30 22:17:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/search/model" 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-07 22:33:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/setting" 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-12 00:04:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/util" 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-11 20:30:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/web" 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-26 23:36:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  ValidateOrgAlert ( c  * contextmodel . ReqContext )  {  
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									id ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":alertId" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . JsonApiErr ( http . StatusBadRequest ,  "alertId is invalid" ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 00:22:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									query  :=  alertmodels . GetAlertByIdQuery { ID :  id } 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-26 23:36:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									res ,  err  :=  hs . AlertEngine . AlertStore . GetAlertById ( c . Req . Context ( ) ,  & query ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-26 23:36:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										c . JsonApiErr ( 404 ,  "Alert not found" ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  c . SignedInUser . GetOrgID ( )  !=  res . OrgID  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-26 23:36:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										c . JsonApiErr ( 403 ,  "You are not allowed to edit/view alert" ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-23 15:56:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-26 23:36:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route GET /alerts/states-for-dashboard legacy_alerts getDashboardStates
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Get alert states for a dashboard.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: getDashboardStatesResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  GetAlertStatesForDashboard ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2018-03-22 19:37:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									dashboardID  :=  c . QueryInt64 ( "dashboardId" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-30 23:37:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-03-22 19:37:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  dashboardID  ==  0  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 400 ,  "Missing query parameter dashboardId" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-30 23:37:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									query  :=  alertmodels . GetAlertStatesForDashboardQuery { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										OrgID :        c . SignedInUser . GetOrgID ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 00:22:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										DashboardID :  c . QueryInt64 ( "dashboardId" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-30 23:37:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									res ,  err  :=  hs . AlertEngine . AlertStore . GetAlertStatesForDashboard ( c . Req . Context ( ) ,  & query ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to fetch alert states" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-30 23:37:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  res ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-30 23:37:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route GET /alerts legacy_alerts getAlerts
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Get legacy alerts.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: getAlertsResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  GetAlerts ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2018-06-01 20:36:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									dashboardQuery  :=  c . Query ( "dashboardQuery" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									dashboardTags  :=  c . QueryStrings ( "dashboardTag" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stringDashboardIDs  :=  c . QueryStrings ( "dashboardId" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stringFolderIDs  :=  c . QueryStrings ( "folderId" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									dashboardIDs  :=  make ( [ ] int64 ,  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  id  :=  range  stringDashboardIDs  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										dashboardID ,  err  :=  strconv . ParseInt ( id ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											dashboardIDs  =  append ( dashboardIDs ,  dashboardID ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  dashboardQuery  !=  ""  ||  len ( dashboardTags )  >  0  ||  len ( stringFolderIDs )  >  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										folderIDs  :=  make ( [ ] int64 ,  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  _ ,  id  :=  range  stringFolderIDs  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											folderID ,  err  :=  strconv . ParseInt ( id ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  err  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												folderIDs  =  append ( folderIDs ,  folderID ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										searchQuery  :=  search . Query { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Title :         dashboardQuery , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Tags :          dashboardTags , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											SignedInUser :  c . SignedInUser , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Limit :         1000 , 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											OrgId :         c . SignedInUser . GetOrgID ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-01 20:36:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											DashboardIds :  dashboardIDs , 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-30 22:17:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Type :          string ( model . DashHitDB ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-07 22:51:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											FolderIds :     folderIDs ,  // nolint:staticcheck
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 21:46:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Permission :    dashboards . PERMISSION_VIEW , 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-01 20:36:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-30 17:28:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										hits ,  err  :=  hs . SearchService . SearchHandler ( c . Req . Context ( ) ,  & searchQuery ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-01 20:36:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 500 ,  "List alerts failed" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-01 20:36:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-30 17:28:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  _ ,  d  :=  range  hits  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-30 22:17:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  d . Type  ==  model . DashHitDB  &&  d . ID  >  0  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-11 15:49:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												dashboardIDs  =  append ( dashboardIDs ,  d . ID ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-01 20:36:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// if we didn't find any dashboards, return empty result
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  len ( dashboardIDs )  ==  0  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . JSON ( http . StatusOK ,  [ ] * alertmodels . AlertListItemDTO { } ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-01 20:36:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									query  :=  alertmodels . GetAlertsQuery { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										OrgID :         c . SignedInUser . GetOrgID ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-01 20:36:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										DashboardIDs :  dashboardIDs , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 00:22:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										PanelID :       c . QueryInt64 ( "panelId" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-01 20:36:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Limit :         c . QueryInt64 ( "limit" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										User :          c . SignedInUser , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Query :         c . Query ( "query" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-26 23:36:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 20:12:19 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									states  :=  c . QueryStrings ( "state" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( states )  >  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										query . State  =  states 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									res ,  err  :=  hs . AlertEngine . AlertStore . HandleAlertsQuery ( c . Req . Context ( ) ,  & query ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "List alerts failed" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-26 23:36:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  alert  :=  range  res  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 00:22:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										alert . URL  =  dashboards . GetDashboardURL ( alert . DashboardUID ,  alert . DashboardSlug ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-31 17:47:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  res ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-26 23:36:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route POST /alerts/test legacy_alerts testAlert
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Test alert.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: testAlertResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 422: unprocessableEntityError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  AlertTest ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									dto  :=  dtos . AlertTestCommand { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & dto ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-23 21:55:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  _ ,  idErr  :=  dto . Dashboard . Get ( "id" ) . Int64 ( ) ;  idErr  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 400 ,  "The dashboard needs to be saved at least once before you can test an alert rule" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-23 21:55:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									res ,  err  :=  hs . AlertEngine . AlertTest ( c . SignedInUser . GetOrgID ( ) ,  dto . Dashboard ,  dto . PanelId ,  c . SignedInUser ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-08 14:02:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-19 20:34:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  validationErr  alerting . ValidationError 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  errors . As ( err ,  & validationErr )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 422 ,  validationErr . Error ( ) ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-21 19:09:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:23:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  datasources . ErrDataSourceAccessDenied )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 403 ,  "Access denied to datasource" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-11-05 21:25:19 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to test rule" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-20 22:13:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-21 16:29:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									dtoRes  :=  & dtos . AlertTestResult { 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 22:48:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Firing :          res . Firing , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ConditionEvals :  res . ConditionEvals , 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-13 17:24:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										State :           res . Rule . State , 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-21 16:29:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  res . Error  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										dtoRes . Error  =  res . Error . Error ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-21 19:09:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  log  :=  range  res . Logs  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										dtoRes . Logs  =  append ( dtoRes . Logs ,  & dtos . AlertTestResultLog { Message :  log . Message ,  Data :  log . Data } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-18 17:22:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  match  :=  range  res . EvalMatches  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										dtoRes . EvalMatches  =  append ( dtoRes . EvalMatches ,  & dtos . EvalMatch { Metric :  match . Metric ,  Value :  match . Value } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-21 19:09:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-26 18:29:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									dtoRes . TimeMs  =  fmt . Sprintf ( "%1.3fms" ,  res . GetDurationMs ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-21 16:29:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-15 20:01:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  dtoRes ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-20 22:13:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route GET /alerts/{alert_id} legacy_alerts getAlertByID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Get alert by ID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// “evalMatches” data in the response is cached in the db when and only when the state of the alert changes (e.g. transitioning from “ok” to “alerting” state).
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// If data from one server triggers the alert first and, before that server is seen leaving alerting state, a second server also enters a state that would trigger the alert, the second server will not be visible in “evalMatches” data.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: getAlertResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  GetAlert ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									id ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":alertId" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "alertId is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 00:22:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									query  :=  alertmodels . GetAlertByIdQuery { ID :  id } 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-26 23:36:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									res ,  err  :=  hs . AlertEngine . AlertStore . GetAlertById ( c . Req . Context ( ) ,  & query ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "List alerts failed" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-26 23:36:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  & res ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-26 23:36:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-04-28 14:23:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  GetAlertNotifiers ( ngalertEnabled  bool )  func ( * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  func ( _  * contextmodel . ReqContext )  response . Response  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-04 19:58:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ngalertEnabled  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-21 01:58:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . JSON ( http . StatusOK ,  channels_config . GetAvailableNotifiers ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-04 19:58:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// TODO(codesome): This wont be required in 8.0 since ngalert
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// will be enabled by default with no disabling. This is to be removed later.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-15 20:01:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . JSON ( http . StatusOK ,  alerting . GetNotifiers ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-04 19:58:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-06 19:04:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route GET /alert-notifications/lookup legacy_alerts_notification_channels getAlertNotificationLookup
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
									
										
										
										
											2022-09-12 15:40:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Get all notification channels (lookup).
  
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Returns all notification channels, but with less detailed information. Accessible by any authenticated user and is mainly used by providing alert notification channels in Grafana UI when configuring alert rule.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: getAlertNotificationLookupResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  GetAlertNotificationLookup ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-02-04 20:41:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									alertNotifications ,  err  :=  hs . getAlertNotificationsInternal ( c ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-13 02:03:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to get alert notifications" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-13 02:03:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-15 16:48:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-08-13 02:03:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  :=  make ( [ ] * dtos . AlertNotificationLookup ,  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  notification  :=  range  alertNotifications  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										result  =  append ( result ,  dtos . NewAlertNotificationLookup ( notification ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-15 20:01:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  result ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-13 02:03:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route GET /alert-notifications legacy_alerts_notification_channels getAlertNotificationChannels
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Get all notification channels.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Returns all notification channels that the authenticated user has permission to view.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: getAlertNotificationChannelsResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  GetAlertNotifications ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-02-04 20:41:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									alertNotifications ,  err  :=  hs . getAlertNotificationsInternal ( c ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-13 02:03:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to get alert notifications" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-15 16:48:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-06 22:40:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  :=  make ( [ ] * dtos . AlertNotification ,  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-20 17:31:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-08-13 02:03:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  notification  :=  range  alertNotifications  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-05 04:19:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										result  =  append ( result ,  dtos . NewAlertNotification ( notification ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-20 17:31:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-15 20:01:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  result ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-15 16:48:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  getAlertNotificationsInternal ( c  * contextmodel . ReqContext )  ( [ ] * alertmodels . AlertNotification ,  error )  {  
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									query  :=  & alertmodels . GetAllAlertNotificationsQuery { OrgID :  c . SignedInUser . GetOrgID ( ) } 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  hs . AlertNotificationService . GetAllAlertNotifications ( c . Req . Context ( ) ,  query ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-13 02:03:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route GET /alert-notifications/{notification_channel_id} legacy_alerts_notification_channels getAlertNotificationChannelByID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Get notification channel by ID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Returns the notification channel given the notification channel ID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: getAlertNotificationChannelResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 404: notFoundError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  GetAlertNotificationByID ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									notificationId ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":notificationId" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "notificationId is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									query  :=  & alertmodels . GetAlertNotificationsQuery { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										OrgID :  c . SignedInUser . GetOrgID ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 22:46:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ID :     notificationId , 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-16 20:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 22:46:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  query . ID  ==  0  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 404 ,  "Alert notification not found" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-26 19:37:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									res ,  err  :=  hs . AlertNotificationService . GetAlertNotifications ( c . Req . Context ( ) ,  query ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to get alert notifications" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-26 19:37:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  res  ==  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 404 ,  "Alert notification not found" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-26 19:37:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  dtos . NewAlertNotification ( res ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-26 19:37:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route GET /alert-notifications/uid/{notification_channel_uid} legacy_alerts_notification_channels getAlertNotificationChannelByUID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
									
										
										
										
											2022-09-12 15:40:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Get notification channel by UID.
  
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Returns the notification channel given the notification channel UID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: getAlertNotificationChannelResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 404: notFoundError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  GetAlertNotificationByUID ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									query  :=  & alertmodels . GetAlertNotificationsWithUidQuery { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										OrgID :  c . SignedInUser . GetOrgID ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 22:46:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										UID :    web . Params ( c . Req ) [ ":uid" ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-26 19:37:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 22:46:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  query . UID  ==  ""  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 404 ,  "Alert notification not found" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-26 19:37:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									res ,  err  :=  hs . AlertNotificationService . GetAlertNotificationsWithUid ( c . Req . Context ( ) ,  query ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to get alert notifications" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-16 20:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  res  ==  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 404 ,  "Alert notification not found" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-14 03:30:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  dtos . NewAlertNotification ( res ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-16 20:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route POST /alert-notifications legacy_alerts_notification_channels createAlertNotificationChannel
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Create notification channel.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// You can find the full list of [supported notifiers](https://grafana.com/docs/grafana/latest/alerting/old-alerting/notifications/#list-of-supported-notifiers) on the alert notifiers page.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: getAlertNotificationChannelResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 409: conflictError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  CreateAlertNotification ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd  :=  alertmodels . CreateAlertNotificationCommand { } 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd . OrgID  =  c . SignedInUser . GetOrgID ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-15 16:48:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									res ,  err  :=  hs . AlertNotificationService . CreateAlertNotificationCommand ( c . Req . Context ( ) ,  & cmd ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  alertmodels . ErrAlertNotificationWithSameNameExists )  ||  errors . Is ( err ,  alertmodels . ErrAlertNotificationWithSameUIDExists )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 409 ,  "Failed to create alert notification" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-10-20 19:53:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-02 21:11:19 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  alertingErr  alerting . ValidationError 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  errors . As ( err ,  & alertingErr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  response . Error ( 400 ,  err . Error ( ) ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to create alert notification" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-15 16:48:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  dtos . NewAlertNotification ( res ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-15 16:48:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route PUT /alert-notifications/{notification_channel_id} legacy_alerts_notification_channels updateAlertNotificationChannel
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Update notification channel by ID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Updates an existing notification channel identified by ID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: getAlertNotificationChannelResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 404: notFoundError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  UpdateAlertNotification ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd  :=  alertmodels . UpdateAlertNotificationCommand { } 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd . OrgID  =  c . SignedInUser . GetOrgID ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-15 16:48:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-10-07 22:33:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									err  :=  hs . fillWithSecureSettingsData ( c . Req . Context ( ) ,  & cmd ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to update alert notification" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  _ ,  err  :=  hs . AlertNotificationService . UpdateAlertNotification ( c . Req . Context ( ) ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  alertmodels . ErrAlertNotificationNotFound )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 404 ,  err . Error ( ) ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-12 00:04:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-02 21:11:19 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  alertingErr  alerting . ValidationError 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  errors . As ( err ,  & alertingErr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  response . Error ( 400 ,  err . Error ( ) ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to update alert notification" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-15 16:48:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									query  :=  alertmodels . GetAlertNotificationsQuery { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										OrgID :  c . SignedInUser . GetOrgID ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 22:46:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ID :     cmd . ID , 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									res ,  err  :=  hs . AlertNotificationService . GetAlertNotifications ( c . Req . Context ( ) ,  & query ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to get alert notification" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  dtos . NewAlertNotification ( res ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-15 16:48:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-06-16 21:21:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route PUT /alert-notifications/uid/{notification_channel_uid} legacy_alerts_notification_channels updateAlertNotificationChannelByUID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Update notification channel by UID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Updates an existing notification channel identified by uid.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: getAlertNotificationChannelResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 404: notFoundError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  UpdateAlertNotificationByUID ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd  :=  alertmodels . UpdateAlertNotificationWithUidCommand { } 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd . OrgID  =  c . SignedInUser . GetOrgID ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 22:46:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd . UID  =  web . Params ( c . Req ) [ ":uid" ] 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-26 19:37:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-10-07 22:33:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									err  :=  hs . fillWithSecureSettingsDataByUID ( c . Req . Context ( ) ,  & cmd ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to update alert notification" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  _ ,  err  :=  hs . AlertNotificationService . UpdateAlertNotificationWithUid ( c . Req . Context ( ) ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  alertmodels . ErrAlertNotificationNotFound )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 404 ,  err . Error ( ) ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-12 00:04:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to update alert notification" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-26 19:37:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									query  :=  alertmodels . GetAlertNotificationsWithUidQuery { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 22:46:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										OrgID :  cmd . OrgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										UID :    cmd . UID , 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									res ,  err  :=  hs . AlertNotificationService . GetAlertNotificationsWithUid ( c . Req . Context ( ) ,  & query ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to get alert notification" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  dtos . NewAlertNotification ( res ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  fillWithSecureSettingsData ( ctx  context . Context ,  cmd  * alertmodels . UpdateAlertNotificationCommand )  error  {  
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  len ( cmd . SecureSettings )  ==  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									query  :=  & alertmodels . GetAlertNotificationsQuery { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 22:46:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										OrgID :  cmd . OrgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ID :     cmd . ID , 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									res ,  err  :=  hs . AlertNotificationService . GetAlertNotifications ( ctx ,  query ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-07 22:33:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									secureSettings ,  err  :=  hs . EncryptionService . DecryptJsonData ( ctx ,  res . SecureSettings ,  setting . SecretKey ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-07 22:33:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  k ,  v  :=  range  secureSettings  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  _ ,  ok  :=  cmd . SecureSettings [ k ] ;  ! ok  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											cmd . SecureSettings [ k ]  =  v 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  fillWithSecureSettingsDataByUID ( ctx  context . Context ,  cmd  * alertmodels . UpdateAlertNotificationWithUidCommand )  error  {  
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  len ( cmd . SecureSettings )  ==  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									query  :=  & alertmodels . GetAlertNotificationsWithUidQuery { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 22:46:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										OrgID :  cmd . OrgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										UID :    cmd . UID , 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									res ,  err  :=  hs . AlertNotificationService . GetAlertNotificationsWithUid ( ctx ,  query ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-07 22:33:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									secureSettings ,  err  :=  hs . EncryptionService . DecryptJsonData ( ctx ,  res . SecureSettings ,  setting . SecretKey ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-07 22:33:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  k ,  v  :=  range  secureSettings  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  _ ,  ok  :=  cmd . SecureSettings [ k ] ;  ! ok  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											cmd . SecureSettings [ k ]  =  v 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  nil 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-26 19:37:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route DELETE /alert-notifications/{notification_channel_id} legacy_alerts_notification_channels deleteAlertNotificationChannel
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Delete alert notification by ID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Deletes an existing notification channel identified by ID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 404: notFoundError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  DeleteAlertNotification ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									notificationId ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":notificationId" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "notificationId is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd  :=  alertmodels . DeleteAlertNotificationCommand { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										OrgID :  c . SignedInUser . GetOrgID ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 22:46:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ID :     notificationId , 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-16 21:21:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-17 01:54:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  :=  hs . AlertNotificationService . DeleteAlertNotification ( c . Req . Context ( ) ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  alertmodels . ErrAlertNotificationNotFound )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 404 ,  err . Error ( ) ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-12 00:04:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to delete alert notification" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-16 21:21:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . Success ( "Notification deleted" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-16 21:21:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-08-30 15:32:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route DELETE /alert-notifications/uid/{notification_channel_uid} legacy_alerts_notification_channels deleteAlertNotificationChannelByUID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Delete alert notification by UID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Deletes an existing notification channel identified by UID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: deleteAlertNotificationChannelResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 404: notFoundError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  DeleteAlertNotificationByUID ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd  :=  alertmodels . DeleteAlertNotificationWithUidCommand { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										OrgID :  c . SignedInUser . GetOrgID ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 22:46:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										UID :    web . Params ( c . Req ) [ ":uid" ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-26 19:37:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-17 01:54:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  :=  hs . AlertNotificationService . DeleteAlertNotificationWithUid ( c . Req . Context ( ) ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  alertmodels . ErrAlertNotificationNotFound )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 404 ,  err . Error ( ) ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-12 00:04:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to delete alert notification" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-26 19:37:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-15 20:01:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  util . DynMap { 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-12 00:04:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										"message" :  "Notification deleted" , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 22:46:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										"id" :       cmd . DeletedAlertNotificationID , 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-12 00:04:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-26 19:37:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route POST /alert-notifications/test legacy_alerts_notification_channels notificationChannelTest
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Test notification channel.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Sends a test notification to the channel.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 412: SMTPNotEnabledError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  NotificationTest ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									dto  :=  dtos . NotificationTestCommand { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & dto ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-05 20:43:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd  :=  & alerting . NotificationTestCommand { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										OrgID :           c . SignedInUser . GetOrgID ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 16:17:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ID :              dto . ID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Name :            dto . Name , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Type :            dto . Type , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Settings :        dto . Settings , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										SecureSettings :  dto . SecureSettings , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-05 20:43:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-08 20:30:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  :=  hs . AlertNotificationService . HandleNotificationTestCommand ( c . Req . Context ( ) ,  cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-18 03:47:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  notifications . ErrSmtpNotEnabled )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 412 ,  err . Error ( ) ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-25 19:16:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-04-22 22:00:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  alertingErr  alerting . ValidationError 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  errors . As ( err ,  & alertingErr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  response . Error ( 400 ,  err . Error ( ) ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to send alert notifications" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-05 20:43:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . Success ( "Test notification sent" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-05 20:43:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route POST /alerts/{alert_id}/pause legacy_alerts pauseAlert
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Pause/unpause alert by id.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: pauseAlertResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 404: notFoundError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  PauseAlert ( legacyAlertingEnabled  * bool )  func ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  legacyAlertingEnabled  ==  nil  ||  ! * legacyAlertingEnabled  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  func ( _  * contextmodel . ReqContext )  response . Response  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( http . StatusBadRequest ,  "legacy alerting is disabled, so this call has no effect." ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-30 21:41:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  func ( c  * contextmodel . ReqContext )  response . Response  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										dto  :=  dtos . PauseAlertCommand { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  :=  web . Bind ( c . Req ,  & dto ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										alertID ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":alertId" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-30 21:41:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( http . StatusBadRequest ,  "alertId is invalid" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-30 21:41:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-30 23:46:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										result  :=  make ( map [ string ] any ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										result [ "alertId" ]  =  alertID 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-30 21:41:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 00:22:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										query  :=  alertmodels . GetAlertByIdQuery { ID :  alertID } 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										res ,  err  :=  hs . AlertEngine . AlertStore . GetAlertById ( c . Req . Context ( ) ,  & query ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 500 ,  "Get Alert failed" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-30 21:41:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										guardian ,  err  :=  guardian . New ( c . Req . Context ( ) ,  res . DashboardID ,  c . SignedInUser . GetOrgID ( ) ,  c . SignedInUser ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-15 22:34:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  response . ErrOrFallback ( http . StatusInternalServerError ,  "Error while creating permission guardian" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  canEdit ,  err  :=  guardian . CanEdit ( ) ;  err  !=  nil  ||  ! canEdit  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  response . Error ( 500 ,  "Error while checking permissions for Alert" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-09 18:18:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 403 ,  "Access denied to this dashboard and alert" ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 20:26:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Alert state validation
 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  res . State  !=  alertmodels . AlertStatePaused  &&  ! dto . Paused  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											result [ "state" ]  =  "un-paused" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											result [ "message" ]  =  "Alert is already un-paused" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  response . JSON ( http . StatusOK ,  result ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 16:41:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										}  else  if  res . State  ==  alertmodels . AlertStatePaused  &&  dto . Paused  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											result [ "state" ]  =  alertmodels . AlertStatePaused 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											result [ "message" ]  =  "Alert is already paused" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  response . JSON ( http . StatusOK ,  result ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 20:26:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										cmd  :=  alertmodels . PauseAlertCommand { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 17:34:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											OrgID :     c . SignedInUser . GetOrgID ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 00:22:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											AlertIDs :  [ ] int64 { alertID } , 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Paused :    dto . Paused , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 20:26:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-03 23:17:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  err  :=  hs . AlertEngine . AlertStore . PauseAlert ( c . Req . Context ( ) ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 500 ,  "" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										resp  :=  alertmodels . AlertStateUnknown 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										pausedState  :=  "un-paused" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  cmd . Paused  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											resp  =  alertmodels . AlertStatePaused 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											pausedState  =  "paused" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										result [ "state" ]  =  resp 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										result [ "message" ]  =  "Alert "  +  pausedState 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . JSON ( http . StatusOK ,  result ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 20:26:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-12-16 00:01:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route POST /admin/pause-all-alerts admin pauseAllAlerts
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Pause/unpause all (legacy) alerts.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Security:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// - basic:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: pauseAlertsResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  PauseAllAlerts ( legacyAlertingEnabled  * bool )  func ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  legacyAlertingEnabled  ==  nil  ||  ! * legacyAlertingEnabled  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  func ( _  * contextmodel . ReqContext )  response . Response  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( http . StatusBadRequest ,  "legacy alerting is disabled, so this call has no effect." ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-16 00:01:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  func ( c  * contextmodel . ReqContext )  response . Response  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										dto  :=  dtos . PauseAllAlertsCommand { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  :=  web . Bind ( c . Req ,  & dto ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										updateCmd  :=  alertmodels . PauseAllAlertCommand { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Paused :  dto . Paused , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-16 00:01:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-03 23:17:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  err  :=  hs . AlertEngine . AlertStore . PauseAllAlerts ( c . Req . Context ( ) ,  & updateCmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 500 ,  "Failed to pause alerts" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-16 00:01:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										resp  :=  alertmodels . AlertStatePending 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										pausedState  :=  "un paused" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  updateCmd . Paused  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											resp  =  alertmodels . AlertStatePaused 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											pausedState  =  "paused" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-16 00:01:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-30 23:46:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										result  :=  map [ string ] any { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 15:01:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											"state" :           resp , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											"message" :         "alerts "  +  pausedState , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											"alertsAffected" :  updateCmd . ResultCount , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . JSON ( http . StatusOK ,  result ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-16 00:01:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters pauseAllAlerts
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  PauseAllAlertsParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  dtos . PauseAllAlertsCommand  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters deleteAlertNotificationChannel
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  DeleteAlertNotificationChannelParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									NotificationID  int64  ` json:"notification_channel_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters getAlertNotificationChannelByID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  GetAlertNotificationChannelByIDParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									NotificationID  int64  ` json:"notification_channel_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters deleteAlertNotificationChannelByUID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  DeleteAlertNotificationChannelByUIDParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									NotificationUID  string  ` json:"notification_channel_uid" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters getAlertNotificationChannelByUID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  GetAlertNotificationChannelByUIDParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									NotificationUID  string  ` json:"notification_channel_uid" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters notificationChannelTest
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  NotificationChannelTestParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  dtos . NotificationTestCommand  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters createAlertNotificationChannel
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  CreateAlertNotificationChannelParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Body  alertmodels . CreateAlertNotificationCommand  ` json:"body" ` 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters updateAlertNotificationChannel
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  UpdateAlertNotificationChannelParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Body  alertmodels . UpdateAlertNotificationCommand  ` json:"body" ` 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									NotificationID  int64  ` json:"notification_channel_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters updateAlertNotificationChannelByUID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  UpdateAlertNotificationChannelByUIDParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Body  alertmodels . UpdateAlertNotificationWithUidCommand  ` json:"body" ` 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									NotificationUID  string  ` json:"notification_channel_uid" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters getAlertByID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  GetAlertByIDParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AlertID  string  ` json:"alert_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters pauseAlert
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  PauseAlertParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AlertID  string  ` json:"alert_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  dtos . PauseAlertCommand  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters getAlerts
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  GetAlertsParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Limit response to alerts in specified dashboard(s). You can specify multiple dashboards.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DashboardID  [ ] string  ` json:"dashboardId" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									//  Limit response to alert for a specified panel on a dashboard.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									PanelID  int64  ` json:"panelId" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Limit response to alerts having a name like this value.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required: false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Query  string  ` json:"query" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Return alerts with one or more of the following alert states
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Description:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// * `all`
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// * `no_data`
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// * `paused`
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// * `alerting`
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// * `ok`
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// * `pending`
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// * `unknown`
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// enum: all,no_data,paused,alerting,ok,pending,unknown
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									State  string  ` json:"state" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Limit response to X number of alerts.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Limit  int64  ` json:"limit" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Limit response to alerts of dashboards in specified folder(s). You can specify multiple folders
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// type array
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// collectionFormat: multi
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									FolderID  [ ] string  ` json:"folderId" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Limit response to alerts having a dashboard name like this value./ Limit response to alerts having a dashboard name like this value.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DashboardQuery  string  ` json:"dashboardQuery" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Limit response to alerts of dashboards with specified tags. To do an “AND” filtering with multiple tags, specify the tags parameter multiple times
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// type: array
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// collectionFormat: multi
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DashboardTag  [ ] string  ` json:"dashboardTag" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters testAlert
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  TestAlertParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  dtos . AlertTestCommand  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters getDashboardStates
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  GetDashboardStatesParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required: true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DashboardID  int64  ` json:"dashboardId" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response pauseAlertsResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  PauseAllAlertsResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// AlertsAffected is the number of the affected alerts.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// required: true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										AlertsAffected  int64  ` json:"alertsAffected" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// required: true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Message  string  ` json:"message" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Alert result state
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// required true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										State  string  ` json:"state" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response getAlertNotificationChannelsResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  GetAlertNotificationChannelsResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  [ ] * dtos . AlertNotification  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response getAlertNotificationLookupResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  LookupAlertNotificationChannelsResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  [ ] * dtos . AlertNotificationLookup  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response getAlertNotificationChannelResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  GetAlertNotificationChannelResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  * dtos . AlertNotification  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response deleteAlertNotificationChannelResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  DeleteAlertNotificationChannelResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ID Identifier of the deleted notification channel.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// required: true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// example: 65
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ID  int64  ` json:"id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Message Message of the deleted notificatiton channel.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// required: true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Message  string  ` json:"message" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response SMTPNotEnabledError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  SMTPNotEnabledError  PreconditionFailedError  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response getAlertsResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  GetAlertsResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Body  [ ] * alertmodels . AlertListItemDTO  ` json:"body" ` 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response getAlertResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  GetAlertResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Body  * alertmodels . Alert  ` json:"body" ` 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response pauseAlertResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  PauseAlertResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// required: true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										AlertID  int64  ` json:"alertId" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// required: true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Message  string  ` json:"message" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Alert result state
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// required true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										State  string  ` json:"state" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response testAlertResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  TestAlertResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  * dtos . AlertTestResult  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response getDashboardStatesResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  GetDashboardStatesResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-23 21:19:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Body  [ ] * alertmodels . AlertStateInfoDTO  ` json:"body" ` 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}