@@ -468,20 +468,39 @@ var metricsMissingDataTriggerConditionSchema = map[string]*schema.Schema{
468468}
469469
470470var sloSLITriggerConditionSchema = map [string ]* schema.Schema {
471- "sli_threshold" : {
472- Type : schema .TypeFloat ,
473- Required : true ,
474- ValidateFunc : validation .FloatBetween (0 , 100 ),
475- },
471+ "critical" : nested (true , schemaMap {
472+ "sli_threshold" : {
473+ Type : schema .TypeFloat ,
474+ Required : true ,
475+ ValidateFunc : validation .FloatBetween (0 , 100 ),
476+ },
477+ }),
478+ "warning" : nested (true , schemaMap {
479+ "sli_threshold" : {
480+ Type : schema .TypeFloat ,
481+ Required : true ,
482+ ValidateFunc : validation .FloatBetween (0 , 100 ),
483+ },
484+ }),
476485}
477486
478487var sloBurnRateTriggerConditionSchema = map [string ]* schema.Schema {
479- "time_range" : & timeRangeSchema ,
480- "burn_rate_threshold" : {
481- Type : schema .TypeFloat ,
482- Required : true ,
483- ValidateFunc : validation .FloatAtLeast (0 ),
484- },
488+ "critical" : nested (true , schemaMap {
489+ "time_range" : & timeRangeSchema ,
490+ "burn_rate_threshold" : {
491+ Type : schema .TypeFloat ,
492+ Required : true ,
493+ ValidateFunc : validation .FloatAtLeast (0 ),
494+ },
495+ }),
496+ "warning" : nested (true , schemaMap {
497+ "time_range" : & timeRangeSchema ,
498+ "burn_rate_threshold" : {
499+ Type : schema .TypeFloat ,
500+ Required : true ,
501+ ValidateFunc : validation .FloatAtLeast (0 ),
502+ },
503+ }),
485504}
486505
487506var occurrenceTypeSchema = schema.Schema {
@@ -588,6 +607,7 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in
588607 d .Set ("group_notifications" , monitor .GroupNotifications )
589608 d .Set ("playbook" , monitor .Playbook )
590609 d .Set ("alert_name" , monitor .AlertName )
610+ d .Set ("slo_id" , monitor .SloID )
591611 // set notifications
592612 notifications := make ([]interface {}, len (monitor .Notifications ))
593613 for i , n := range monitor .Notifications {
@@ -804,6 +824,12 @@ func triggerConditionsBlockToJson(block map[string]interface{}) []TriggerConditi
804824 if sc , ok := fromSingletonArray (block , metricsMissingDataConditionFieldName ); ok {
805825 conditions = append (conditions , metricsMissingDataConditionBlockToJson (sc )... )
806826 }
827+ if sc , ok := fromSingletonArray (block , sloSLIConditionFieldName ); ok {
828+ conditions = append (conditions , sloSLIConditionBlockToJson (sc )... )
829+ }
830+ if sc , ok := fromSingletonArray (block , sloBurnRateConditionFieldName ); ok {
831+ conditions = append (conditions , sloBurnConditionBlockToJson (sc )... )
832+ }
807833
808834 return conditions
809835}
@@ -867,7 +893,6 @@ func logsMissingDataConditionBlockToJson(block map[string]interface{}) []Trigger
867893 alert := TriggerCondition {
868894 TimeRange : block ["time_range" ].(string ),
869895 DetectionMethod : logsMissingDataConditionDetectionMethod ,
870- TriggerType : "MissingData" ,
871896 }
872897 resolution := TriggerCondition {
873898 TimeRange : block ["time_range" ].(string ),
@@ -886,6 +911,7 @@ func metricsMissingDataConditionBlockToJson(block map[string]interface{}) []Trig
886911 DetectionMethod : metricsMissingDataConditionDetectionMethod ,
887912 TriggerType : "MissingData" ,
888913 }
914+
889915 resolution := TriggerCondition {
890916 TimeRange : block ["time_range" ].(string ),
891917 TriggerSource : block ["trigger_source" ].(string ),
@@ -895,6 +921,22 @@ func metricsMissingDataConditionBlockToJson(block map[string]interface{}) []Trig
895921 return []TriggerCondition {alert , resolution }
896922}
897923
924+ func sloSLIConditionBlockToJson (block map [string ]interface {}) []TriggerCondition {
925+ base := TriggerCondition {
926+ DetectionMethod : sloSLIConditionDetectionMethod ,
927+ }
928+
929+ return base .sloCloneReadingFromNestedBlocks (block )
930+ }
931+
932+ func sloBurnConditionBlockToJson (block map [string ]interface {}) []TriggerCondition {
933+ base := TriggerCondition {
934+ DetectionMethod : sloBurnRateConditionDetectionMethod ,
935+ }
936+
937+ return base .sloCloneReadingFromNestedBlocks (block )
938+ }
939+
898940// TriggerCondition JSON model to 'trigger_conditions' block
899941func jsonToTriggerConditionsBlock (conditions []TriggerCondition ) map [string ]interface {} {
900942 missingDataConditions := make ([]TriggerCondition , 0 )
@@ -917,6 +959,10 @@ func jsonToTriggerConditionsBlock(conditions []TriggerCondition) map[string]inte
917959 triggerConditionsBlock [logsOutlierConditionFieldName ] = toSingletonArray (jsonToLogsOutlierConditionBlock (dataConditions ))
918960 case metricsOutlierConditionDetectionMethod :
919961 triggerConditionsBlock [metricsOutlierConditionFieldName ] = toSingletonArray (jsonToMetricsOutlierConditionBlock (dataConditions ))
962+ case sloSLIConditionDetectionMethod :
963+ triggerConditionsBlock [sloSLIConditionFieldName ] = toSingletonArray (jsonToSloSliConditionBlock (dataConditions ))
964+ case sloBurnRateConditionDetectionMethod :
965+ triggerConditionsBlock [sloBurnRateConditionFieldName ] = toSingletonArray (jsonToSloBurnRateConditionBlock (dataConditions ))
920966 }
921967 }
922968 if len (missingDataConditions ) > 0 {
@@ -1112,6 +1158,63 @@ func jsonToMetricsOutlierConditionBlock(conditions []TriggerCondition) map[strin
11121158 return block
11131159}
11141160
1161+ func jsonToSloSliConditionBlock (conditions []TriggerCondition ) map [string ]interface {} {
1162+ var criticalAlrt , warningAlrt = dict {}, dict {}
1163+ block := map [string ]interface {}{}
1164+
1165+ block ["critical" ] = toSingletonArray (criticalAlrt )
1166+ block ["warning" ] = toSingletonArray (warningAlrt )
1167+
1168+ var hasCritical , hasWarning = false , false
1169+ for _ , condition := range conditions {
1170+ switch condition .TriggerType {
1171+ case "Critical" :
1172+ hasCritical = true
1173+ criticalAlrt ["sli_threshold" ] = condition .SLIThreshold
1174+ case "Warning" :
1175+ hasWarning = true
1176+ warningAlrt ["sli_threshold" ] = condition .SLIThreshold
1177+ }
1178+ }
1179+ if ! hasCritical {
1180+ delete (block , "critical" )
1181+ }
1182+ if ! hasWarning {
1183+ delete (block , "warning" )
1184+ }
1185+ return block
1186+ }
1187+
1188+ func jsonToSloBurnRateConditionBlock (conditions []TriggerCondition ) map [string ]interface {} {
1189+
1190+ var criticalAlrt , warningAlrt = dict {}, dict {}
1191+ block := map [string ]interface {}{}
1192+
1193+ block ["critical" ] = toSingletonArray (criticalAlrt )
1194+ block ["warning" ] = toSingletonArray (warningAlrt )
1195+
1196+ var hasCritical , hasWarning = false , false
1197+ for _ , condition := range conditions {
1198+ switch condition .TriggerType {
1199+ case "Critical" :
1200+ hasCritical = true
1201+ criticalAlrt ["time_range" ] = condition .TimeRange
1202+ criticalAlrt ["burn_rate_threshold" ] = condition .BurnRateThreshold
1203+ case "Warning" :
1204+ hasWarning = true
1205+ warningAlrt ["time_range" ] = condition .TimeRange
1206+ warningAlrt ["burn_rate_threshold" ] = condition .BurnRateThreshold
1207+ }
1208+ }
1209+ if ! hasCritical {
1210+ delete (block , "critical" )
1211+ }
1212+ if ! hasWarning {
1213+ delete (block , "warning" )
1214+ }
1215+ return block
1216+ }
1217+
11151218func jsonToLogsMissingDataConditionBlock (conditions []TriggerCondition ) map [string ]interface {} {
11161219 block := map [string ]interface {}{}
11171220 firstCondition := conditions [0 ]
@@ -1193,6 +1296,7 @@ func resourceToMonitorsLibraryMonitor(d *schema.ResourceData) MonitorsLibraryMon
11931296 GroupNotifications : d .Get ("group_notifications" ).(bool ),
11941297 Playbook : d .Get ("playbook" ).(string ),
11951298 AlertName : d .Get ("alert_name" ).(string ),
1299+ SloID : d .Get ("slo_id" ).(string ),
11961300 }
11971301}
11981302
@@ -1256,6 +1360,10 @@ func (condition *TriggerCondition) readFrom(block map[string]interface{}) {
12561360 condition .Consecutive = v .(int )
12571361 case "direction" :
12581362 condition .Direction = v .(string )
1363+ case "sli_threshold" :
1364+ condition .SLIThreshold = v .(float64 )
1365+ case "burn_rate_threshold" :
1366+ condition .BurnRateThreshold = v .(float64 )
12591367 default :
12601368 }
12611369 }
@@ -1313,6 +1421,24 @@ func (base TriggerCondition) cloneReadingFromNestedBlocks(block map[string]inter
13131421 return conditions
13141422}
13151423
1424+ // adapted version of cloneReadingFromNestedBlocks for slo conditions
1425+ func (base TriggerCondition ) sloCloneReadingFromNestedBlocks (block map [string ]interface {}) []TriggerCondition {
1426+ var conditions = []TriggerCondition {}
1427+ var criticalCondition , warningCondition = base , base
1428+ criticalCondition .TriggerType = "Critical"
1429+ warningCondition .TriggerType = "Warning"
1430+
1431+ if critical , ok := fromSingletonArray (block , "critical" ); ok {
1432+ criticalCondition .readFrom (critical )
1433+ conditions = append (conditions , criticalCondition )
1434+ }
1435+ if warning , ok := fromSingletonArray (block , "warning" ); ok {
1436+ warningCondition .readFrom (warning )
1437+ conditions = append (conditions , warningCondition )
1438+ }
1439+ return conditions
1440+ }
1441+
13161442func toSingletonArray (m map [string ]interface {}) []map [string ]interface {} {
13171443 return []map [string ]interface {}{m }
13181444}
0 commit comments