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