1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package cloudwatch 4 5import ( 6 "context" 7 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 8 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 9 "github.com/aws/aws-sdk-go-v2/service/cloudwatch/types" 10 "github.com/aws/smithy-go/middleware" 11 smithyhttp "github.com/aws/smithy-go/transport/http" 12) 13 14// Creates or updates a composite alarm. When you create a composite alarm, you 15// specify a rule expression for the alarm that takes into account the alarm states 16// of other alarms that you have created. The composite alarm goes into ALARM state 17// only if all conditions of the rule are met. The alarms specified in a composite 18// alarm's rule expression can include metric alarms and other composite alarms. 19// Using composite alarms can reduce alarm noise. You can create multiple metric 20// alarms, and also create a composite alarm and set up alerts only for the 21// composite alarm. For example, you could create a composite alarm that goes into 22// ALARM state only when more than one of the underlying metric alarms are in ALARM 23// state. Currently, the only alarm actions that can be taken by composite alarms 24// are notifying SNS topics. It is possible to create a loop or cycle of composite 25// alarms, where composite alarm A depends on composite alarm B, and composite 26// alarm B also depends on composite alarm A. In this scenario, you can't delete 27// any composite alarm that is part of the cycle because there is always still a 28// composite alarm that depends on that alarm that you want to delete. To get out 29// of such a situation, you must break the cycle by changing the rule of one of the 30// composite alarms in the cycle to remove a dependency that creates the cycle. The 31// simplest change to make to break a cycle is to change the AlarmRule of one of 32// the alarms to False. Additionally, the evaluation of composite alarms stops if 33// CloudWatch detects a cycle in the evaluation path. When this operation creates 34// an alarm, the alarm state is immediately set to INSUFFICIENT_DATA. The alarm is 35// then evaluated and its state is set appropriately. Any actions associated with 36// the new state are then executed. For a composite alarm, this initial time after 37// creation is the only time that the alarm can be in INSUFFICIENT_DATA state. When 38// you update an existing alarm, its state is left unchanged, but the update 39// completely overwrites the previous configuration of the alarm. If you are an IAM 40// user, you must have iam:CreateServiceLinkedRole to create a composite alarm that 41// has Systems Manager OpsItem actions. 42func (c *Client) PutCompositeAlarm(ctx context.Context, params *PutCompositeAlarmInput, optFns ...func(*Options)) (*PutCompositeAlarmOutput, error) { 43 if params == nil { 44 params = &PutCompositeAlarmInput{} 45 } 46 47 result, metadata, err := c.invokeOperation(ctx, "PutCompositeAlarm", params, optFns, addOperationPutCompositeAlarmMiddlewares) 48 if err != nil { 49 return nil, err 50 } 51 52 out := result.(*PutCompositeAlarmOutput) 53 out.ResultMetadata = metadata 54 return out, nil 55} 56 57type PutCompositeAlarmInput struct { 58 59 // The name for the composite alarm. This name must be unique within the Region. 60 // 61 // This member is required. 62 AlarmName *string 63 64 // An expression that specifies which other alarms are to be evaluated to determine 65 // this composite alarm's state. For each alarm that you reference, you designate a 66 // function that specifies whether that alarm needs to be in ALARM state, OK state, 67 // or INSUFFICIENT_DATA state. You can use operators (AND, OR and NOT) to combine 68 // multiple functions in a single expression. You can use parenthesis to logically 69 // group the functions in your expression. You can use either alarm names or ARNs 70 // to reference the other alarms that are to be evaluated. Functions can include 71 // the following: 72 // 73 // * ALARM("alarm-name or alarm-ARN") is TRUE if the named alarm is 74 // in ALARM state. 75 // 76 // * OK("alarm-name or alarm-ARN") is TRUE if the named alarm is 77 // in OK state. 78 // 79 // * INSUFFICIENT_DATA("alarm-name or alarm-ARN") is TRUE if the 80 // named alarm is in INSUFFICIENT_DATA state. 81 // 82 // * TRUE always evaluates to TRUE. 83 // 84 // * 85 // FALSE always evaluates to FALSE. 86 // 87 // TRUE and FALSE are useful for testing a 88 // complex AlarmRule structure, and for testing your alarm actions. Alarm names 89 // specified in AlarmRule can be surrounded with double-quotes ("), but do not have 90 // to be. The following are some examples of AlarmRule: 91 // 92 // * 93 // ALARM(CPUUtilizationTooHigh) AND ALARM(DiskReadOpsTooHigh) specifies that the 94 // composite alarm goes into ALARM state only if both CPUUtilizationTooHigh and 95 // DiskReadOpsTooHigh alarms are in ALARM state. 96 // 97 // * ALARM(CPUUtilizationTooHigh) 98 // AND NOT ALARM(DeploymentInProgress) specifies that the alarm goes to ALARM state 99 // if CPUUtilizationTooHigh is in ALARM state and DeploymentInProgress is not in 100 // ALARM state. This example reduces alarm noise during a known deployment 101 // window. 102 // 103 // * (ALARM(CPUUtilizationTooHigh) OR ALARM(DiskReadOpsTooHigh)) AND 104 // OK(NetworkOutTooHigh) goes into ALARM state if CPUUtilizationTooHigh OR 105 // DiskReadOpsTooHigh is in ALARM state, and if NetworkOutTooHigh is in OK state. 106 // This provides another example of using a composite alarm to prevent noise. This 107 // rule ensures that you are not notified with an alarm action on high CPU or disk 108 // usage if a known network problem is also occurring. 109 // 110 // The AlarmRule can specify 111 // as many as 100 "children" alarms. The AlarmRule expression can have as many as 112 // 500 elements. Elements are child alarms, TRUE or FALSE statements, and 113 // parentheses. 114 // 115 // This member is required. 116 AlarmRule *string 117 118 // Indicates whether actions should be executed during any changes to the alarm 119 // state of the composite alarm. The default is TRUE. 120 ActionsEnabled *bool 121 122 // The actions to execute when this alarm transitions to the ALARM state from any 123 // other state. Each action is specified as an Amazon Resource Name (ARN). Valid 124 // Values: arn:aws:sns:region:account-id:sns-topic-name | 125 // arn:aws:ssm:region:account-id:opsitem:severity 126 AlarmActions []string 127 128 // The description for the composite alarm. 129 AlarmDescription *string 130 131 // The actions to execute when this alarm transitions to the INSUFFICIENT_DATA 132 // state from any other state. Each action is specified as an Amazon Resource Name 133 // (ARN). Valid Values: arn:aws:sns:region:account-id:sns-topic-name 134 InsufficientDataActions []string 135 136 // The actions to execute when this alarm transitions to an OK state from any other 137 // state. Each action is specified as an Amazon Resource Name (ARN). Valid Values: 138 // arn:aws:sns:region:account-id:sns-topic-name 139 OKActions []string 140 141 // A list of key-value pairs to associate with the composite alarm. You can 142 // associate as many as 50 tags with an alarm. Tags can help you organize and 143 // categorize your resources. You can also use them to scope user permissions, by 144 // granting a user permission to access or change only resources with certain tag 145 // values. 146 Tags []types.Tag 147} 148 149type PutCompositeAlarmOutput struct { 150 // Metadata pertaining to the operation's result. 151 ResultMetadata middleware.Metadata 152} 153 154func addOperationPutCompositeAlarmMiddlewares(stack *middleware.Stack, options Options) (err error) { 155 err = stack.Serialize.Add(&awsAwsquery_serializeOpPutCompositeAlarm{}, middleware.After) 156 if err != nil { 157 return err 158 } 159 err = stack.Deserialize.Add(&awsAwsquery_deserializeOpPutCompositeAlarm{}, middleware.After) 160 if err != nil { 161 return err 162 } 163 if err = addSetLoggerMiddleware(stack, options); err != nil { 164 return err 165 } 166 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 167 return err 168 } 169 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 170 return err 171 } 172 if err = addResolveEndpointMiddleware(stack, options); err != nil { 173 return err 174 } 175 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 176 return err 177 } 178 if err = addRetryMiddlewares(stack, options); err != nil { 179 return err 180 } 181 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 182 return err 183 } 184 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 185 return err 186 } 187 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 188 return err 189 } 190 if err = addClientUserAgent(stack); err != nil { 191 return err 192 } 193 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 194 return err 195 } 196 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 197 return err 198 } 199 if err = addOpPutCompositeAlarmValidationMiddleware(stack); err != nil { 200 return err 201 } 202 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPutCompositeAlarm(options.Region), middleware.Before); err != nil { 203 return err 204 } 205 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 206 return err 207 } 208 if err = addResponseErrorMiddleware(stack); err != nil { 209 return err 210 } 211 if err = addRequestResponseLogging(stack, options); err != nil { 212 return err 213 } 214 return nil 215} 216 217func newServiceMetadataMiddleware_opPutCompositeAlarm(region string) *awsmiddleware.RegisterServiceMetadata { 218 return &awsmiddleware.RegisterServiceMetadata{ 219 Region: region, 220 ServiceID: ServiceID, 221 SigningName: "monitoring", 222 OperationName: "PutCompositeAlarm", 223 } 224} 225