api_op_PutAlarm.go raw

   1  // Code generated by smithy-go-codegen DO NOT EDIT.
   2  
   3  package lightsail
   4  
   5  import (
   6  	"context"
   7  	"fmt"
   8  	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
   9  	"github.com/aws/aws-sdk-go-v2/service/lightsail/types"
  10  	"github.com/aws/smithy-go/middleware"
  11  	smithyhttp "github.com/aws/smithy-go/transport/http"
  12  )
  13  
  14  // Creates or updates an alarm, and associates it with the specified metric.
  15  //
  16  // An alarm is used to monitor a single metric for one of your resources. When a
  17  // metric condition is met, the alarm can notify you by email, SMS text message,
  18  // and a banner displayed on the Amazon Lightsail console. For more information,
  19  // see [Alarms in Amazon Lightsail].
  20  //
  21  // When this action creates an alarm, the alarm state is immediately set to
  22  // INSUFFICIENT_DATA . The alarm is then evaluated and its state is set
  23  // appropriately. Any actions associated with the new state are then executed.
  24  //
  25  // When you update an existing alarm, its state is left unchanged, but the update
  26  // completely overwrites the previous configuration of the alarm. The alarm is then
  27  // evaluated with the updated configuration.
  28  //
  29  // [Alarms in Amazon Lightsail]: https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-alarms
  30  func (c *Client) PutAlarm(ctx context.Context, params *PutAlarmInput, optFns ...func(*Options)) (*PutAlarmOutput, error) {
  31  	if params == nil {
  32  		params = &PutAlarmInput{}
  33  	}
  34  
  35  	result, metadata, err := c.invokeOperation(ctx, "PutAlarm", params, optFns, c.addOperationPutAlarmMiddlewares)
  36  	if err != nil {
  37  		return nil, err
  38  	}
  39  
  40  	out := result.(*PutAlarmOutput)
  41  	out.ResultMetadata = metadata
  42  	return out, nil
  43  }
  44  
  45  type PutAlarmInput struct {
  46  
  47  	// The name for the alarm. Specify the name of an existing alarm to update, and
  48  	// overwrite the previous configuration of the alarm.
  49  	//
  50  	// This member is required.
  51  	AlarmName *string
  52  
  53  	// The arithmetic operation to use when comparing the specified statistic to the
  54  	// threshold. The specified statistic value is used as the first operand.
  55  	//
  56  	// This member is required.
  57  	ComparisonOperator types.ComparisonOperator
  58  
  59  	// The number of most recent periods over which data is compared to the specified
  60  	// threshold. If you are setting an "M out of N" alarm, this value (
  61  	// evaluationPeriods ) is the N.
  62  	//
  63  	// If you are setting an alarm that requires that a number of consecutive data
  64  	// points be breaching to trigger the alarm, this value specifies the rolling
  65  	// period of time in which data points are evaluated.
  66  	//
  67  	// Each evaluation period is five minutes long. For example, specify an evaluation
  68  	// period of 24 to evaluate a metric over a rolling period of two hours.
  69  	//
  70  	// You can specify a minimum valuation period of 1 (5 minutes), and a maximum
  71  	// evaluation period of 288 (24 hours).
  72  	//
  73  	// This member is required.
  74  	EvaluationPeriods *int32
  75  
  76  	// The name of the metric to associate with the alarm.
  77  	//
  78  	// You can configure up to two alarms per metric.
  79  	//
  80  	// The following metrics are available for each resource type:
  81  	//
  82  	//   - Instances: BurstCapacityPercentage , BurstCapacityTime , CPUUtilization ,
  83  	//   NetworkIn , NetworkOut , StatusCheckFailed , StatusCheckFailed_Instance , and
  84  	//   StatusCheckFailed_System .
  85  	//
  86  	//   - Load balancers: ClientTLSNegotiationErrorCount , HealthyHostCount ,
  87  	//   UnhealthyHostCount , HTTPCode_LB_4XX_Count , HTTPCode_LB_5XX_Count ,
  88  	//   HTTPCode_Instance_2XX_Count , HTTPCode_Instance_3XX_Count ,
  89  	//   HTTPCode_Instance_4XX_Count , HTTPCode_Instance_5XX_Count ,
  90  	//   InstanceResponseTime , RejectedConnectionCount , and RequestCount .
  91  	//
  92  	//   - Relational databases: CPUUtilization , DatabaseConnections , DiskQueueDepth
  93  	//   , FreeStorageSpace , NetworkReceiveThroughput , and NetworkTransmitThroughput .
  94  	//
  95  	// For more information about these metrics, see [Metrics available in Lightsail].
  96  	//
  97  	// [Metrics available in Lightsail]: https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-resource-health-metrics#available-metrics
  98  	//
  99  	// This member is required.
 100  	MetricName types.MetricName
 101  
 102  	// The name of the Lightsail resource that will be monitored.
 103  	//
 104  	// Instances, load balancers, and relational databases are the only Lightsail
 105  	// resources that can currently be monitored by alarms.
 106  	//
 107  	// This member is required.
 108  	MonitoredResourceName *string
 109  
 110  	// The value against which the specified statistic is compared.
 111  	//
 112  	// This member is required.
 113  	Threshold *float64
 114  
 115  	// The contact protocols to use for the alarm, such as Email , SMS (text
 116  	// messaging), or both.
 117  	//
 118  	// A notification is sent via the specified contact protocol if notifications are
 119  	// enabled for the alarm, and when the alarm is triggered.
 120  	//
 121  	// A notification is not sent if a contact protocol is not specified, if the
 122  	// specified contact protocol is not configured in the Amazon Web Services Region,
 123  	// or if notifications are not enabled for the alarm using the notificationEnabled
 124  	// paramater.
 125  	//
 126  	// Use the CreateContactMethod action to configure a contact protocol in an Amazon
 127  	// Web Services Region.
 128  	ContactProtocols []types.ContactProtocol
 129  
 130  	// The number of data points that must be not within the specified threshold to
 131  	// trigger the alarm. If you are setting an "M out of N" alarm, this value (
 132  	// datapointsToAlarm ) is the M.
 133  	DatapointsToAlarm *int32
 134  
 135  	// Indicates whether the alarm is enabled.
 136  	//
 137  	// Notifications are enabled by default if you don't specify this parameter.
 138  	NotificationEnabled *bool
 139  
 140  	// The alarm states that trigger a notification.
 141  	//
 142  	// An alarm has the following possible states:
 143  	//
 144  	//   - ALARM - The metric is outside of the defined threshold.
 145  	//
 146  	//   - INSUFFICIENT_DATA - The alarm has just started, the metric is not available,
 147  	//   or not enough data is available for the metric to determine the alarm state.
 148  	//
 149  	//   - OK - The metric is within the defined threshold.
 150  	//
 151  	// When you specify a notification trigger, the ALARM state must be specified. The
 152  	// INSUFFICIENT_DATA and OK states can be specified in addition to the ALARM state.
 153  	//
 154  	//   - If you specify OK as an alarm trigger, a notification is sent when the alarm
 155  	//   switches from an ALARM or INSUFFICIENT_DATA alarm state to an OK state. This
 156  	//   can be thought of as an all clear alarm notification.
 157  	//
 158  	//   - If you specify INSUFFICIENT_DATA as the alarm trigger, a notification is
 159  	//   sent when the alarm switches from an OK or ALARM alarm state to an
 160  	//   INSUFFICIENT_DATA state.
 161  	//
 162  	// The notification trigger defaults to ALARM if you don't specify this parameter.
 163  	NotificationTriggers []types.AlarmState
 164  
 165  	// Sets how this alarm will handle missing data points.
 166  	//
 167  	// An alarm can treat missing data in the following ways:
 168  	//
 169  	//   - breaching - Assume the missing data is not within the threshold. Missing
 170  	//   data counts towards the number of times the metric is not within the threshold.
 171  	//
 172  	//   - notBreaching - Assume the missing data is within the threshold. Missing data
 173  	//   does not count towards the number of times the metric is not within the
 174  	//   threshold.
 175  	//
 176  	//   - ignore - Ignore the missing data. Maintains the current alarm state.
 177  	//
 178  	//   - missing - Missing data is treated as missing.
 179  	//
 180  	// If treatMissingData is not specified, the default behavior of missing is used.
 181  	TreatMissingData types.TreatMissingData
 182  
 183  	noSmithyDocumentSerde
 184  }
 185  
 186  type PutAlarmOutput struct {
 187  
 188  	// An array of objects that describe the result of the action, such as the status
 189  	// of the request, the timestamp of the request, and the resources affected by the
 190  	// request.
 191  	Operations []types.Operation
 192  
 193  	// Metadata pertaining to the operation's result.
 194  	ResultMetadata middleware.Metadata
 195  
 196  	noSmithyDocumentSerde
 197  }
 198  
 199  func (c *Client) addOperationPutAlarmMiddlewares(stack *middleware.Stack, options Options) (err error) {
 200  	if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
 201  		return err
 202  	}
 203  	err = stack.Serialize.Add(&awsAwsjson11_serializeOpPutAlarm{}, middleware.After)
 204  	if err != nil {
 205  		return err
 206  	}
 207  	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpPutAlarm{}, middleware.After)
 208  	if err != nil {
 209  		return err
 210  	}
 211  	if err := addProtocolFinalizerMiddlewares(stack, options, "PutAlarm"); err != nil {
 212  		return fmt.Errorf("add protocol finalizers: %v", err)
 213  	}
 214  
 215  	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
 216  		return err
 217  	}
 218  	if err = addSetLoggerMiddleware(stack, options); err != nil {
 219  		return err
 220  	}
 221  	if err = addClientRequestID(stack); err != nil {
 222  		return err
 223  	}
 224  	if err = addComputeContentLength(stack); err != nil {
 225  		return err
 226  	}
 227  	if err = addResolveEndpointMiddleware(stack, options); err != nil {
 228  		return err
 229  	}
 230  	if err = addComputePayloadSHA256(stack); err != nil {
 231  		return err
 232  	}
 233  	if err = addRetry(stack, options); err != nil {
 234  		return err
 235  	}
 236  	if err = addRawResponseToMetadata(stack); err != nil {
 237  		return err
 238  	}
 239  	if err = addRecordResponseTiming(stack); err != nil {
 240  		return err
 241  	}
 242  	if err = addSpanRetryLoop(stack, options); err != nil {
 243  		return err
 244  	}
 245  	if err = addClientUserAgent(stack, options); err != nil {
 246  		return err
 247  	}
 248  	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
 249  		return err
 250  	}
 251  	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
 252  		return err
 253  	}
 254  	if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
 255  		return err
 256  	}
 257  	if err = addTimeOffsetBuild(stack, c); err != nil {
 258  		return err
 259  	}
 260  	if err = addUserAgentRetryMode(stack, options); err != nil {
 261  		return err
 262  	}
 263  	if err = addCredentialSource(stack, options); err != nil {
 264  		return err
 265  	}
 266  	if err = addOpPutAlarmValidationMiddleware(stack); err != nil {
 267  		return err
 268  	}
 269  	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPutAlarm(options.Region), middleware.Before); err != nil {
 270  		return err
 271  	}
 272  	if err = addRecursionDetection(stack); err != nil {
 273  		return err
 274  	}
 275  	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
 276  		return err
 277  	}
 278  	if err = addResponseErrorMiddleware(stack); err != nil {
 279  		return err
 280  	}
 281  	if err = addRequestResponseLogging(stack, options); err != nil {
 282  		return err
 283  	}
 284  	if err = addDisableHTTPSMiddleware(stack, options); err != nil {
 285  		return err
 286  	}
 287  	if err = addInterceptBeforeRetryLoop(stack, options); err != nil {
 288  		return err
 289  	}
 290  	if err = addInterceptAttempt(stack, options); err != nil {
 291  		return err
 292  	}
 293  	if err = addInterceptors(stack, options); err != nil {
 294  		return err
 295  	}
 296  	return nil
 297  }
 298  
 299  func newServiceMetadataMiddleware_opPutAlarm(region string) *awsmiddleware.RegisterServiceMetadata {
 300  	return &awsmiddleware.RegisterServiceMetadata{
 301  		Region:        region,
 302  		ServiceID:     ServiceID,
 303  		OperationName: "PutAlarm",
 304  	}
 305  }
 306