...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/appinsights/v1/insights/events.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/appinsights/v1/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  // EventsClient is the composite Swagger for Application Insights Data Client
    18  type EventsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewEventsClient creates an instance of the EventsClient client.
    23  func NewEventsClient() EventsClient {
    24  	return NewEventsClientWithBaseURI(DefaultBaseURI)
    25  }
    26  
    27  // NewEventsClientWithBaseURI creates an instance of the EventsClient client using a custom endpoint.  Use this when
    28  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewEventsClientWithBaseURI(baseURI string) EventsClient {
    30  	return EventsClient{NewWithBaseURI(baseURI)}
    31  }
    32  
    33  // Get gets the data for a single event
    34  // Parameters:
    35  // appID - ID of the application. This is Application ID from the API Access settings blade in the Azure
    36  // portal.
    37  // eventType - the type of events to query; either a standard event type (`traces`, `customEvents`,
    38  // `pageViews`, `requests`, `dependencies`, `exceptions`, `availabilityResults`) or `$all` to query across all
    39  // event types.
    40  // eventID - ID of event.
    41  // timespan - optional. The timespan over which to retrieve events. This is an ISO8601 time period value.  This
    42  // timespan is applied in addition to any that are specified in the Odata expression.
    43  func (client EventsClient) Get(ctx context.Context, appID string, eventType EventType, eventID string, timespan string) (result EventsResults, err error) {
    44  	if tracing.IsEnabled() {
    45  		ctx = tracing.StartSpan(ctx, fqdn+"/EventsClient.Get")
    46  		defer func() {
    47  			sc := -1
    48  			if result.Response.Response != nil {
    49  				sc = result.Response.Response.StatusCode
    50  			}
    51  			tracing.EndSpan(ctx, sc, err)
    52  		}()
    53  	}
    54  	req, err := client.GetPreparer(ctx, appID, eventType, eventID, timespan)
    55  	if err != nil {
    56  		err = autorest.NewErrorWithError(err, "insights.EventsClient", "Get", nil, "Failure preparing request")
    57  		return
    58  	}
    59  
    60  	resp, err := client.GetSender(req)
    61  	if err != nil {
    62  		result.Response = autorest.Response{Response: resp}
    63  		err = autorest.NewErrorWithError(err, "insights.EventsClient", "Get", resp, "Failure sending request")
    64  		return
    65  	}
    66  
    67  	result, err = client.GetResponder(resp)
    68  	if err != nil {
    69  		err = autorest.NewErrorWithError(err, "insights.EventsClient", "Get", resp, "Failure responding to request")
    70  		return
    71  	}
    72  
    73  	return
    74  }
    75  
    76  // GetPreparer prepares the Get request.
    77  func (client EventsClient) GetPreparer(ctx context.Context, appID string, eventType EventType, eventID string, timespan string) (*http.Request, error) {
    78  	pathParameters := map[string]interface{}{
    79  		"appId":     autorest.Encode("path", appID),
    80  		"eventId":   autorest.Encode("path", eventID),
    81  		"eventType": autorest.Encode("path", eventType),
    82  	}
    83  
    84  	queryParameters := map[string]interface{}{}
    85  	if len(timespan) > 0 {
    86  		queryParameters["timespan"] = autorest.Encode("query", timespan)
    87  	}
    88  
    89  	preparer := autorest.CreatePreparer(
    90  		autorest.AsGet(),
    91  		autorest.WithBaseURL(client.BaseURI),
    92  		autorest.WithPathParameters("/apps/{appId}/events/{eventType}/{eventId}", pathParameters),
    93  		autorest.WithQueryParameters(queryParameters))
    94  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    95  }
    96  
    97  // GetSender sends the Get request. The method will close the
    98  // http.Response Body if it receives an error.
    99  func (client EventsClient) GetSender(req *http.Request) (*http.Response, error) {
   100  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   101  }
   102  
   103  // GetResponder handles the response to the Get request. The method always
   104  // closes the http.Response Body.
   105  func (client EventsClient) GetResponder(resp *http.Response) (result EventsResults, err error) {
   106  	err = autorest.Respond(
   107  		resp,
   108  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   109  		autorest.ByUnmarshallingJSON(&result),
   110  		autorest.ByClosing())
   111  	result.Response = autorest.Response{Response: resp}
   112  	return
   113  }
   114  
   115  // GetByType executes an OData query for events
   116  // Parameters:
   117  // appID - ID of the application. This is Application ID from the API Access settings blade in the Azure
   118  // portal.
   119  // eventType - the type of events to query; either a standard event type (`traces`, `customEvents`,
   120  // `pageViews`, `requests`, `dependencies`, `exceptions`, `availabilityResults`) or `$all` to query across all
   121  // event types.
   122  // timespan - optional. The timespan over which to retrieve events. This is an ISO8601 time period value.  This
   123  // timespan is applied in addition to any that are specified in the Odata expression.
   124  // filter - an expression used to filter the returned events
   125  // search - a free-text search expression to match for whether a particular event should be returned
   126  // orderby - a comma-separated list of properties with \"asc\" (the default) or \"desc\" to control the order
   127  // of returned events
   128  // selectParameter - limits the properties to just those requested on each returned event
   129  // skip - the number of items to skip over before returning events
   130  // top - the number of events to return
   131  // formatParameter - format for the returned events
   132  // count - request a count of matching items included with the returned events
   133  // apply - an expression used for aggregation over returned events
   134  func (client EventsClient) GetByType(ctx context.Context, appID string, eventType EventType, timespan string, filter string, search string, orderby string, selectParameter string, skip *int32, top *int32, formatParameter string, count *bool, apply string) (result EventsResults, err error) {
   135  	if tracing.IsEnabled() {
   136  		ctx = tracing.StartSpan(ctx, fqdn+"/EventsClient.GetByType")
   137  		defer func() {
   138  			sc := -1
   139  			if result.Response.Response != nil {
   140  				sc = result.Response.Response.StatusCode
   141  			}
   142  			tracing.EndSpan(ctx, sc, err)
   143  		}()
   144  	}
   145  	req, err := client.GetByTypePreparer(ctx, appID, eventType, timespan, filter, search, orderby, selectParameter, skip, top, formatParameter, count, apply)
   146  	if err != nil {
   147  		err = autorest.NewErrorWithError(err, "insights.EventsClient", "GetByType", nil, "Failure preparing request")
   148  		return
   149  	}
   150  
   151  	resp, err := client.GetByTypeSender(req)
   152  	if err != nil {
   153  		result.Response = autorest.Response{Response: resp}
   154  		err = autorest.NewErrorWithError(err, "insights.EventsClient", "GetByType", resp, "Failure sending request")
   155  		return
   156  	}
   157  
   158  	result, err = client.GetByTypeResponder(resp)
   159  	if err != nil {
   160  		err = autorest.NewErrorWithError(err, "insights.EventsClient", "GetByType", resp, "Failure responding to request")
   161  		return
   162  	}
   163  
   164  	return
   165  }
   166  
   167  // GetByTypePreparer prepares the GetByType request.
   168  func (client EventsClient) GetByTypePreparer(ctx context.Context, appID string, eventType EventType, timespan string, filter string, search string, orderby string, selectParameter string, skip *int32, top *int32, formatParameter string, count *bool, apply string) (*http.Request, error) {
   169  	pathParameters := map[string]interface{}{
   170  		"appId":     autorest.Encode("path", appID),
   171  		"eventType": autorest.Encode("path", eventType),
   172  	}
   173  
   174  	queryParameters := map[string]interface{}{}
   175  	if len(timespan) > 0 {
   176  		queryParameters["timespan"] = autorest.Encode("query", timespan)
   177  	}
   178  	if len(filter) > 0 {
   179  		queryParameters["$filter"] = autorest.Encode("query", filter)
   180  	}
   181  	if len(search) > 0 {
   182  		queryParameters["$search"] = autorest.Encode("query", search)
   183  	}
   184  	if len(orderby) > 0 {
   185  		queryParameters["$orderby"] = autorest.Encode("query", orderby)
   186  	}
   187  	if len(selectParameter) > 0 {
   188  		queryParameters["$select"] = autorest.Encode("query", selectParameter)
   189  	}
   190  	if skip != nil {
   191  		queryParameters["$skip"] = autorest.Encode("query", *skip)
   192  	}
   193  	if top != nil {
   194  		queryParameters["$top"] = autorest.Encode("query", *top)
   195  	}
   196  	if len(formatParameter) > 0 {
   197  		queryParameters["$format"] = autorest.Encode("query", formatParameter)
   198  	}
   199  	if count != nil {
   200  		queryParameters["$count"] = autorest.Encode("query", *count)
   201  	}
   202  	if len(apply) > 0 {
   203  		queryParameters["$apply"] = autorest.Encode("query", apply)
   204  	}
   205  
   206  	preparer := autorest.CreatePreparer(
   207  		autorest.AsGet(),
   208  		autorest.WithBaseURL(client.BaseURI),
   209  		autorest.WithPathParameters("/apps/{appId}/events/{eventType}", pathParameters),
   210  		autorest.WithQueryParameters(queryParameters))
   211  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   212  }
   213  
   214  // GetByTypeSender sends the GetByType request. The method will close the
   215  // http.Response Body if it receives an error.
   216  func (client EventsClient) GetByTypeSender(req *http.Request) (*http.Response, error) {
   217  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   218  }
   219  
   220  // GetByTypeResponder handles the response to the GetByType request. The method always
   221  // closes the http.Response Body.
   222  func (client EventsClient) GetByTypeResponder(resp *http.Response) (result EventsResults, err error) {
   223  	err = autorest.Respond(
   224  		resp,
   225  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   226  		autorest.ByUnmarshallingJSON(&result),
   227  		autorest.ByClosing())
   228  	result.Response = autorest.Response{Response: resp}
   229  	return
   230  }
   231  
   232  // GetOdataMetadata gets OData EDMX metadata describing the event data model
   233  // Parameters:
   234  // appID - ID of the application. This is Application ID from the API Access settings blade in the Azure
   235  // portal.
   236  func (client EventsClient) GetOdataMetadata(ctx context.Context, appID string) (result SetObject, err error) {
   237  	if tracing.IsEnabled() {
   238  		ctx = tracing.StartSpan(ctx, fqdn+"/EventsClient.GetOdataMetadata")
   239  		defer func() {
   240  			sc := -1
   241  			if result.Response.Response != nil {
   242  				sc = result.Response.Response.StatusCode
   243  			}
   244  			tracing.EndSpan(ctx, sc, err)
   245  		}()
   246  	}
   247  	req, err := client.GetOdataMetadataPreparer(ctx, appID)
   248  	if err != nil {
   249  		err = autorest.NewErrorWithError(err, "insights.EventsClient", "GetOdataMetadata", nil, "Failure preparing request")
   250  		return
   251  	}
   252  
   253  	resp, err := client.GetOdataMetadataSender(req)
   254  	if err != nil {
   255  		result.Response = autorest.Response{Response: resp}
   256  		err = autorest.NewErrorWithError(err, "insights.EventsClient", "GetOdataMetadata", resp, "Failure sending request")
   257  		return
   258  	}
   259  
   260  	result, err = client.GetOdataMetadataResponder(resp)
   261  	if err != nil {
   262  		err = autorest.NewErrorWithError(err, "insights.EventsClient", "GetOdataMetadata", resp, "Failure responding to request")
   263  		return
   264  	}
   265  
   266  	return
   267  }
   268  
   269  // GetOdataMetadataPreparer prepares the GetOdataMetadata request.
   270  func (client EventsClient) GetOdataMetadataPreparer(ctx context.Context, appID string) (*http.Request, error) {
   271  	pathParameters := map[string]interface{}{
   272  		"appId": autorest.Encode("path", appID),
   273  	}
   274  
   275  	preparer := autorest.CreatePreparer(
   276  		autorest.AsGet(),
   277  		autorest.WithBaseURL(client.BaseURI),
   278  		autorest.WithPathParameters("/apps/{appId}/events/$metadata", pathParameters))
   279  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   280  }
   281  
   282  // GetOdataMetadataSender sends the GetOdataMetadata request. The method will close the
   283  // http.Response Body if it receives an error.
   284  func (client EventsClient) GetOdataMetadataSender(req *http.Request) (*http.Response, error) {
   285  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   286  }
   287  
   288  // GetOdataMetadataResponder handles the response to the GetOdataMetadata request. The method always
   289  // closes the http.Response Body.
   290  func (client EventsClient) GetOdataMetadataResponder(resp *http.Response) (result SetObject, err error) {
   291  	err = autorest.Respond(
   292  		resp,
   293  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   294  		autorest.ByUnmarshallingJSON(&result.Value),
   295  		autorest.ByClosing())
   296  	result.Response = autorest.Response{Response: resp}
   297  	return
   298  }
   299  

View as plain text