1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package devopsguru 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/devopsguru/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Returns a list of insights in your AWS account. You can specify which insights 16// are returned by their start time, one or more statuses (ONGOING, CLOSED, and 17// CLOSED), one or more severities (LOW, MEDIUM, and HIGH), and type (REACTIVE or 18// PROACTIVE). Use the Filters parameter to specify status and severity search 19// parameters. Use the Type parameter to specify REACTIVE or PROACTIVE in your 20// search. 21func (c *Client) SearchInsights(ctx context.Context, params *SearchInsightsInput, optFns ...func(*Options)) (*SearchInsightsOutput, error) { 22 if params == nil { 23 params = &SearchInsightsInput{} 24 } 25 26 result, metadata, err := c.invokeOperation(ctx, "SearchInsights", params, optFns, addOperationSearchInsightsMiddlewares) 27 if err != nil { 28 return nil, err 29 } 30 31 out := result.(*SearchInsightsOutput) 32 out.ResultMetadata = metadata 33 return out, nil 34} 35 36type SearchInsightsInput struct { 37 38 // The start of the time range passed in. Returned insights occurred after this 39 // time. 40 // 41 // This member is required. 42 StartTimeRange *types.StartTimeRange 43 44 // The type of insights you are searching for (REACTIVE or PROACTIVE). 45 // 46 // This member is required. 47 Type types.InsightType 48 49 // A SearchInsightsFilters object that is used to set the severity and status 50 // filters on your insight search. 51 Filters *types.SearchInsightsFilters 52 53 // The maximum number of results to return with a single call. To retrieve the 54 // remaining results, make another call with the returned nextToken value. 55 MaxResults *int32 56 57 // The pagination token to use to retrieve the next page of results for this 58 // operation. If this value is null, it retrieves the first page. 59 NextToken *string 60} 61 62type SearchInsightsOutput struct { 63 64 // The pagination token to use to retrieve the next page of results for this 65 // operation. If there are no more pages, this value is null. 66 NextToken *string 67 68 // The returned proactive insights. 69 ProactiveInsights []types.ProactiveInsightSummary 70 71 // The returned reactive insights. 72 ReactiveInsights []types.ReactiveInsightSummary 73 74 // Metadata pertaining to the operation's result. 75 ResultMetadata middleware.Metadata 76} 77 78func addOperationSearchInsightsMiddlewares(stack *middleware.Stack, options Options) (err error) { 79 err = stack.Serialize.Add(&awsRestjson1_serializeOpSearchInsights{}, middleware.After) 80 if err != nil { 81 return err 82 } 83 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpSearchInsights{}, middleware.After) 84 if err != nil { 85 return err 86 } 87 if err = addSetLoggerMiddleware(stack, options); err != nil { 88 return err 89 } 90 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 91 return err 92 } 93 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 94 return err 95 } 96 if err = addResolveEndpointMiddleware(stack, options); err != nil { 97 return err 98 } 99 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 100 return err 101 } 102 if err = addRetryMiddlewares(stack, options); err != nil { 103 return err 104 } 105 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 106 return err 107 } 108 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 109 return err 110 } 111 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 112 return err 113 } 114 if err = addClientUserAgent(stack); err != nil { 115 return err 116 } 117 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 118 return err 119 } 120 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 121 return err 122 } 123 if err = addOpSearchInsightsValidationMiddleware(stack); err != nil { 124 return err 125 } 126 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opSearchInsights(options.Region), middleware.Before); err != nil { 127 return err 128 } 129 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 130 return err 131 } 132 if err = addResponseErrorMiddleware(stack); err != nil { 133 return err 134 } 135 if err = addRequestResponseLogging(stack, options); err != nil { 136 return err 137 } 138 return nil 139} 140 141// SearchInsightsAPIClient is a client that implements the SearchInsights 142// operation. 143type SearchInsightsAPIClient interface { 144 SearchInsights(context.Context, *SearchInsightsInput, ...func(*Options)) (*SearchInsightsOutput, error) 145} 146 147var _ SearchInsightsAPIClient = (*Client)(nil) 148 149// SearchInsightsPaginatorOptions is the paginator options for SearchInsights 150type SearchInsightsPaginatorOptions struct { 151 // The maximum number of results to return with a single call. To retrieve the 152 // remaining results, make another call with the returned nextToken value. 153 Limit int32 154 155 // Set to true if pagination should stop if the service returns a pagination token 156 // that matches the most recent token provided to the service. 157 StopOnDuplicateToken bool 158} 159 160// SearchInsightsPaginator is a paginator for SearchInsights 161type SearchInsightsPaginator struct { 162 options SearchInsightsPaginatorOptions 163 client SearchInsightsAPIClient 164 params *SearchInsightsInput 165 nextToken *string 166 firstPage bool 167} 168 169// NewSearchInsightsPaginator returns a new SearchInsightsPaginator 170func NewSearchInsightsPaginator(client SearchInsightsAPIClient, params *SearchInsightsInput, optFns ...func(*SearchInsightsPaginatorOptions)) *SearchInsightsPaginator { 171 if params == nil { 172 params = &SearchInsightsInput{} 173 } 174 175 options := SearchInsightsPaginatorOptions{} 176 if params.MaxResults != nil { 177 options.Limit = *params.MaxResults 178 } 179 180 for _, fn := range optFns { 181 fn(&options) 182 } 183 184 return &SearchInsightsPaginator{ 185 options: options, 186 client: client, 187 params: params, 188 firstPage: true, 189 } 190} 191 192// HasMorePages returns a boolean indicating whether more pages are available 193func (p *SearchInsightsPaginator) HasMorePages() bool { 194 return p.firstPage || p.nextToken != nil 195} 196 197// NextPage retrieves the next SearchInsights page. 198func (p *SearchInsightsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*SearchInsightsOutput, error) { 199 if !p.HasMorePages() { 200 return nil, fmt.Errorf("no more pages available") 201 } 202 203 params := *p.params 204 params.NextToken = p.nextToken 205 206 var limit *int32 207 if p.options.Limit > 0 { 208 limit = &p.options.Limit 209 } 210 params.MaxResults = limit 211 212 result, err := p.client.SearchInsights(ctx, ¶ms, optFns...) 213 if err != nil { 214 return nil, err 215 } 216 p.firstPage = false 217 218 prevToken := p.nextToken 219 p.nextToken = result.NextToken 220 221 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 222 p.nextToken = nil 223 } 224 225 return result, nil 226} 227 228func newServiceMetadataMiddleware_opSearchInsights(region string) *awsmiddleware.RegisterServiceMetadata { 229 return &awsmiddleware.RegisterServiceMetadata{ 230 Region: region, 231 ServiceID: ServiceID, 232 SigningName: "devops-guru", 233 OperationName: "SearchInsights", 234 } 235} 236