...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2022-10-01-preview/insights/activitylogs.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2022-10-01-preview/insights

     1  package insights
     2  
     3  // Copyright (c) Microsoft Corporation. All rights reserved.
     4  // Licensed under the MIT License. See License.txt in the project root for license information.
     5  //
     6  // Code generated by Microsoft (R) AutoRest Code Generator.
     7  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
     8  
     9  import (
    10  	"context"
    11  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // ActivityLogsClient is the monitor Management Client
    19  type ActivityLogsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewActivityLogsClient creates an instance of the ActivityLogsClient client.
    24  func NewActivityLogsClient(subscriptionID string) ActivityLogsClient {
    25  	return NewActivityLogsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewActivityLogsClientWithBaseURI creates an instance of the ActivityLogsClient client using a custom endpoint.  Use
    29  // this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewActivityLogsClientWithBaseURI(baseURI string, subscriptionID string) ActivityLogsClient {
    31  	return ActivityLogsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // List provides the list of records from the activity logs.
    35  // Parameters:
    36  // filter - reduces the set of data collected.<br>This argument is required and it also requires at least the
    37  // start date/time.<br>The **$filter** argument is very restricted and allows only the following patterns.<br>-
    38  // *List events for a resource group*: $filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and
    39  // eventTimestamp le '2014-07-20T04:36:37.6407898Z' and resourceGroupName eq 'resourceGroupName'.<br>- *List
    40  // events for resource*: $filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le
    41  // '2014-07-20T04:36:37.6407898Z' and resourceUri eq 'resourceURI'.<br>- *List events for a subscription in a
    42  // time range*: $filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le
    43  // '2014-07-20T04:36:37.6407898Z'.<br>- *List events for a resource provider*: $filter=eventTimestamp ge
    44  // '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z' and resourceProvider eq
    45  // 'resourceProviderName'.<br>- *List events for a correlation Id*: $filter=eventTimestamp ge
    46  // '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z' and correlationId eq
    47  // 'correlationID'.<br><br>**NOTE**: No other syntax is allowed.
    48  // selectParameter - used to fetch events with only the given properties.<br>The **$select** argument is a
    49  // comma separated list of property names to be returned. Possible values are: *authorization*, *claims*,
    50  // *correlationId*, *description*, *eventDataId*, *eventName*, *eventTimestamp*, *httpRequest*, *level*,
    51  // *operationId*, *operationName*, *properties*, *resourceGroupName*, *resourceProviderName*, *resourceId*,
    52  // *status*, *submissionTimestamp*, *subStatus*, *subscriptionId*
    53  func (client ActivityLogsClient) List(ctx context.Context, filter string, selectParameter string) (result EventDataCollectionPage, err error) {
    54  	if tracing.IsEnabled() {
    55  		ctx = tracing.StartSpan(ctx, fqdn+"/ActivityLogsClient.List")
    56  		defer func() {
    57  			sc := -1
    58  			if result.edc.Response.Response != nil {
    59  				sc = result.edc.Response.Response.StatusCode
    60  			}
    61  			tracing.EndSpan(ctx, sc, err)
    62  		}()
    63  	}
    64  	if err := validation.Validate([]validation.Validation{
    65  		{TargetValue: client.SubscriptionID,
    66  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
    67  		return result, validation.NewError("insights.ActivityLogsClient", "List", err.Error())
    68  	}
    69  
    70  	result.fn = client.listNextResults
    71  	req, err := client.ListPreparer(ctx, filter, selectParameter)
    72  	if err != nil {
    73  		err = autorest.NewErrorWithError(err, "insights.ActivityLogsClient", "List", nil, "Failure preparing request")
    74  		return
    75  	}
    76  
    77  	resp, err := client.ListSender(req)
    78  	if err != nil {
    79  		result.edc.Response = autorest.Response{Response: resp}
    80  		err = autorest.NewErrorWithError(err, "insights.ActivityLogsClient", "List", resp, "Failure sending request")
    81  		return
    82  	}
    83  
    84  	result.edc, err = client.ListResponder(resp)
    85  	if err != nil {
    86  		err = autorest.NewErrorWithError(err, "insights.ActivityLogsClient", "List", resp, "Failure responding to request")
    87  		return
    88  	}
    89  	if result.edc.hasNextLink() && result.edc.IsEmpty() {
    90  		err = result.NextWithContext(ctx)
    91  		return
    92  	}
    93  
    94  	return
    95  }
    96  
    97  // ListPreparer prepares the List request.
    98  func (client ActivityLogsClient) ListPreparer(ctx context.Context, filter string, selectParameter string) (*http.Request, error) {
    99  	pathParameters := map[string]interface{}{
   100  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   101  	}
   102  
   103  	const APIVersion = "2015-04-01"
   104  	queryParameters := map[string]interface{}{
   105  		"$filter":     autorest.Encode("query", filter),
   106  		"api-version": APIVersion,
   107  	}
   108  	if len(selectParameter) > 0 {
   109  		queryParameters["$select"] = autorest.Encode("query", selectParameter)
   110  	}
   111  
   112  	preparer := autorest.CreatePreparer(
   113  		autorest.AsGet(),
   114  		autorest.WithBaseURL(client.BaseURI),
   115  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Insights/eventtypes/management/values", pathParameters),
   116  		autorest.WithQueryParameters(queryParameters))
   117  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   118  }
   119  
   120  // ListSender sends the List request. The method will close the
   121  // http.Response Body if it receives an error.
   122  func (client ActivityLogsClient) ListSender(req *http.Request) (*http.Response, error) {
   123  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   124  }
   125  
   126  // ListResponder handles the response to the List request. The method always
   127  // closes the http.Response Body.
   128  func (client ActivityLogsClient) ListResponder(resp *http.Response) (result EventDataCollection, err error) {
   129  	err = autorest.Respond(
   130  		resp,
   131  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   132  		autorest.ByUnmarshallingJSON(&result),
   133  		autorest.ByClosing())
   134  	result.Response = autorest.Response{Response: resp}
   135  	return
   136  }
   137  
   138  // listNextResults retrieves the next set of results, if any.
   139  func (client ActivityLogsClient) listNextResults(ctx context.Context, lastResults EventDataCollection) (result EventDataCollection, err error) {
   140  	req, err := lastResults.eventDataCollectionPreparer(ctx)
   141  	if err != nil {
   142  		return result, autorest.NewErrorWithError(err, "insights.ActivityLogsClient", "listNextResults", nil, "Failure preparing next results request")
   143  	}
   144  	if req == nil {
   145  		return
   146  	}
   147  	resp, err := client.ListSender(req)
   148  	if err != nil {
   149  		result.Response = autorest.Response{Response: resp}
   150  		return result, autorest.NewErrorWithError(err, "insights.ActivityLogsClient", "listNextResults", resp, "Failure sending next results request")
   151  	}
   152  	result, err = client.ListResponder(resp)
   153  	if err != nil {
   154  		err = autorest.NewErrorWithError(err, "insights.ActivityLogsClient", "listNextResults", resp, "Failure responding to next results request")
   155  	}
   156  	return
   157  }
   158  
   159  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   160  func (client ActivityLogsClient) ListComplete(ctx context.Context, filter string, selectParameter string) (result EventDataCollectionIterator, err error) {
   161  	if tracing.IsEnabled() {
   162  		ctx = tracing.StartSpan(ctx, fqdn+"/ActivityLogsClient.List")
   163  		defer func() {
   164  			sc := -1
   165  			if result.Response().Response.Response != nil {
   166  				sc = result.page.Response().Response.Response.StatusCode
   167  			}
   168  			tracing.EndSpan(ctx, sc, err)
   169  		}()
   170  	}
   171  	result.page, err = client.List(ctx, filter, selectParameter)
   172  	return
   173  }
   174  

View as plain text