1package insights 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/tracing" 25 "net/http" 26) 27 28// TenantActivityLogsClient is the monitor Management Client 29type TenantActivityLogsClient struct { 30 BaseClient 31} 32 33// NewTenantActivityLogsClient creates an instance of the TenantActivityLogsClient client. 34func NewTenantActivityLogsClient(subscriptionID string) TenantActivityLogsClient { 35 return NewTenantActivityLogsClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewTenantActivityLogsClientWithBaseURI creates an instance of the TenantActivityLogsClient client using a custom 39// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 40// stack). 41func NewTenantActivityLogsClientWithBaseURI(baseURI string, subscriptionID string) TenantActivityLogsClient { 42 return TenantActivityLogsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// List gets the Activity Logs for the Tenant.<br>Everything that is applicable to the API to get the Activity Logs for 46// the subscription is applicable to this API (the parameters, $filter, etc.).<br>One thing to point out here is that 47// this API does *not* retrieve the logs at the individual subscription of the tenant but only surfaces the logs that 48// were generated at the tenant level. 49// Parameters: 50// filter - reduces the set of data collected. <br>The **$filter** is very restricted and allows only the 51// following patterns.<br>- List events for a resource group: $filter=eventTimestamp ge '<Start Time>' and 52// eventTimestamp le '<End Time>' and eventChannels eq 'Admin, Operation' and resourceGroupName eq 53// '<ResourceGroupName>'.<br>- List events for resource: $filter=eventTimestamp ge '<Start Time>' and 54// eventTimestamp le '<End Time>' and eventChannels eq 'Admin, Operation' and resourceUri eq 55// '<ResourceURI>'.<br>- List events for a subscription: $filter=eventTimestamp ge '<Start Time>' and 56// eventTimestamp le '<End Time>' and eventChannels eq 'Admin, Operation'.<br>- List events for a resource 57// provider: $filter=eventTimestamp ge '<Start Time>' and eventTimestamp le '<End Time>' and eventChannels eq 58// 'Admin, Operation' and resourceProvider eq '<ResourceProviderName>'.<br>- List events for a correlation Id: 59// api-version=2014-04-01&$filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le 60// '2014-07-20T04:36:37.6407898Z' and eventChannels eq 'Admin, Operation' and correlationId eq 61// '<CorrelationID>'.<br>**NOTE**: No other syntax is allowed. 62// selectParameter - used to fetch events with only the given properties.<br>The **$select** argument is a 63// comma separated list of property names to be returned. Possible values are: *authorization*, *claims*, 64// *correlationId*, *description*, *eventDataId*, *eventName*, *eventTimestamp*, *httpRequest*, *level*, 65// *operationId*, *operationName*, *properties*, *resourceGroupName*, *resourceProviderName*, *resourceId*, 66// *status*, *submissionTimestamp*, *subStatus*, *subscriptionId* 67func (client TenantActivityLogsClient) List(ctx context.Context, filter string, selectParameter string) (result EventDataCollectionPage, err error) { 68 if tracing.IsEnabled() { 69 ctx = tracing.StartSpan(ctx, fqdn+"/TenantActivityLogsClient.List") 70 defer func() { 71 sc := -1 72 if result.edc.Response.Response != nil { 73 sc = result.edc.Response.Response.StatusCode 74 } 75 tracing.EndSpan(ctx, sc, err) 76 }() 77 } 78 result.fn = client.listNextResults 79 req, err := client.ListPreparer(ctx, filter, selectParameter) 80 if err != nil { 81 err = autorest.NewErrorWithError(err, "insights.TenantActivityLogsClient", "List", nil, "Failure preparing request") 82 return 83 } 84 85 resp, err := client.ListSender(req) 86 if err != nil { 87 result.edc.Response = autorest.Response{Response: resp} 88 err = autorest.NewErrorWithError(err, "insights.TenantActivityLogsClient", "List", resp, "Failure sending request") 89 return 90 } 91 92 result.edc, err = client.ListResponder(resp) 93 if err != nil { 94 err = autorest.NewErrorWithError(err, "insights.TenantActivityLogsClient", "List", resp, "Failure responding to request") 95 } 96 97 return 98} 99 100// ListPreparer prepares the List request. 101func (client TenantActivityLogsClient) ListPreparer(ctx context.Context, filter string, selectParameter string) (*http.Request, error) { 102 const APIVersion = "2015-04-01" 103 queryParameters := map[string]interface{}{ 104 "api-version": APIVersion, 105 } 106 if len(filter) > 0 { 107 queryParameters["$filter"] = autorest.Encode("query", filter) 108 } 109 if len(selectParameter) > 0 { 110 queryParameters["$select"] = autorest.Encode("query", selectParameter) 111 } 112 113 preparer := autorest.CreatePreparer( 114 autorest.AsGet(), 115 autorest.WithBaseURL(client.BaseURI), 116 autorest.WithPath("/providers/microsoft.insights/eventtypes/management/values"), 117 autorest.WithQueryParameters(queryParameters)) 118 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 119} 120 121// ListSender sends the List request. The method will close the 122// http.Response Body if it receives an error. 123func (client TenantActivityLogsClient) ListSender(req *http.Request) (*http.Response, error) { 124 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 125} 126 127// ListResponder handles the response to the List request. The method always 128// closes the http.Response Body. 129func (client TenantActivityLogsClient) ListResponder(resp *http.Response) (result EventDataCollection, err error) { 130 err = autorest.Respond( 131 resp, 132 client.ByInspecting(), 133 azure.WithErrorUnlessStatusCode(http.StatusOK), 134 autorest.ByUnmarshallingJSON(&result), 135 autorest.ByClosing()) 136 result.Response = autorest.Response{Response: resp} 137 return 138} 139 140// listNextResults retrieves the next set of results, if any. 141func (client TenantActivityLogsClient) listNextResults(ctx context.Context, lastResults EventDataCollection) (result EventDataCollection, err error) { 142 req, err := lastResults.eventDataCollectionPreparer(ctx) 143 if err != nil { 144 return result, autorest.NewErrorWithError(err, "insights.TenantActivityLogsClient", "listNextResults", nil, "Failure preparing next results request") 145 } 146 if req == nil { 147 return 148 } 149 resp, err := client.ListSender(req) 150 if err != nil { 151 result.Response = autorest.Response{Response: resp} 152 return result, autorest.NewErrorWithError(err, "insights.TenantActivityLogsClient", "listNextResults", resp, "Failure sending next results request") 153 } 154 result, err = client.ListResponder(resp) 155 if err != nil { 156 err = autorest.NewErrorWithError(err, "insights.TenantActivityLogsClient", "listNextResults", resp, "Failure responding to next results request") 157 } 158 return 159} 160 161// ListComplete enumerates all values, automatically crossing page boundaries as required. 162func (client TenantActivityLogsClient) ListComplete(ctx context.Context, filter string, selectParameter string) (result EventDataCollectionIterator, err error) { 163 if tracing.IsEnabled() { 164 ctx = tracing.StartSpan(ctx, fqdn+"/TenantActivityLogsClient.List") 165 defer func() { 166 sc := -1 167 if result.Response().Response.Response != nil { 168 sc = result.page.Response().Response.Response.StatusCode 169 } 170 tracing.EndSpan(ctx, sc, err) 171 }() 172 } 173 result.page, err = client.List(ctx, filter, selectParameter) 174 return 175} 176