1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package cloudwatch 4 5import ( 6 "context" 7 "fmt" 8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 9 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 10 "github.com/aws/aws-sdk-go-v2/service/cloudwatch/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13 "time" 14) 15 16// Retrieves the history for the specified alarm. You can filter the results by 17// date range or item type. If an alarm name is not specified, the histories for 18// either all metric alarms or all composite alarms are returned. CloudWatch 19// retains the history of an alarm even if you delete the alarm. 20func (c *Client) DescribeAlarmHistory(ctx context.Context, params *DescribeAlarmHistoryInput, optFns ...func(*Options)) (*DescribeAlarmHistoryOutput, error) { 21 if params == nil { 22 params = &DescribeAlarmHistoryInput{} 23 } 24 25 result, metadata, err := c.invokeOperation(ctx, "DescribeAlarmHistory", params, optFns, addOperationDescribeAlarmHistoryMiddlewares) 26 if err != nil { 27 return nil, err 28 } 29 30 out := result.(*DescribeAlarmHistoryOutput) 31 out.ResultMetadata = metadata 32 return out, nil 33} 34 35type DescribeAlarmHistoryInput struct { 36 37 // The name of the alarm. 38 AlarmName *string 39 40 // Use this parameter to specify whether you want the operation to return metric 41 // alarms or composite alarms. If you omit this parameter, only metric alarms are 42 // returned. 43 AlarmTypes []types.AlarmType 44 45 // The ending date to retrieve alarm history. 46 EndDate *time.Time 47 48 // The type of alarm histories to retrieve. 49 HistoryItemType types.HistoryItemType 50 51 // The maximum number of alarm history records to retrieve. 52 MaxRecords *int32 53 54 // The token returned by a previous call to indicate that there is more data 55 // available. 56 NextToken *string 57 58 // Specified whether to return the newest or oldest alarm history first. Specify 59 // TimestampDescending to have the newest event history returned first, and specify 60 // TimestampAscending to have the oldest history returned first. 61 ScanBy types.ScanBy 62 63 // The starting date to retrieve alarm history. 64 StartDate *time.Time 65} 66 67type DescribeAlarmHistoryOutput struct { 68 69 // The alarm histories, in JSON format. 70 AlarmHistoryItems []types.AlarmHistoryItem 71 72 // The token that marks the start of the next batch of returned results. 73 NextToken *string 74 75 // Metadata pertaining to the operation's result. 76 ResultMetadata middleware.Metadata 77} 78 79func addOperationDescribeAlarmHistoryMiddlewares(stack *middleware.Stack, options Options) (err error) { 80 err = stack.Serialize.Add(&awsAwsquery_serializeOpDescribeAlarmHistory{}, middleware.After) 81 if err != nil { 82 return err 83 } 84 err = stack.Deserialize.Add(&awsAwsquery_deserializeOpDescribeAlarmHistory{}, middleware.After) 85 if err != nil { 86 return err 87 } 88 if err = addSetLoggerMiddleware(stack, options); err != nil { 89 return err 90 } 91 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 92 return err 93 } 94 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 95 return err 96 } 97 if err = addResolveEndpointMiddleware(stack, options); err != nil { 98 return err 99 } 100 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 101 return err 102 } 103 if err = addRetryMiddlewares(stack, options); err != nil { 104 return err 105 } 106 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 107 return err 108 } 109 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 110 return err 111 } 112 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 113 return err 114 } 115 if err = addClientUserAgent(stack); err != nil { 116 return err 117 } 118 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 119 return err 120 } 121 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 122 return err 123 } 124 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeAlarmHistory(options.Region), middleware.Before); err != nil { 125 return err 126 } 127 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 128 return err 129 } 130 if err = addResponseErrorMiddleware(stack); err != nil { 131 return err 132 } 133 if err = addRequestResponseLogging(stack, options); err != nil { 134 return err 135 } 136 return nil 137} 138 139// DescribeAlarmHistoryAPIClient is a client that implements the 140// DescribeAlarmHistory operation. 141type DescribeAlarmHistoryAPIClient interface { 142 DescribeAlarmHistory(context.Context, *DescribeAlarmHistoryInput, ...func(*Options)) (*DescribeAlarmHistoryOutput, error) 143} 144 145var _ DescribeAlarmHistoryAPIClient = (*Client)(nil) 146 147// DescribeAlarmHistoryPaginatorOptions is the paginator options for 148// DescribeAlarmHistory 149type DescribeAlarmHistoryPaginatorOptions struct { 150 // The maximum number of alarm history records to retrieve. 151 Limit int32 152 153 // Set to true if pagination should stop if the service returns a pagination token 154 // that matches the most recent token provided to the service. 155 StopOnDuplicateToken bool 156} 157 158// DescribeAlarmHistoryPaginator is a paginator for DescribeAlarmHistory 159type DescribeAlarmHistoryPaginator struct { 160 options DescribeAlarmHistoryPaginatorOptions 161 client DescribeAlarmHistoryAPIClient 162 params *DescribeAlarmHistoryInput 163 nextToken *string 164 firstPage bool 165} 166 167// NewDescribeAlarmHistoryPaginator returns a new DescribeAlarmHistoryPaginator 168func NewDescribeAlarmHistoryPaginator(client DescribeAlarmHistoryAPIClient, params *DescribeAlarmHistoryInput, optFns ...func(*DescribeAlarmHistoryPaginatorOptions)) *DescribeAlarmHistoryPaginator { 169 options := DescribeAlarmHistoryPaginatorOptions{} 170 if params.MaxRecords != nil { 171 options.Limit = *params.MaxRecords 172 } 173 174 for _, fn := range optFns { 175 fn(&options) 176 } 177 178 if params == nil { 179 params = &DescribeAlarmHistoryInput{} 180 } 181 182 return &DescribeAlarmHistoryPaginator{ 183 options: options, 184 client: client, 185 params: params, 186 firstPage: true, 187 } 188} 189 190// HasMorePages returns a boolean indicating whether more pages are available 191func (p *DescribeAlarmHistoryPaginator) HasMorePages() bool { 192 return p.firstPage || p.nextToken != nil 193} 194 195// NextPage retrieves the next DescribeAlarmHistory page. 196func (p *DescribeAlarmHistoryPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeAlarmHistoryOutput, error) { 197 if !p.HasMorePages() { 198 return nil, fmt.Errorf("no more pages available") 199 } 200 201 params := *p.params 202 params.NextToken = p.nextToken 203 204 var limit *int32 205 if p.options.Limit > 0 { 206 limit = &p.options.Limit 207 } 208 params.MaxRecords = limit 209 210 result, err := p.client.DescribeAlarmHistory(ctx, ¶ms, optFns...) 211 if err != nil { 212 return nil, err 213 } 214 p.firstPage = false 215 216 prevToken := p.nextToken 217 p.nextToken = result.NextToken 218 219 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 220 p.nextToken = nil 221 } 222 223 return result, nil 224} 225 226func newServiceMetadataMiddleware_opDescribeAlarmHistory(region string) *awsmiddleware.RegisterServiceMetadata { 227 return &awsmiddleware.RegisterServiceMetadata{ 228 Region: region, 229 ServiceID: ServiceID, 230 SigningName: "monitoring", 231 OperationName: "DescribeAlarmHistory", 232 } 233} 234