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/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// MetricBaselineClient is the monitor Management Client 19type MetricBaselineClient struct { 20 BaseClient 21} 22 23// NewMetricBaselineClient creates an instance of the MetricBaselineClient client. 24func NewMetricBaselineClient(subscriptionID string) MetricBaselineClient { 25 return NewMetricBaselineClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewMetricBaselineClientWithBaseURI creates an instance of the MetricBaselineClient client using a custom endpoint. 29// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewMetricBaselineClientWithBaseURI(baseURI string, subscriptionID string) MetricBaselineClient { 31 return MetricBaselineClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// CalculateBaseline **Lists the baseline values for a resource**. 35// Parameters: 36// resourceURI - the identifier of the resource. It has the following structure: 37// subscriptions/{subscriptionName}/resourceGroups/{resourceGroupName}/providers/{providerName}/{resourceName}. 38// For example: 39// subscriptions/b368ca2f-e298-46b7-b0ab-012281956afa/resourceGroups/vms/providers/Microsoft.Compute/virtualMachines/vm1 40// timeSeriesInformation - information that need to be specified to calculate a baseline on a time series. 41func (client MetricBaselineClient) CalculateBaseline(ctx context.Context, resourceURI string, timeSeriesInformation TimeSeriesInformation) (result CalculateBaselineResponse, err error) { 42 if tracing.IsEnabled() { 43 ctx = tracing.StartSpan(ctx, fqdn+"/MetricBaselineClient.CalculateBaseline") 44 defer func() { 45 sc := -1 46 if result.Response.Response != nil { 47 sc = result.Response.Response.StatusCode 48 } 49 tracing.EndSpan(ctx, sc, err) 50 }() 51 } 52 if err := validation.Validate([]validation.Validation{ 53 {TargetValue: timeSeriesInformation, 54 Constraints: []validation.Constraint{{Target: "timeSeriesInformation.Sensitivities", Name: validation.Null, Rule: true, Chain: nil}, 55 {Target: "timeSeriesInformation.Values", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 56 return result, validation.NewError("insights.MetricBaselineClient", "CalculateBaseline", err.Error()) 57 } 58 59 req, err := client.CalculateBaselinePreparer(ctx, resourceURI, timeSeriesInformation) 60 if err != nil { 61 err = autorest.NewErrorWithError(err, "insights.MetricBaselineClient", "CalculateBaseline", nil, "Failure preparing request") 62 return 63 } 64 65 resp, err := client.CalculateBaselineSender(req) 66 if err != nil { 67 result.Response = autorest.Response{Response: resp} 68 err = autorest.NewErrorWithError(err, "insights.MetricBaselineClient", "CalculateBaseline", resp, "Failure sending request") 69 return 70 } 71 72 result, err = client.CalculateBaselineResponder(resp) 73 if err != nil { 74 err = autorest.NewErrorWithError(err, "insights.MetricBaselineClient", "CalculateBaseline", resp, "Failure responding to request") 75 return 76 } 77 78 return 79} 80 81// CalculateBaselinePreparer prepares the CalculateBaseline request. 82func (client MetricBaselineClient) CalculateBaselinePreparer(ctx context.Context, resourceURI string, timeSeriesInformation TimeSeriesInformation) (*http.Request, error) { 83 pathParameters := map[string]interface{}{ 84 "resourceUri": resourceURI, 85 } 86 87 const APIVersion = "2017-11-01-preview" 88 queryParameters := map[string]interface{}{ 89 "api-version": APIVersion, 90 } 91 92 preparer := autorest.CreatePreparer( 93 autorest.AsContentType("application/json; charset=utf-8"), 94 autorest.AsPost(), 95 autorest.WithBaseURL(client.BaseURI), 96 autorest.WithPathParameters("/{resourceUri}/providers/microsoft.insights/calculatebaseline", pathParameters), 97 autorest.WithJSON(timeSeriesInformation), 98 autorest.WithQueryParameters(queryParameters)) 99 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 100} 101 102// CalculateBaselineSender sends the CalculateBaseline request. The method will close the 103// http.Response Body if it receives an error. 104func (client MetricBaselineClient) CalculateBaselineSender(req *http.Request) (*http.Response, error) { 105 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 106} 107 108// CalculateBaselineResponder handles the response to the CalculateBaseline request. The method always 109// closes the http.Response Body. 110func (client MetricBaselineClient) CalculateBaselineResponder(resp *http.Response) (result CalculateBaselineResponse, err error) { 111 err = autorest.Respond( 112 resp, 113 azure.WithErrorUnlessStatusCode(http.StatusOK), 114 autorest.ByUnmarshallingJSON(&result), 115 autorest.ByClosing()) 116 result.Response = autorest.Response{Response: resp} 117 return 118} 119 120// Get **Gets the baseline values for a specific metric**. 121// Parameters: 122// resourceURI - the identifier of the resource. It has the following structure: 123// subscriptions/{subscriptionName}/resourceGroups/{resourceGroupName}/providers/{providerName}/{resourceName}. 124// For example: 125// subscriptions/b368ca2f-e298-46b7-b0ab-012281956afa/resourceGroups/vms/providers/Microsoft.Compute/virtualMachines/vm1 126// metricName - the name of the metric to retrieve the baseline for. 127// timespan - the timespan of the query. It is a string with the following format 128// 'startDateTime_ISO/endDateTime_ISO'. 129// interval - the interval (i.e. timegrain) of the query. 130// aggregation - the aggregation type of the metric to retrieve the baseline for. 131// sensitivities - the list of sensitivities (comma separated) to retrieve. 132// resultType - allows retrieving only metadata of the baseline. On data request all information is retrieved. 133func (client MetricBaselineClient) Get(ctx context.Context, resourceURI string, metricName string, timespan string, interval *string, aggregation string, sensitivities string, resultType ResultType) (result BaselineResponse, err error) { 134 if tracing.IsEnabled() { 135 ctx = tracing.StartSpan(ctx, fqdn+"/MetricBaselineClient.Get") 136 defer func() { 137 sc := -1 138 if result.Response.Response != nil { 139 sc = result.Response.Response.StatusCode 140 } 141 tracing.EndSpan(ctx, sc, err) 142 }() 143 } 144 req, err := client.GetPreparer(ctx, resourceURI, metricName, timespan, interval, aggregation, sensitivities, resultType) 145 if err != nil { 146 err = autorest.NewErrorWithError(err, "insights.MetricBaselineClient", "Get", nil, "Failure preparing request") 147 return 148 } 149 150 resp, err := client.GetSender(req) 151 if err != nil { 152 result.Response = autorest.Response{Response: resp} 153 err = autorest.NewErrorWithError(err, "insights.MetricBaselineClient", "Get", resp, "Failure sending request") 154 return 155 } 156 157 result, err = client.GetResponder(resp) 158 if err != nil { 159 err = autorest.NewErrorWithError(err, "insights.MetricBaselineClient", "Get", resp, "Failure responding to request") 160 return 161 } 162 163 return 164} 165 166// GetPreparer prepares the Get request. 167func (client MetricBaselineClient) GetPreparer(ctx context.Context, resourceURI string, metricName string, timespan string, interval *string, aggregation string, sensitivities string, resultType ResultType) (*http.Request, error) { 168 pathParameters := map[string]interface{}{ 169 "metricName": autorest.Encode("path", metricName), 170 "resourceUri": resourceURI, 171 } 172 173 const APIVersion = "2017-11-01-preview" 174 queryParameters := map[string]interface{}{ 175 "api-version": APIVersion, 176 } 177 if len(timespan) > 0 { 178 queryParameters["timespan"] = autorest.Encode("query", timespan) 179 } 180 if interval != nil { 181 queryParameters["interval"] = autorest.Encode("query", *interval) 182 } 183 if len(aggregation) > 0 { 184 queryParameters["aggregation"] = autorest.Encode("query", aggregation) 185 } 186 if len(sensitivities) > 0 { 187 queryParameters["sensitivities"] = autorest.Encode("query", sensitivities) 188 } 189 if len(string(resultType)) > 0 { 190 queryParameters["resultType"] = autorest.Encode("query", resultType) 191 } 192 193 preparer := autorest.CreatePreparer( 194 autorest.AsGet(), 195 autorest.WithBaseURL(client.BaseURI), 196 autorest.WithPathParameters("/{resourceUri}/providers/microsoft.insights/baseline/{metricName}", pathParameters), 197 autorest.WithQueryParameters(queryParameters)) 198 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 199} 200 201// GetSender sends the Get request. The method will close the 202// http.Response Body if it receives an error. 203func (client MetricBaselineClient) GetSender(req *http.Request) (*http.Response, error) { 204 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 205} 206 207// GetResponder handles the response to the Get request. The method always 208// closes the http.Response Body. 209func (client MetricBaselineClient) GetResponder(resp *http.Response) (result BaselineResponse, err error) { 210 err = autorest.Respond( 211 resp, 212 azure.WithErrorUnlessStatusCode(http.StatusOK), 213 autorest.ByUnmarshallingJSON(&result), 214 autorest.ByClosing()) 215 result.Response = autorest.Response{Response: resp} 216 return 217} 218