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// BaselinesClient is the monitor Management Client 18type BaselinesClient struct { 19 BaseClient 20} 21 22// NewBaselinesClient creates an instance of the BaselinesClient client. 23func NewBaselinesClient(subscriptionID string) BaselinesClient { 24 return NewBaselinesClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewBaselinesClientWithBaseURI creates an instance of the BaselinesClient client using a custom endpoint. Use this 28// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 29func NewBaselinesClientWithBaseURI(baseURI string, subscriptionID string) BaselinesClient { 30 return BaselinesClient{NewWithBaseURI(baseURI, subscriptionID)} 31} 32 33// List **Lists the metric baseline values for a resource**. 34// Parameters: 35// resourceURI - the identifier of the resource. 36// metricnames - the names of the metrics (comma separated) to retrieve. 37// metricnamespace - metric namespace to query metric definitions for. 38// timespan - the timespan of the query. It is a string with the following format 39// 'startDateTime_ISO/endDateTime_ISO'. 40// interval - the interval (i.e. timegrain) of the query. 41// aggregation - the list of aggregation types (comma separated) to retrieve. 42// sensitivities - the list of sensitivities (comma separated) to retrieve. 43// filter - the **$filter** is used to reduce the set of metric data returned.<br>Example:<br>Metric contains 44// metadata A, B and C.<br>- Return all time series of C where A = a1 and B = b1 or b2<br>**$filter=A eq ‘a1’ 45// and B eq ‘b1’ or B eq ‘b2’ and C eq ‘*’**<br>- Invalid variant:<br>**$filter=A eq ‘a1’ and B eq ‘b1’ and C 46// eq ‘*’ or B = ‘b2’**<br>This is invalid because the logical or operator cannot separate two different 47// metadata names.<br>- Return all time series where A = a1, B = b1 and C = c1:<br>**$filter=A eq ‘a1’ and B eq 48// ‘b1’ and C eq ‘c1’**<br>- Return all time series where A = a1<br>**$filter=A eq ‘a1’ and B eq ‘*’ and C eq 49// ‘*’**. 50// resultType - allows retrieving only metadata of the baseline. On data request all information is retrieved. 51func (client BaselinesClient) List(ctx context.Context, resourceURI string, metricnames string, metricnamespace string, timespan string, interval *string, aggregation string, sensitivities string, filter string, resultType ResultType) (result MetricBaselinesResponse, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/BaselinesClient.List") 54 defer func() { 55 sc := -1 56 if result.Response.Response != nil { 57 sc = result.Response.Response.StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 req, err := client.ListPreparer(ctx, resourceURI, metricnames, metricnamespace, timespan, interval, aggregation, sensitivities, filter, resultType) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "insights.BaselinesClient", "List", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.ListSender(req) 69 if err != nil { 70 result.Response = autorest.Response{Response: resp} 71 err = autorest.NewErrorWithError(err, "insights.BaselinesClient", "List", resp, "Failure sending request") 72 return 73 } 74 75 result, err = client.ListResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "insights.BaselinesClient", "List", resp, "Failure responding to request") 78 return 79 } 80 81 return 82} 83 84// ListPreparer prepares the List request. 85func (client BaselinesClient) ListPreparer(ctx context.Context, resourceURI string, metricnames string, metricnamespace string, timespan string, interval *string, aggregation string, sensitivities string, filter string, resultType ResultType) (*http.Request, error) { 86 pathParameters := map[string]interface{}{ 87 "resourceUri": resourceURI, 88 } 89 90 const APIVersion = "2019-03-01" 91 queryParameters := map[string]interface{}{ 92 "api-version": APIVersion, 93 } 94 if len(metricnames) > 0 { 95 queryParameters["metricnames"] = autorest.Encode("query", metricnames) 96 } 97 if len(metricnamespace) > 0 { 98 queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace) 99 } 100 if len(timespan) > 0 { 101 queryParameters["timespan"] = autorest.Encode("query", timespan) 102 } 103 if interval != nil { 104 queryParameters["interval"] = autorest.Encode("query", *interval) 105 } 106 if len(aggregation) > 0 { 107 queryParameters["aggregation"] = autorest.Encode("query", aggregation) 108 } 109 if len(sensitivities) > 0 { 110 queryParameters["sensitivities"] = autorest.Encode("query", sensitivities) 111 } 112 if len(filter) > 0 { 113 queryParameters["$filter"] = autorest.Encode("query", filter) 114 } 115 if len(string(resultType)) > 0 { 116 queryParameters["resultType"] = autorest.Encode("query", resultType) 117 } 118 119 preparer := autorest.CreatePreparer( 120 autorest.AsGet(), 121 autorest.WithBaseURL(client.BaseURI), 122 autorest.WithPathParameters("/{resourceUri}/providers/microsoft.insights/metricBaselines", pathParameters), 123 autorest.WithQueryParameters(queryParameters)) 124 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 125} 126 127// ListSender sends the List request. The method will close the 128// http.Response Body if it receives an error. 129func (client BaselinesClient) ListSender(req *http.Request) (*http.Response, error) { 130 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 131} 132 133// ListResponder handles the response to the List request. The method always 134// closes the http.Response Body. 135func (client BaselinesClient) ListResponder(resp *http.Response) (result MetricBaselinesResponse, err error) { 136 err = autorest.Respond( 137 resp, 138 azure.WithErrorUnlessStatusCode(http.StatusOK), 139 autorest.ByUnmarshallingJSON(&result), 140 autorest.ByClosing()) 141 result.Response = autorest.Response{Response: resp} 142 return 143} 144