2023-02-28 06:57:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								package  api  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  (  
						 
					
						
							
								
									
										
										
										
											2024-05-14 21:29:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"bytes" 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-30 01:34:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"encoding/json" 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-28 06:57:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"time" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-12 10:36:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									jsoniter  "github.com/json-iterator/go" 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-28 06:57:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"github.com/prometheus/common/model" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/ngalert/models" 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 03:16:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/util" 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-28 06:57:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// AlertRuleFromProvisionedAlertRule converts definitions.ProvisionedAlertRule to models.AlertRule
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  AlertRuleFromProvisionedAlertRule ( a  definitions . ProvisionedAlertRule )  ( models . AlertRule ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  models . AlertRule { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-15 22:45:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ID :                    a . ID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										UID :                   a . UID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										OrgID :                 a . OrgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										NamespaceUID :          a . FolderUID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										RuleGroup :             a . RuleGroup , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Title :                 a . Title , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Condition :             a . Condition , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Data :                  AlertQueriesFromApiAlertQueries ( a . Data ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Updated :               a . Updated , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										NoDataState :           models . NoDataState ( a . NoDataState ) ,           // TODO there must be a validation
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ExecErrState :          models . ExecutionErrorState ( a . ExecErrState ) ,  // TODO there must be a validation
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										For :                   time . Duration ( a . For ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Annotations :           a . Annotations , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Labels :                a . Labels , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										IsPaused :              a . IsPaused , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										NotificationSettings :  NotificationSettingsFromAlertRuleNotificationSettings ( a . NotificationSettings ) , 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-10 01:12:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Recording Rule fields will be implemented in the future.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// For now, no rules can be recording rules. So, we force these to be empty.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Record :  nil , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-28 06:57:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ProvisionedAlertRuleFromAlertRule converts models.AlertRule to definitions.ProvisionedAlertRule and sets provided provenance status
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ProvisionedAlertRuleFromAlertRule ( rule  models . AlertRule ,  provenance  models . Provenance )  definitions . ProvisionedAlertRule  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  definitions . ProvisionedAlertRule { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-15 22:45:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ID :                    rule . ID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										UID :                   rule . UID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										OrgID :                 rule . OrgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										FolderUID :             rule . NamespaceUID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										RuleGroup :             rule . RuleGroup , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Title :                 rule . Title , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										For :                   model . Duration ( rule . For ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Condition :             rule . Condition , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Data :                  ApiAlertQueriesFromAlertQueries ( rule . Data ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Updated :               rule . Updated , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										NoDataState :           definitions . NoDataState ( rule . NoDataState ) ,           // TODO there may be a validation
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ExecErrState :          definitions . ExecutionErrorState ( rule . ExecErrState ) ,  // TODO there may be a validation
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Annotations :           rule . Annotations , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Labels :                rule . Labels , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Provenance :            definitions . Provenance ( provenance ) ,  // TODO validate enum conversion?
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										IsPaused :              rule . IsPaused , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										NotificationSettings :  AlertRuleNotificationSettingsFromNotificationSettings ( rule . NotificationSettings ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-28 06:57:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ProvisionedAlertRuleFromAlertRules converts a collection of models.AlertRule to definitions.ProvisionedAlertRules with provenance status models.ProvenanceNone
  
						 
					
						
							
								
									
										
										
										
											2023-10-11 21:51:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ProvisionedAlertRuleFromAlertRules ( rules  [ ] * models . AlertRule ,  provenances  map [ string ] models . Provenance )  definitions . ProvisionedAlertRules  {  
						 
					
						
							
								
									
										
										
										
											2023-02-28 06:57:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									result  :=  make ( [ ] definitions . ProvisionedAlertRule ,  0 ,  len ( rules ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  r  :=  range  rules  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-11 21:51:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										result  =  append ( result ,  ProvisionedAlertRuleFromAlertRule ( * r ,  provenances [ r . UID ] ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-28 06:57:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  result 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-27 23:55:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// AlertQueriesFromApiAlertQueries converts a collection of definitions.AlertQuery to collection of models.AlertQuery
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  AlertQueriesFromApiAlertQueries ( queries  [ ] definitions . AlertQuery )  [ ] models . AlertQuery  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									result  :=  make ( [ ] models . AlertQuery ,  0 ,  len ( queries ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  q  :=  range  queries  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										result  =  append ( result ,  models . AlertQuery { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											RefID :      q . RefID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											QueryType :  q . QueryType , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											RelativeTimeRange :  models . RelativeTimeRange { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												From :  models . Duration ( q . RelativeTimeRange . From ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												To :    models . Duration ( q . RelativeTimeRange . To ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											DatasourceUID :  q . DatasourceUID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Model :          q . Model , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  result 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ApiAlertQueriesFromAlertQueries converts a collection of models.AlertQuery to collection of definitions.AlertQuery
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ApiAlertQueriesFromAlertQueries ( queries  [ ] models . AlertQuery )  [ ] definitions . AlertQuery  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									result  :=  make ( [ ] definitions . AlertQuery ,  0 ,  len ( queries ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  q  :=  range  queries  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										result  =  append ( result ,  definitions . AlertQuery { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											RefID :      q . RefID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											QueryType :  q . QueryType , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											RelativeTimeRange :  definitions . RelativeTimeRange { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												From :  definitions . Duration ( q . RelativeTimeRange . From ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												To :    definitions . Duration ( q . RelativeTimeRange . To ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											DatasourceUID :  q . DatasourceUID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Model :          q . Model , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  result 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  AlertRuleGroupFromApiAlertRuleGroup ( a  definitions . AlertRuleGroup )  ( models . AlertRuleGroup ,  error )  {  
						 
					
						
							
								
									
										
										
										
											2023-02-28 06:57:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ruleGroup  :=  models . AlertRuleGroup { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Title :      a . Title , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										FolderUID :  a . FolderUID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Interval :   a . Interval , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i  :=  range  a . Rules  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										converted ,  err  :=  AlertRuleFromProvisionedAlertRule ( a . Rules [ i ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  models . AlertRuleGroup { } ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ruleGroup . Rules  =  append ( ruleGroup . Rules ,  converted ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  ruleGroup ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-27 23:55:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ApiAlertRuleGroupFromAlertRuleGroup ( d  models . AlertRuleGroup )  definitions . AlertRuleGroup  {  
						 
					
						
							
								
									
										
										
										
											2023-02-28 06:57:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									rules  :=  make ( [ ] definitions . ProvisionedAlertRule ,  0 ,  len ( d . Rules ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i  :=  range  d . Rules  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										rules  =  append ( rules ,  ProvisionedAlertRuleFromAlertRule ( d . Rules [ i ] ,  d . Provenance ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  definitions . AlertRuleGroup { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Title :      d . Title , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										FolderUID :  d . FolderUID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Interval :   d . Interval , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Rules :      rules , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2023-03-30 01:34:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// AlertingFileExportFromAlertRuleGroupWithFolderTitle creates an definitions.AlertingFileExport DTO from []models.AlertRuleGroupWithFolderTitle.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  AlertingFileExportFromAlertRuleGroupWithFolderTitle ( groups  [ ] models . AlertRuleGroupWithFolderTitle )  ( definitions . AlertingFileExport ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									f  :=  definitions . AlertingFileExport { APIVersion :  1 } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  group  :=  range  groups  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										export ,  err  :=  AlertRuleGroupExportFromAlertRuleGroupWithFolderTitle ( group ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  definitions . AlertingFileExport { } ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										f . Groups  =  append ( f . Groups ,  export ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  f ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// AlertRuleGroupExportFromAlertRuleGroupWithFolderTitle creates a definitions.AlertRuleGroupExport DTO from models.AlertRuleGroup.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  AlertRuleGroupExportFromAlertRuleGroupWithFolderTitle ( d  models . AlertRuleGroupWithFolderTitle )  ( definitions . AlertRuleGroupExport ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									rules  :=  make ( [ ] definitions . AlertRuleExport ,  0 ,  len ( d . Rules ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i  :=  range  d . Rules  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										alert ,  err  :=  AlertRuleExportFromAlertRule ( d . Rules [ i ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  definitions . AlertRuleGroupExport { } ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										rules  =  append ( rules ,  alert ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  definitions . AlertRuleGroupExport { 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-11 23:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										OrgID :            d . OrgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Name :             d . Title , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Folder :           d . FolderTitle , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										FolderUID :        d . FolderUID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Interval :         model . Duration ( time . Duration ( d . Interval )  *  time . Second ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										IntervalSeconds :  d . Interval , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Rules :            rules , 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-30 01:34:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// AlertRuleExportFromAlertRule creates a definitions.AlertRuleExport DTO from models.AlertRule.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  AlertRuleExportFromAlertRule ( rule  models . AlertRule )  ( definitions . AlertRuleExport ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									data  :=  make ( [ ] definitions . AlertQueryExport ,  0 ,  len ( rule . Data ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i  :=  range  rule . Data  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										query ,  err  :=  AlertQueryExportFromAlertQuery ( rule . Data [ i ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  definitions . AlertRuleExport { } ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										data  =  append ( data ,  query ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 03:16:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  :=  definitions . AlertRuleExport { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-15 22:45:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										UID :                   rule . UID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Title :                 rule . Title , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										For :                   model . Duration ( rule . For ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Condition :             rule . Condition , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Data :                  data , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										DashboardUID :          rule . DashboardUID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										PanelID :               rule . PanelID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										NoDataState :           definitions . NoDataState ( rule . NoDataState ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ExecErrState :          definitions . ExecutionErrorState ( rule . ExecErrState ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										IsPaused :              rule . IsPaused , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										NotificationSettings :  AlertRuleNotificationSettingsExportFromNotificationSettings ( rule . NotificationSettings ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 03:16:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  rule . For . Seconds ( )  >  0  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-20 17:09:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										result . ForString  =  util . Pointer ( model . Duration ( rule . For ) . String ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 03:16:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  rule . Annotations  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										result . Annotations  =  & rule . Annotations 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  rule . Labels  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										result . Labels  =  & rule . Labels 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  result ,  nil 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-30 01:34:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-14 21:29:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  encodeQueryModel ( m  map [ string ] any )  ( string ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  buf  bytes . Buffer 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									enc  :=  json . NewEncoder ( & buf ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									enc . SetEscapeHTML ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									err  :=  enc . Encode ( m ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  "" ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  string ( bytes . TrimRight ( buf . Bytes ( ) ,  "\n" ) ) ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-30 01:34:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// AlertQueryExportFromAlertQuery creates a definitions.AlertQueryExport DTO from models.AlertQuery.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  AlertQueryExportFromAlertQuery ( query  models . AlertQuery )  ( definitions . AlertQueryExport ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// We unmarshal the json.RawMessage model into a map in order to facilitate yaml marshalling.
 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-30 23:46:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  mdl  map [ string ] any 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-30 01:34:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									err  :=  json . Unmarshal ( query . Model ,  & mdl ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  definitions . AlertQueryExport { } ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 03:16:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  queryType  * string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  query . QueryType  !=  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										queryType  =  & query . QueryType 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-14 21:29:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									modelString ,  err  :=  encodeQueryModel ( mdl ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  definitions . AlertQueryExport { } ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-30 01:34:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  definitions . AlertQueryExport { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										RefID :      query . RefID , 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-06 03:16:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										QueryType :  queryType , 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-11 23:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										RelativeTimeRange :  definitions . RelativeTimeRangeExport { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											FromSeconds :  int64 ( time . Duration ( query . RelativeTimeRange . From ) . Seconds ( ) ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ToSeconds :    int64 ( time . Duration ( query . RelativeTimeRange . To ) . Seconds ( ) ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-30 01:34:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										DatasourceUID :  query . DatasourceUID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Model :          mdl , 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-14 21:29:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ModelString :    modelString , 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-30 01:34:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2023-07-21 02:35:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// AlertingFileExportFromEmbeddedContactPoints creates a definitions.AlertingFileExport DTO from []definitions.EmbeddedContactPoint.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  AlertingFileExportFromEmbeddedContactPoints ( orgID  int64 ,  ecps  [ ] definitions . EmbeddedContactPoint )  ( definitions . AlertingFileExport ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									f  :=  definitions . AlertingFileExport { APIVersion :  1 } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cache  :=  make ( map [ string ] * definitions . ContactPointExport ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									contactPoints  :=  make ( [ ] * definitions . ContactPointExport ,  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  ecp  :=  range  ecps  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c ,  ok  :=  cache [ ecp . Name ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ! ok  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											c  =  & definitions . ContactPointExport { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												OrgID :      orgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Name :       ecp . Name , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Receivers :  make ( [ ] definitions . ReceiverExport ,  0 ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											cache [ ecp . Name ]  =  c 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											contactPoints  =  append ( contactPoints ,  c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										recv ,  err  :=  ReceiverExportFromEmbeddedContactPoint ( ecp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  definitions . AlertingFileExport { } ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Receivers  =  append ( c . Receivers ,  recv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  c  :=  range  contactPoints  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										f . ContactPoints  =  append ( f . ContactPoints ,  * c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  f ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ReceiverExportFromEmbeddedContactPoint creates a definitions.ReceiverExport DTO from definitions.EmbeddedContactPoint.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ReceiverExportFromEmbeddedContactPoint ( contact  definitions . EmbeddedContactPoint )  ( definitions . ReceiverExport ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									raw ,  err  :=  contact . Settings . MarshalJSON ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  definitions . ReceiverExport { } ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  definitions . ReceiverExport { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										UID :                    contact . UID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Type :                   contact . Type , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Settings :               raw , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										DisableResolveMessage :  contact . DisableResolveMessage , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2023-07-25 05:56:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// AlertingFileExportFromRoute creates a definitions.AlertingFileExport DTO from definitions.Route.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  AlertingFileExportFromRoute ( orgID  int64 ,  route  definitions . Route )  ( definitions . AlertingFileExport ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									f  :=  definitions . AlertingFileExport { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										APIVersion :  1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Policies :  [ ] definitions . NotificationPolicyExport { { 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-05 05:57:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											OrgID :        orgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											RouteExport :  RouteExportFromRoute ( & route ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-25 05:56:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  f ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// RouteExportFromRoute creates a definitions.RouteExport DTO from definitions.Route.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  RouteExportFromRoute ( route  * definitions . Route )  * definitions . RouteExport  {  
						 
					
						
							
								
									
										
										
										
											2023-10-13 00:10:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									toStringIfNotNil  :=  func ( d  * model . Duration )  * string  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  d  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										s  :=  d . String ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  & s 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									matchers  :=  make ( [ ] * definitions . MatcherExport ,  0 ,  len ( route . ObjectMatchers ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  matcher  :=  range  route . ObjectMatchers  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										matchers  =  append ( matchers ,  & definitions . MatcherExport { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Label :  matcher . Name , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Match :  matcher . Type . String ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Value :  matcher . Value , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-07-25 05:56:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									export  :=  definitions . RouteExport { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-13 00:10:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Receiver :             route . Receiver , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										GroupByStr :           NilIfEmpty ( util . Pointer ( route . GroupByStr ) ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Match :                route . Match , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										MatchRE :              route . MatchRE , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Matchers :             route . Matchers , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ObjectMatchers :       route . ObjectMatchers , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ObjectMatchersSlice :  matchers , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										MuteTimeIntervals :    NilIfEmpty ( util . Pointer ( route . MuteTimeIntervals ) ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Continue :             OmitDefault ( util . Pointer ( route . Continue ) ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										GroupWait :            toStringIfNotNil ( route . GroupWait ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										GroupInterval :        toStringIfNotNil ( route . GroupInterval ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										RepeatInterval :       toStringIfNotNil ( route . RepeatInterval ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-25 05:56:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( route . Routes )  >  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										export . Routes  =  make ( [ ] * definitions . RouteExport ,  0 ,  len ( route . Routes ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  _ ,  r  :=  range  route . Routes  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											export . Routes  =  append ( export . Routes ,  RouteExportFromRoute ( r ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  & export 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2023-10-13 00:10:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// OmitDefault returns nil if the value is the default.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  OmitDefault [ T  comparable ] ( v  * T )  * T  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  def  T 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  v  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  v 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  * v  ==  def  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  v 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// NilIfEmpty returns nil if pointer to slice points to the empty slice.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  NilIfEmpty [ T  any ] ( v  * [ ] T )  * [ ] T  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  v  ==  nil  ||  len ( * v )  ==  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  v 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2023-12-12 10:36:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  AlertingFileExportFromMuteTimings ( orgID  int64 ,  m  [ ] definitions . MuteTimeInterval )  definitions . AlertingFileExport  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									f  :=  definitions . AlertingFileExport { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										APIVersion :   1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										MuteTimings :  make ( [ ] definitions . MuteTimeIntervalExport ,  0 ,  len ( m ) ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  mi  :=  range  m  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										f . MuteTimings  =  append ( f . MuteTimings ,  MuteTimeIntervalExportFromMuteTiming ( orgID ,  mi ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  f 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  MuteTimeIntervalExportFromMuteTiming ( orgID  int64 ,  m  definitions . MuteTimeInterval )  definitions . MuteTimeIntervalExport  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  definitions . MuteTimeIntervalExport { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										OrgID :             orgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										MuteTimeInterval :  m . MuteTimeInterval , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Converts definitions.MuteTimeIntervalExport to definitions.MuteTimeIntervalExportHcl using JSON marshalling. Returns error if structure could not be marshalled\unmarshalled
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  MuteTimingIntervalToMuteTimeIntervalHclExport ( m  definitions . MuteTimeIntervalExport )  ( definitions . MuteTimeIntervalExportHcl ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									result  :=  definitions . MuteTimeIntervalExportHcl { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									j  :=  jsoniter . ConfigCompatibleWithStandardLibrary 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									mdata ,  err  :=  j . Marshal ( m ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  result ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									err  =  j . Unmarshal ( mdata ,  & result ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  result ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2024-02-15 22:45:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// AlertRuleNotificationSettingsFromNotificationSettings converts []models.NotificationSettings to definitions.AlertRuleNotificationSettings
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  AlertRuleNotificationSettingsFromNotificationSettings ( ns  [ ] models . NotificationSettings )  * definitions . AlertRuleNotificationSettings  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( ns )  ==  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									m  :=  ns [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  & definitions . AlertRuleNotificationSettings { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Receiver :           m . Receiver , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										GroupBy :            m . GroupBy , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										GroupWait :          m . GroupWait , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										GroupInterval :      m . GroupInterval , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										RepeatInterval :     m . RepeatInterval , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										MuteTimeIntervals :  m . MuteTimeIntervals , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// AlertRuleNotificationSettingsFromNotificationSettings converts []models.NotificationSettings to definitions.AlertRuleNotificationSettingsExport
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  AlertRuleNotificationSettingsExportFromNotificationSettings ( ns  [ ] models . NotificationSettings )  * definitions . AlertRuleNotificationSettingsExport  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( ns )  ==  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									m  :=  ns [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									toStringIfNotNil  :=  func ( d  * model . Duration )  * string  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  d  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										s  :=  d . String ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  & s 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  & definitions . AlertRuleNotificationSettingsExport { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Receiver :           m . Receiver , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										GroupBy :            m . GroupBy , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										GroupWait :          toStringIfNotNil ( m . GroupWait ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										GroupInterval :      toStringIfNotNil ( m . GroupInterval ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										RepeatInterval :     toStringIfNotNil ( m . RepeatInterval ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										MuteTimeIntervals :  m . MuteTimeIntervals , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// NotificationSettingsFromAlertRuleNotificationSettings converts definitions.AlertRuleNotificationSettings to []models.NotificationSettings
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  NotificationSettingsFromAlertRuleNotificationSettings ( ns  * definitions . AlertRuleNotificationSettings )  [ ] models . NotificationSettings  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ns  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  [ ] models . NotificationSettings { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Receiver :           ns . Receiver , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											GroupBy :            ns . GroupBy , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											GroupWait :          ns . GroupWait , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											GroupInterval :      ns . GroupInterval , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											RepeatInterval :     ns . RepeatInterval , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											MuteTimeIntervals :  ns . MuteTimeIntervals , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}