...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2018-03-01/insights/tenantactivitylogs.go

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

View as plain text