...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2016-03-01-preview/monitorlegacy/alertrules.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2016-03-01-preview/monitorlegacy

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

View as plain text