...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2022-06-01-preview/insights/metricalerts.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2022-06-01-preview/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/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // MetricAlertsClient is the monitor Management Client
    19  type MetricAlertsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewMetricAlertsClient creates an instance of the MetricAlertsClient client.
    24  func NewMetricAlertsClient(subscriptionID string) MetricAlertsClient {
    25  	return NewMetricAlertsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewMetricAlertsClientWithBaseURI creates an instance of the MetricAlertsClient client using a custom endpoint.  Use
    29  // this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewMetricAlertsClientWithBaseURI(baseURI string, subscriptionID string) MetricAlertsClient {
    31  	return MetricAlertsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate create or update an metric alert definition.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group. The name is case insensitive.
    37  // ruleName - the name of the rule.
    38  // parameters - the parameters of the rule to create or update.
    39  func (client MetricAlertsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, ruleName string, parameters MetricAlertResource) (result MetricAlertResource, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsClient.CreateOrUpdate")
    42  		defer func() {
    43  			sc := -1
    44  			if result.Response.Response != nil {
    45  				sc = result.Response.Response.StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	if err := validation.Validate([]validation.Validation{
    51  		{TargetValue: client.SubscriptionID,
    52  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    53  		{TargetValue: resourceGroupName,
    54  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    55  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    56  		{TargetValue: parameters,
    57  			Constraints: []validation.Constraint{{Target: "parameters.MetricAlertProperties", Name: validation.Null, Rule: true,
    58  				Chain: []validation.Constraint{{Target: "parameters.MetricAlertProperties.Severity", Name: validation.Null, Rule: true, Chain: nil},
    59  					{Target: "parameters.MetricAlertProperties.Enabled", Name: validation.Null, Rule: true, Chain: nil},
    60  					{Target: "parameters.MetricAlertProperties.Scopes", Name: validation.Null, Rule: true, Chain: nil},
    61  					{Target: "parameters.MetricAlertProperties.EvaluationFrequency", Name: validation.Null, Rule: true, Chain: nil},
    62  					{Target: "parameters.MetricAlertProperties.WindowSize", Name: validation.Null, Rule: true, Chain: nil},
    63  				}}}}}); err != nil {
    64  		return result, validation.NewError("insights.MetricAlertsClient", "CreateOrUpdate", err.Error())
    65  	}
    66  
    67  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, ruleName, parameters)
    68  	if err != nil {
    69  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "CreateOrUpdate", nil, "Failure preparing request")
    70  		return
    71  	}
    72  
    73  	resp, err := client.CreateOrUpdateSender(req)
    74  	if err != nil {
    75  		result.Response = autorest.Response{Response: resp}
    76  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "CreateOrUpdate", resp, "Failure sending request")
    77  		return
    78  	}
    79  
    80  	result, err = client.CreateOrUpdateResponder(resp)
    81  	if err != nil {
    82  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "CreateOrUpdate", resp, "Failure responding to request")
    83  		return
    84  	}
    85  
    86  	return
    87  }
    88  
    89  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    90  func (client MetricAlertsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, ruleName string, parameters MetricAlertResource) (*http.Request, error) {
    91  	pathParameters := map[string]interface{}{
    92  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    93  		"ruleName":          autorest.Encode("path", ruleName),
    94  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    95  	}
    96  
    97  	const APIVersion = "2018-03-01"
    98  	queryParameters := map[string]interface{}{
    99  		"api-version": APIVersion,
   100  	}
   101  
   102  	preparer := autorest.CreatePreparer(
   103  		autorest.AsContentType("application/json; charset=utf-8"),
   104  		autorest.AsPut(),
   105  		autorest.WithBaseURL(client.BaseURI),
   106  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}", pathParameters),
   107  		autorest.WithJSON(parameters),
   108  		autorest.WithQueryParameters(queryParameters))
   109  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   110  }
   111  
   112  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   113  // http.Response Body if it receives an error.
   114  func (client MetricAlertsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   115  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   116  }
   117  
   118  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   119  // closes the http.Response Body.
   120  func (client MetricAlertsClient) CreateOrUpdateResponder(resp *http.Response) (result MetricAlertResource, err error) {
   121  	err = autorest.Respond(
   122  		resp,
   123  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   124  		autorest.ByUnmarshallingJSON(&result),
   125  		autorest.ByClosing())
   126  	result.Response = autorest.Response{Response: resp}
   127  	return
   128  }
   129  
   130  // Delete delete an alert rule definition.
   131  // Parameters:
   132  // resourceGroupName - the name of the resource group. The name is case insensitive.
   133  // ruleName - the name of the rule.
   134  func (client MetricAlertsClient) Delete(ctx context.Context, resourceGroupName string, ruleName string) (result autorest.Response, err error) {
   135  	if tracing.IsEnabled() {
   136  		ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsClient.Delete")
   137  		defer func() {
   138  			sc := -1
   139  			if result.Response != nil {
   140  				sc = result.Response.StatusCode
   141  			}
   142  			tracing.EndSpan(ctx, sc, err)
   143  		}()
   144  	}
   145  	if err := validation.Validate([]validation.Validation{
   146  		{TargetValue: client.SubscriptionID,
   147  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   148  		{TargetValue: resourceGroupName,
   149  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   150  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   151  		return result, validation.NewError("insights.MetricAlertsClient", "Delete", err.Error())
   152  	}
   153  
   154  	req, err := client.DeletePreparer(ctx, resourceGroupName, ruleName)
   155  	if err != nil {
   156  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Delete", nil, "Failure preparing request")
   157  		return
   158  	}
   159  
   160  	resp, err := client.DeleteSender(req)
   161  	if err != nil {
   162  		result.Response = resp
   163  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Delete", resp, "Failure sending request")
   164  		return
   165  	}
   166  
   167  	result, err = client.DeleteResponder(resp)
   168  	if err != nil {
   169  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Delete", resp, "Failure responding to request")
   170  		return
   171  	}
   172  
   173  	return
   174  }
   175  
   176  // DeletePreparer prepares the Delete request.
   177  func (client MetricAlertsClient) DeletePreparer(ctx context.Context, resourceGroupName string, ruleName string) (*http.Request, error) {
   178  	pathParameters := map[string]interface{}{
   179  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   180  		"ruleName":          autorest.Encode("path", ruleName),
   181  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   182  	}
   183  
   184  	const APIVersion = "2018-03-01"
   185  	queryParameters := map[string]interface{}{
   186  		"api-version": APIVersion,
   187  	}
   188  
   189  	preparer := autorest.CreatePreparer(
   190  		autorest.AsDelete(),
   191  		autorest.WithBaseURL(client.BaseURI),
   192  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}", pathParameters),
   193  		autorest.WithQueryParameters(queryParameters))
   194  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   195  }
   196  
   197  // DeleteSender sends the Delete request. The method will close the
   198  // http.Response Body if it receives an error.
   199  func (client MetricAlertsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   200  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   201  }
   202  
   203  // DeleteResponder handles the response to the Delete request. The method always
   204  // closes the http.Response Body.
   205  func (client MetricAlertsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   206  	err = autorest.Respond(
   207  		resp,
   208  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   209  		autorest.ByClosing())
   210  	result.Response = resp
   211  	return
   212  }
   213  
   214  // Get retrieve an alert rule definition.
   215  // Parameters:
   216  // resourceGroupName - the name of the resource group. The name is case insensitive.
   217  // ruleName - the name of the rule.
   218  func (client MetricAlertsClient) Get(ctx context.Context, resourceGroupName string, ruleName string) (result MetricAlertResource, err error) {
   219  	if tracing.IsEnabled() {
   220  		ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsClient.Get")
   221  		defer func() {
   222  			sc := -1
   223  			if result.Response.Response != nil {
   224  				sc = result.Response.Response.StatusCode
   225  			}
   226  			tracing.EndSpan(ctx, sc, err)
   227  		}()
   228  	}
   229  	if err := validation.Validate([]validation.Validation{
   230  		{TargetValue: client.SubscriptionID,
   231  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   232  		{TargetValue: resourceGroupName,
   233  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   234  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   235  		return result, validation.NewError("insights.MetricAlertsClient", "Get", err.Error())
   236  	}
   237  
   238  	req, err := client.GetPreparer(ctx, resourceGroupName, ruleName)
   239  	if err != nil {
   240  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Get", nil, "Failure preparing request")
   241  		return
   242  	}
   243  
   244  	resp, err := client.GetSender(req)
   245  	if err != nil {
   246  		result.Response = autorest.Response{Response: resp}
   247  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Get", resp, "Failure sending request")
   248  		return
   249  	}
   250  
   251  	result, err = client.GetResponder(resp)
   252  	if err != nil {
   253  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Get", resp, "Failure responding to request")
   254  		return
   255  	}
   256  
   257  	return
   258  }
   259  
   260  // GetPreparer prepares the Get request.
   261  func (client MetricAlertsClient) GetPreparer(ctx context.Context, resourceGroupName string, ruleName string) (*http.Request, error) {
   262  	pathParameters := map[string]interface{}{
   263  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   264  		"ruleName":          autorest.Encode("path", ruleName),
   265  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   266  	}
   267  
   268  	const APIVersion = "2018-03-01"
   269  	queryParameters := map[string]interface{}{
   270  		"api-version": APIVersion,
   271  	}
   272  
   273  	preparer := autorest.CreatePreparer(
   274  		autorest.AsGet(),
   275  		autorest.WithBaseURL(client.BaseURI),
   276  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}", pathParameters),
   277  		autorest.WithQueryParameters(queryParameters))
   278  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   279  }
   280  
   281  // GetSender sends the Get request. The method will close the
   282  // http.Response Body if it receives an error.
   283  func (client MetricAlertsClient) GetSender(req *http.Request) (*http.Response, error) {
   284  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   285  }
   286  
   287  // GetResponder handles the response to the Get request. The method always
   288  // closes the http.Response Body.
   289  func (client MetricAlertsClient) GetResponder(resp *http.Response) (result MetricAlertResource, err error) {
   290  	err = autorest.Respond(
   291  		resp,
   292  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   293  		autorest.ByUnmarshallingJSON(&result),
   294  		autorest.ByClosing())
   295  	result.Response = autorest.Response{Response: resp}
   296  	return
   297  }
   298  
   299  // ListByResourceGroup retrieve alert rule definitions in a resource group.
   300  // Parameters:
   301  // resourceGroupName - the name of the resource group. The name is case insensitive.
   302  func (client MetricAlertsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result MetricAlertResourceCollection, err error) {
   303  	if tracing.IsEnabled() {
   304  		ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsClient.ListByResourceGroup")
   305  		defer func() {
   306  			sc := -1
   307  			if result.Response.Response != nil {
   308  				sc = result.Response.Response.StatusCode
   309  			}
   310  			tracing.EndSpan(ctx, sc, err)
   311  		}()
   312  	}
   313  	if err := validation.Validate([]validation.Validation{
   314  		{TargetValue: client.SubscriptionID,
   315  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   316  		{TargetValue: resourceGroupName,
   317  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   318  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   319  		return result, validation.NewError("insights.MetricAlertsClient", "ListByResourceGroup", err.Error())
   320  	}
   321  
   322  	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
   323  	if err != nil {
   324  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "ListByResourceGroup", nil, "Failure preparing request")
   325  		return
   326  	}
   327  
   328  	resp, err := client.ListByResourceGroupSender(req)
   329  	if err != nil {
   330  		result.Response = autorest.Response{Response: resp}
   331  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "ListByResourceGroup", resp, "Failure sending request")
   332  		return
   333  	}
   334  
   335  	result, err = client.ListByResourceGroupResponder(resp)
   336  	if err != nil {
   337  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "ListByResourceGroup", resp, "Failure responding to request")
   338  		return
   339  	}
   340  
   341  	return
   342  }
   343  
   344  // ListByResourceGroupPreparer prepares the ListByResourceGroup request.
   345  func (client MetricAlertsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
   346  	pathParameters := map[string]interface{}{
   347  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   348  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   349  	}
   350  
   351  	const APIVersion = "2018-03-01"
   352  	queryParameters := map[string]interface{}{
   353  		"api-version": APIVersion,
   354  	}
   355  
   356  	preparer := autorest.CreatePreparer(
   357  		autorest.AsGet(),
   358  		autorest.WithBaseURL(client.BaseURI),
   359  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts", pathParameters),
   360  		autorest.WithQueryParameters(queryParameters))
   361  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   362  }
   363  
   364  // ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
   365  // http.Response Body if it receives an error.
   366  func (client MetricAlertsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
   367  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   368  }
   369  
   370  // ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
   371  // closes the http.Response Body.
   372  func (client MetricAlertsClient) ListByResourceGroupResponder(resp *http.Response) (result MetricAlertResourceCollection, err error) {
   373  	err = autorest.Respond(
   374  		resp,
   375  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   376  		autorest.ByUnmarshallingJSON(&result),
   377  		autorest.ByClosing())
   378  	result.Response = autorest.Response{Response: resp}
   379  	return
   380  }
   381  
   382  // ListBySubscription retrieve alert rule definitions in a subscription.
   383  func (client MetricAlertsClient) ListBySubscription(ctx context.Context) (result MetricAlertResourceCollection, err error) {
   384  	if tracing.IsEnabled() {
   385  		ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsClient.ListBySubscription")
   386  		defer func() {
   387  			sc := -1
   388  			if result.Response.Response != nil {
   389  				sc = result.Response.Response.StatusCode
   390  			}
   391  			tracing.EndSpan(ctx, sc, err)
   392  		}()
   393  	}
   394  	if err := validation.Validate([]validation.Validation{
   395  		{TargetValue: client.SubscriptionID,
   396  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   397  		return result, validation.NewError("insights.MetricAlertsClient", "ListBySubscription", err.Error())
   398  	}
   399  
   400  	req, err := client.ListBySubscriptionPreparer(ctx)
   401  	if err != nil {
   402  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "ListBySubscription", nil, "Failure preparing request")
   403  		return
   404  	}
   405  
   406  	resp, err := client.ListBySubscriptionSender(req)
   407  	if err != nil {
   408  		result.Response = autorest.Response{Response: resp}
   409  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "ListBySubscription", resp, "Failure sending request")
   410  		return
   411  	}
   412  
   413  	result, err = client.ListBySubscriptionResponder(resp)
   414  	if err != nil {
   415  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "ListBySubscription", resp, "Failure responding to request")
   416  		return
   417  	}
   418  
   419  	return
   420  }
   421  
   422  // ListBySubscriptionPreparer prepares the ListBySubscription request.
   423  func (client MetricAlertsClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) {
   424  	pathParameters := map[string]interface{}{
   425  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   426  	}
   427  
   428  	const APIVersion = "2018-03-01"
   429  	queryParameters := map[string]interface{}{
   430  		"api-version": APIVersion,
   431  	}
   432  
   433  	preparer := autorest.CreatePreparer(
   434  		autorest.AsGet(),
   435  		autorest.WithBaseURL(client.BaseURI),
   436  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Insights/metricAlerts", pathParameters),
   437  		autorest.WithQueryParameters(queryParameters))
   438  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   439  }
   440  
   441  // ListBySubscriptionSender sends the ListBySubscription request. The method will close the
   442  // http.Response Body if it receives an error.
   443  func (client MetricAlertsClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
   444  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   445  }
   446  
   447  // ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always
   448  // closes the http.Response Body.
   449  func (client MetricAlertsClient) ListBySubscriptionResponder(resp *http.Response) (result MetricAlertResourceCollection, err error) {
   450  	err = autorest.Respond(
   451  		resp,
   452  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   453  		autorest.ByUnmarshallingJSON(&result),
   454  		autorest.ByClosing())
   455  	result.Response = autorest.Response{Response: resp}
   456  	return
   457  }
   458  
   459  // Update update an metric alert definition.
   460  // Parameters:
   461  // resourceGroupName - the name of the resource group. The name is case insensitive.
   462  // ruleName - the name of the rule.
   463  // parameters - the parameters of the rule to update.
   464  func (client MetricAlertsClient) Update(ctx context.Context, resourceGroupName string, ruleName string, parameters MetricAlertResourcePatch) (result MetricAlertResource, err error) {
   465  	if tracing.IsEnabled() {
   466  		ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsClient.Update")
   467  		defer func() {
   468  			sc := -1
   469  			if result.Response.Response != nil {
   470  				sc = result.Response.Response.StatusCode
   471  			}
   472  			tracing.EndSpan(ctx, sc, err)
   473  		}()
   474  	}
   475  	if err := validation.Validate([]validation.Validation{
   476  		{TargetValue: client.SubscriptionID,
   477  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   478  		{TargetValue: resourceGroupName,
   479  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   480  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   481  		return result, validation.NewError("insights.MetricAlertsClient", "Update", err.Error())
   482  	}
   483  
   484  	req, err := client.UpdatePreparer(ctx, resourceGroupName, ruleName, parameters)
   485  	if err != nil {
   486  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Update", nil, "Failure preparing request")
   487  		return
   488  	}
   489  
   490  	resp, err := client.UpdateSender(req)
   491  	if err != nil {
   492  		result.Response = autorest.Response{Response: resp}
   493  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Update", resp, "Failure sending request")
   494  		return
   495  	}
   496  
   497  	result, err = client.UpdateResponder(resp)
   498  	if err != nil {
   499  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Update", resp, "Failure responding to request")
   500  		return
   501  	}
   502  
   503  	return
   504  }
   505  
   506  // UpdatePreparer prepares the Update request.
   507  func (client MetricAlertsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, ruleName string, parameters MetricAlertResourcePatch) (*http.Request, error) {
   508  	pathParameters := map[string]interface{}{
   509  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   510  		"ruleName":          autorest.Encode("path", ruleName),
   511  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   512  	}
   513  
   514  	const APIVersion = "2018-03-01"
   515  	queryParameters := map[string]interface{}{
   516  		"api-version": APIVersion,
   517  	}
   518  
   519  	preparer := autorest.CreatePreparer(
   520  		autorest.AsContentType("application/json; charset=utf-8"),
   521  		autorest.AsPatch(),
   522  		autorest.WithBaseURL(client.BaseURI),
   523  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}", pathParameters),
   524  		autorest.WithJSON(parameters),
   525  		autorest.WithQueryParameters(queryParameters))
   526  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   527  }
   528  
   529  // UpdateSender sends the Update request. The method will close the
   530  // http.Response Body if it receives an error.
   531  func (client MetricAlertsClient) UpdateSender(req *http.Request) (*http.Response, error) {
   532  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   533  }
   534  
   535  // UpdateResponder handles the response to the Update request. The method always
   536  // closes the http.Response Body.
   537  func (client MetricAlertsClient) UpdateResponder(resp *http.Response) (result MetricAlertResource, err error) {
   538  	err = autorest.Respond(
   539  		resp,
   540  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   541  		autorest.ByUnmarshallingJSON(&result),
   542  		autorest.ByClosing())
   543  	result.Response = autorest.Response{Response: resp}
   544  	return
   545  }
   546  

View as plain text