diff --git a/cfn-resources/alert-configuration/cmd/resource/model.go b/cfn-resources/alert-configuration/cmd/resource/model.go index 1c8e4efac..7a9a2615d 100644 --- a/cfn-resources/alert-configuration/cmd/resource/model.go +++ b/cfn-resources/alert-configuration/cmd/resource/model.go @@ -4,18 +4,19 @@ package resource // Model is autogenerated from the json schema type Model struct { - Id *string `json:",omitempty"` - Profile *string `json:",omitempty"` - Created *string `json:",omitempty"` - Enabled *bool `json:",omitempty"` - EventTypeName *string `json:",omitempty"` - ProjectId *string `json:",omitempty"` - Matchers []Matcher `json:",omitempty"` - MetricThreshold *MetricThresholdView `json:",omitempty"` - Notifications []NotificationView `json:",omitempty"` - Threshold *IntegerThresholdView `json:",omitempty"` - TypeName *string `json:",omitempty"` - Updated *string `json:",omitempty"` + Id *string `json:",omitempty"` + Profile *string `json:",omitempty"` + Created *string `json:",omitempty"` + Enabled *bool `json:",omitempty"` + EventTypeName *string `json:",omitempty"` + ProjectId *string `json:",omitempty"` + Matchers []Matcher `json:",omitempty"` + MetricThreshold *MetricThresholdView `json:",omitempty"` + Notifications []NotificationView `json:",omitempty"` + Threshold *IntegerThresholdView `json:",omitempty"` + TypeName *string `json:",omitempty"` + Updated *string `json:",omitempty"` + SeverityOverride *string `json:",omitempty"` } // Matcher is autogenerated from the json schema @@ -63,6 +64,8 @@ type NotificationView struct { VictorOpsRoutingKey *string `json:",omitempty"` WebhookSecret *string `json:",omitempty"` WebhookUrl *string `json:",omitempty"` + NotifierId *string `json:",omitempty"` + IntegrationId *string `json:",omitempty"` } // IntegerThresholdView is autogenerated from the json schema diff --git a/cfn-resources/alert-configuration/cmd/resource/resource.go b/cfn-resources/alert-configuration/cmd/resource/resource.go index c8e8bf691..8786de9e6 100644 --- a/cfn-resources/alert-configuration/cmd/resource/resource.go +++ b/cfn-resources/alert-configuration/cmd/resource/resource.go @@ -21,7 +21,7 @@ import ( "reflect" "strings" - admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" + "go.mongodb.org/atlas-sdk/v20250312012/admin" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" @@ -63,7 +63,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler if peErr != nil { return *peErr, nil } - atlasV2 := client.Atlas20231115014 + atlasV2 := client.AtlasSDK if currentModel.Id != nil && *currentModel.Id != "" { _, _ = logger.Warnf("resource already exists for Id: %s", *currentModel.Id) @@ -78,19 +78,20 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler return progressevents.GetFailedEventByCode(err.Error(), string(types.HandlerErrorCodeInvalidRequest)), err } - alertConfigRequest := admin20231115014.GroupAlertsConfig{ - GroupId: currentModel.ProjectId, - EventTypeName: currentModel.EventTypeName, - Enabled: currentModel.Enabled, - Matchers: expandAlertConfigurationMatchers(currentModel.Matchers), - MetricThreshold: expandAlertConfigurationMetricThresholdConfig(currentModel), - Threshold: expandAlertConfigurationThreshold(currentModel.Threshold), - Notifications: notifications, + alertConfigRequest := admin.GroupAlertsConfig{ + GroupId: currentModel.ProjectId, + EventTypeName: currentModel.EventTypeName, + Enabled: currentModel.Enabled, + Matchers: expandAlertConfigurationMatchers(currentModel.Matchers), + MetricThreshold: expandAlertConfigurationMetricThresholdConfig(currentModel), + Threshold: expandAlertConfigurationThreshold(currentModel.Threshold), + Notifications: notifications, + SeverityOverride: currentModel.SeverityOverride, } projectID := *currentModel.ProjectId var res *http.Response - alertConfig, res, err := atlasV2.AlertConfigurationsApi.CreateAlertConfiguration(context.Background(), projectID, &alertConfigRequest).Execute() + alertConfig, res, err := atlasV2.AlertConfigurationsApi.CreateAlertConfig(context.Background(), projectID, &alertConfigRequest).Execute() defer res.Body.Close() if err != nil { return progressevents.GetFailedEventByResponse(err.Error(), res), nil @@ -120,7 +121,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P if peErr != nil { return *peErr, nil } - atlasV2 := client.Atlas20231115014 + atlasV2 := client.AtlasSDK if !isExist(currentModel, atlasV2) { _, _ = logger.Warnf("resource not exist for Id: %s", *currentModel.Id) @@ -130,7 +131,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } - alertConfig, resp, err := atlasV2.AlertConfigurationsApi.GetAlertConfiguration(context.Background(), *currentModel.ProjectId, *currentModel.Id).Execute() + alertConfig, resp, err := atlasV2.AlertConfigurationsApi.GetAlertConfig(context.Background(), *currentModel.ProjectId, *currentModel.Id).Execute() defer resp.Body.Close() if err != nil { return progressevents.GetFailedEventByResponse(err.Error(), resp), nil @@ -160,7 +161,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler if peErr != nil { return *peErr, nil } - atlasV2 := client.Atlas20231115014 + atlasV2 := client.AtlasSDK if !isExist(currentModel, atlasV2) { _, _ = logger.Warnf("resource not exist for Id: %s", *currentModel.Id) @@ -174,7 +175,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler // server returns an error 500 projectID := *currentModel.ProjectId id := *currentModel.Id - alertReq, res, err := atlasV2.AlertConfigurationsApi.GetAlertConfiguration(context.Background(), projectID, id).Execute() + alertReq, res, err := atlasV2.AlertConfigurationsApi.GetAlertConfig(context.Background(), projectID, id).Execute() if err != nil { return progressevents.GetFailedEventByResponse(err.Error(), res), nil } @@ -184,15 +185,15 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler // Removing the computed attributes to recreate the original request alertReq.Created = nil alertReq.Updated = nil - var alertModel *admin20231115014.GroupAlertsConfig + var alertModel *admin.GroupAlertsConfig // Cannot enable/disable ONLY via update (if only send enable as changed field server returns a 500 error) // so have to use different method to change enabled. - if reflect.DeepEqual(alertReq, &admin20231115014.GroupAlertsConfig{Enabled: aws.Bool(true)}) || - reflect.DeepEqual(alertReq, &admin20231115014.GroupAlertsConfig{Enabled: aws.Bool(false)}) { - alertModel, res, err = atlasV2.AlertConfigurationsApi.ToggleAlertConfiguration(context.Background(), projectID, id, &admin20231115014.AlertsToggle{Enabled: alertReq.Enabled}).Execute() + if reflect.DeepEqual(alertReq, &admin.GroupAlertsConfig{Enabled: aws.Bool(true)}) || + reflect.DeepEqual(alertReq, &admin.GroupAlertsConfig{Enabled: aws.Bool(false)}) { + alertModel, res, err = atlasV2.AlertConfigurationsApi.ToggleAlertConfig(context.Background(), projectID, id, &admin.AlertsToggle{Enabled: alertReq.Enabled}).Execute() } else { - alertModel, res, err = atlasV2.AlertConfigurationsApi.UpdateAlertConfiguration(context.Background(), projectID, id, alertReq).Execute() + alertModel, res, err = atlasV2.AlertConfigurationsApi.UpdateAlertConfig(context.Background(), projectID, id, alertReq).Execute() } if err != nil { @@ -224,7 +225,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler if peErr != nil { return *peErr, nil } - atlasV2 := client.Atlas20231115014 + atlasV2 := client.AtlasSDK if !isExist(currentModel, atlasV2) { _, _ = logger.Warnf("resource not exist for Id: %s", *currentModel.Id) @@ -234,7 +235,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } - res, err := atlasV2.AlertConfigurationsApi.DeleteAlertConfiguration(context.Background(), *currentModel.ProjectId, *currentModel.Id).Execute() + res, err := atlasV2.AlertConfigurationsApi.DeleteAlertConfig(context.Background(), *currentModel.ProjectId, *currentModel.Id).Execute() if err != nil { _, _ = logger.Warnf("Delete - error: %+v", err) @@ -253,15 +254,15 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } -func isExist(currentModel *Model, client *admin20231115014.APIClient) bool { - alert, _, err := client.AlertConfigurationsApi.GetAlertConfiguration(context.Background(), *currentModel.ProjectId, *currentModel.Id).Execute() +func isExist(currentModel *Model, client *admin.APIClient) bool { + alert, _, err := client.AlertConfigurationsApi.GetAlertConfig(context.Background(), *currentModel.ProjectId, *currentModel.Id).Execute() return err == nil && alert != nil } -func expandAlertConfigurationMatchers(matchers []Matcher) *[]admin20231115014.StreamsMatcher { - mts := make([]admin20231115014.StreamsMatcher, 0) +func expandAlertConfigurationMatchers(matchers []Matcher) *[]admin.StreamsMatcher { + mts := make([]admin.StreamsMatcher, 0) for ind := range matchers { - mMatcher := admin20231115014.NewStreamsMatcher( + mMatcher := admin.NewStreamsMatcher( cast.ToString(matchers[ind].FieldName), cast.ToString(matchers[ind].Operator), cast.ToString(matchers[ind].Value), @@ -271,12 +272,12 @@ func expandAlertConfigurationMatchers(matchers []Matcher) *[]admin20231115014.St return &mts } -func expandAlertConfigurationMetricThresholdConfig(currentModel *Model) *admin20231115014.ServerlessMetricThreshold { +func expandAlertConfigurationMetricThresholdConfig(currentModel *Model) *admin.FlexClusterMetricThreshold { threshold := currentModel.MetricThreshold if threshold == nil { return nil } - return &admin20231115014.ServerlessMetricThreshold{ + return &admin.FlexClusterMetricThreshold{ MetricName: cast.ToString(threshold.MetricName), Operator: threshold.Operator, Threshold: threshold.Threshold, @@ -285,19 +286,19 @@ func expandAlertConfigurationMetricThresholdConfig(currentModel *Model) *admin20 } } -func expandAlertConfigurationThreshold(threshold *IntegerThresholdView) *admin20231115014.GreaterThanRawThreshold { +func expandAlertConfigurationThreshold(threshold *IntegerThresholdView) *admin.StreamProcessorMetricThreshold { if threshold == nil { return nil } - return &admin20231115014.GreaterThanRawThreshold{ + return &admin.StreamProcessorMetricThreshold{ Operator: threshold.Operator, - Threshold: util.Pointer(int(*threshold.Threshold)), + Threshold: threshold.Threshold, Units: threshold.Units, } } -func expandAlertConfigurationNotification(notificationList []NotificationView) (*[]admin20231115014.AlertsNotificationRootForGroup, error) { - notifications := make([]admin20231115014.AlertsNotificationRootForGroup, 0) +func expandAlertConfigurationNotification(notificationList []NotificationView) (*[]admin.AlertsNotificationRootForGroup, error) { + notifications := make([]admin.AlertsNotificationRootForGroup, 0) for ind := range notificationList { if notificationList[ind].IntervalMin != nil && *notificationList[ind].IntervalMin > cast.ToFloat64(0) { @@ -309,7 +310,7 @@ func expandAlertConfigurationNotification(notificationList []NotificationView) ( } for ind := range notificationList { - notification := admin20231115014.AlertsNotificationRootForGroup{ + notification := admin.AlertsNotificationRootForGroup{ ApiToken: notificationList[ind].ApiToken, ChannelName: notificationList[ind].ChannelName, DatadogApiKey: notificationList[ind].DatadogApiKey, @@ -330,15 +331,17 @@ func expandAlertConfigurationNotification(notificationList []NotificationView) ( VictorOpsRoutingKey: notificationList[ind].VictorOpsRoutingKey, Roles: ¬ificationList[ind].Roles, DelayMin: notificationList[ind].DelayMin, + NotifierId: notificationList[ind].NotifierId, + IntegrationId: notificationList[ind].IntegrationId, } notifications = append(notifications, notification) } return ¬ifications, nil } -func convertToMongoModel(reqModel *admin20231115014.GroupAlertsConfig, currentModel *Model) *admin20231115014.GroupAlertsConfig { +func convertToMongoModel(reqModel *admin.GroupAlertsConfig, currentModel *Model) *admin.GroupAlertsConfig { if reqModel == nil { - reqModel = &admin20231115014.GroupAlertsConfig{} + reqModel = &admin.GroupAlertsConfig{} } // Only change the updated fields @@ -360,10 +363,13 @@ func convertToMongoModel(reqModel *admin20231115014.GroupAlertsConfig, currentMo if currentModel.Notifications != nil { reqModel.Notifications, _ = expandAlertConfigurationNotification(currentModel.Notifications) } + if currentModel.SeverityOverride != nil { + reqModel.SeverityOverride = currentModel.SeverityOverride + } return reqModel } -func convertToUIModel(alertConfig *admin20231115014.GroupAlertsConfig, currentModel *Model) *Model { +func convertToUIModel(alertConfig *admin.GroupAlertsConfig, currentModel *Model) *Model { currentModel.Id = alertConfig.Id if alertConfig.Created != nil { currentModel.Created = util.TimePtrToStringPtr(alertConfig.Created) @@ -377,5 +383,9 @@ func convertToUIModel(alertConfig *admin20231115014.GroupAlertsConfig, currentMo currentModel.Enabled = alertConfig.Enabled } + if alertConfig.SeverityOverride != nil { + currentModel.SeverityOverride = alertConfig.SeverityOverride + } + return currentModel } diff --git a/cfn-resources/alert-configuration/docs/README.md b/cfn-resources/alert-configuration/docs/README.md index 03750f832..0192afc93 100644 --- a/cfn-resources/alert-configuration/docs/README.md +++ b/cfn-resources/alert-configuration/docs/README.md @@ -20,6 +20,7 @@ To declare this entity in your AWS CloudFormation template, use the following sy "Notifications" : [ NotificationView, ... ], "Threshold" : IntegerThresholdView, "TypeName" : String, + "SeverityOverride" : String } } @@ -39,6 +40,7 @@ Properties: - NotificationView Threshold: IntegerThresholdView TypeName: String + SeverityOverride: String ## Properties @@ -125,6 +127,16 @@ _Type_: String _Update requires_: [Replacement](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-replacement) +#### SeverityOverride + +Degree of seriousness given to this alert. This value overrides the default severity level for the alert. + +_Required_: No + +_Type_: String + +_Update requires_: [Replacement](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-replacement) + ## Return Values ### Fn::GetAtt diff --git a/cfn-resources/alert-configuration/docs/notificationview.md b/cfn-resources/alert-configuration/docs/notificationview.md index 538adfc3b..fbb42afb9 100644 --- a/cfn-resources/alert-configuration/docs/notificationview.md +++ b/cfn-resources/alert-configuration/docs/notificationview.md @@ -34,7 +34,9 @@ To declare this entity in your AWS CloudFormation template, use the following sy "VictorOpsApiKey" : String, "VictorOpsRoutingKey" : String, "WebhookSecret" : String, - "WebhookUrl" : String + "WebhookUrl" : String, + "NotifierId" : String, + "IntegrationId" : String } @@ -69,6 +71,8 @@ To declare this entity in your AWS CloudFormation template, use the following sy VictorOpsRoutingKey: String WebhookSecret: String WebhookUrl: String +NotifierId: String +IntegrationId: String ## Properties @@ -390,3 +394,35 @@ _Type_: String _Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) +#### NotifierId + +Unique 24-hexadecimal digit string that identifies the notifier to use for this alert configuration. + +_Required_: No + +_Type_: String + +_Minimum Length_: 24 + +_Maximum Length_: 24 + +_Pattern_: ^([a-f0-9]{24})$ + +_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) + +#### IntegrationId + +Unique 24-hexadecimal digit string that identifies the third party integration to use for this alert configuration. + +_Required_: No + +_Type_: String + +_Minimum Length_: 24 + +_Maximum Length_: 24 + +_Pattern_: ^([a-f0-9]{24})$ + +_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) + diff --git a/cfn-resources/alert-configuration/mongodb-atlas-alertconfiguration.json b/cfn-resources/alert-configuration/mongodb-atlas-alertconfiguration.json index 81f58fa4e..1b8d95f54 100644 --- a/cfn-resources/alert-configuration/mongodb-atlas-alertconfiguration.json +++ b/cfn-resources/alert-configuration/mongodb-atlas-alertconfiguration.json @@ -453,6 +453,20 @@ "WebhookUrl": { "type": "string", "description": "Your webhook URL." + }, + "NotifierId": { + "type": "string", + "description": "Unique 24-hexadecimal digit string that identifies the notifier to use for this alert configuration.", + "maxLength": 24, + "minLength": 24, + "pattern": "^([a-f0-9]{24})$" + }, + "IntegrationId": { + "type": "string", + "description": "Unique 24-hexadecimal digit string that identifies the third party integration to use for this alert configuration.", + "maxLength": 24, + "minLength": 24, + "pattern": "^([a-f0-9]{24})$" } }, "additionalProperties": false @@ -552,6 +566,10 @@ "type": "string", "description": "Date and time when someone last updated this alert configuration. This parameter expresses its value in the ISO 8601 timestamp format in UTC.", "pattern": "^(?:[1-9]\\d{3}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1\\d|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[1-9]\\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00)-02-29)T(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d{1,9})?(?:Z)$" + }, + "SeverityOverride": { + "type": "string", + "description": "Degree of seriousness given to this alert. This value overrides the default severity level for the alert." } }, "readOnlyProperties": [ @@ -568,7 +586,8 @@ "/properties/Notifications", "/properties/MetricThreshold", "/properties/Threshold", - "/properties/TypeName" + "/properties/TypeName", + "/properties/SeverityOverride" ], "primaryIdentifier": [ "/properties/ProjectId", diff --git a/cfn-resources/alert-configuration/test/alert-configuration.sample-cfn-request.json b/cfn-resources/alert-configuration/test/alert-configuration.sample-cfn-request.json index 72230f88f..80153ccac 100644 --- a/cfn-resources/alert-configuration/test/alert-configuration.sample-cfn-request.json +++ b/cfn-resources/alert-configuration/test/alert-configuration.sample-cfn-request.json @@ -4,6 +4,7 @@ "ProjectId": "", "Enabled": true, "EventTypeName": "OUTSIDE_METRIC_THRESHOLD", + "SeverityOverride": "WARNING", "MetricThreshold": { "MetricName": "NORMALIZED_SYSTEM_CPU_USER", "Operator": "GREATER_THAN", diff --git a/cfn-resources/alert-configuration/test/inputs_1_create.template.json b/cfn-resources/alert-configuration/test/inputs_1_create.template.json index 09b1c74fd..d9009d697 100644 --- a/cfn-resources/alert-configuration/test/inputs_1_create.template.json +++ b/cfn-resources/alert-configuration/test/inputs_1_create.template.json @@ -3,6 +3,7 @@ "ProjectId": "", "Enabled": true, "EventTypeName": "OUTSIDE_METRIC_THRESHOLD", + "SeverityOverride": "WARNING", "MetricThreshold": { "MetricName": "NORMALIZED_SYSTEM_CPU_USER", "Operator": "GREATER_THAN", diff --git a/cfn-resources/alert-configuration/test/inputs_1_update.template.json b/cfn-resources/alert-configuration/test/inputs_1_update.template.json index 09b1c74fd..d9009d697 100644 --- a/cfn-resources/alert-configuration/test/inputs_1_update.template.json +++ b/cfn-resources/alert-configuration/test/inputs_1_update.template.json @@ -3,6 +3,7 @@ "ProjectId": "", "Enabled": true, "EventTypeName": "OUTSIDE_METRIC_THRESHOLD", + "SeverityOverride": "WARNING", "MetricThreshold": { "MetricName": "NORMALIZED_SYSTEM_CPU_USER", "Operator": "GREATER_THAN", diff --git a/examples/alert-configuration/alert-configuration-email.json b/examples/alert-configuration/alert-configuration-email.json index 430d35eb4..b6f524894 100644 --- a/examples/alert-configuration/alert-configuration-email.json +++ b/examples/alert-configuration/alert-configuration-email.json @@ -24,6 +24,12 @@ "Description": "", "Default": "true", "ConstraintDescription": "" + }, + "SeverityOverride": { + "Type": "String", + "Description": "Override the default severity level for this alert", + "Default": "WARNING", + "AllowedValues": ["CRITICAL", "ERROR", "WARNING"] } }, "Mappings": {}, @@ -41,6 +47,9 @@ "Ref": "Enabled" }, "EventTypeName": "OUTSIDE_METRIC_THRESHOLD", + "SeverityOverride": { + "Ref": "SeverityOverride" + }, "Notifications": [ { "TypeName": "EMAIL", @@ -78,26 +87,17 @@ }, "Id": { "Value": { - "Fn::GetAtt": [ - "AlertConfiguration", - "Id" - ] + "Fn::GetAtt": ["AlertConfiguration", "Id"] } }, "Created": { "Value": { - "Fn::GetAtt": [ - "AlertConfiguration", - "Created" - ] + "Fn::GetAtt": ["AlertConfiguration", "Created"] } }, "Enabled": { "Value": { - "Fn::GetAtt": [ - "AlertConfiguration", - "Enabled" - ] + "Fn::GetAtt": ["AlertConfiguration", "Enabled"] } } }