...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2022-10-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  // MetricAlertsStatusClient is the monitor Management Client
    19  type MetricAlertsStatusClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewMetricAlertsStatusClient creates an instance of the MetricAlertsStatusClient client.
    24  func NewMetricAlertsStatusClient(subscriptionID string) MetricAlertsStatusClient {
    25  	return NewMetricAlertsStatusClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewMetricAlertsStatusClientWithBaseURI creates an instance of the MetricAlertsStatusClient client using a custom
    29  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    30  // stack).
    31  func NewMetricAlertsStatusClientWithBaseURI(baseURI string, subscriptionID string) MetricAlertsStatusClient {
    32  	return MetricAlertsStatusClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // List retrieve an alert rule status.
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group. The name is case insensitive.
    38  // ruleName - the name of the rule.
    39  func (client MetricAlertsStatusClient) List(ctx context.Context, resourceGroupName string, ruleName string) (result MetricAlertStatusCollection, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsStatusClient.List")
    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}}}}); err != nil {
    56  		return result, validation.NewError("insights.MetricAlertsStatusClient", "List", err.Error())
    57  	}
    58  
    59  	req, err := client.ListPreparer(ctx, resourceGroupName, ruleName)
    60  	if err != nil {
    61  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsStatusClient", "List", nil, "Failure preparing request")
    62  		return
    63  	}
    64  
    65  	resp, err := client.ListSender(req)
    66  	if err != nil {
    67  		result.Response = autorest.Response{Response: resp}
    68  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsStatusClient", "List", resp, "Failure sending request")
    69  		return
    70  	}
    71  
    72  	result, err = client.ListResponder(resp)
    73  	if err != nil {
    74  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsStatusClient", "List", resp, "Failure responding to request")
    75  		return
    76  	}
    77  
    78  	return
    79  }
    80  
    81  // ListPreparer prepares the List request.
    82  func (client MetricAlertsStatusClient) ListPreparer(ctx context.Context, resourceGroupName string, ruleName string) (*http.Request, error) {
    83  	pathParameters := map[string]interface{}{
    84  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    85  		"ruleName":          autorest.Encode("path", ruleName),
    86  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    87  	}
    88  
    89  	const APIVersion = "2018-03-01"
    90  	queryParameters := map[string]interface{}{
    91  		"api-version": APIVersion,
    92  	}
    93  
    94  	preparer := autorest.CreatePreparer(
    95  		autorest.AsGet(),
    96  		autorest.WithBaseURL(client.BaseURI),
    97  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}/status", pathParameters),
    98  		autorest.WithQueryParameters(queryParameters))
    99  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   100  }
   101  
   102  // ListSender sends the List request. The method will close the
   103  // http.Response Body if it receives an error.
   104  func (client MetricAlertsStatusClient) ListSender(req *http.Request) (*http.Response, error) {
   105  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   106  }
   107  
   108  // ListResponder handles the response to the List request. The method always
   109  // closes the http.Response Body.
   110  func (client MetricAlertsStatusClient) ListResponder(resp *http.Response) (result MetricAlertStatusCollection, 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  // ListByName retrieve an alert rule status.
   121  // Parameters:
   122  // resourceGroupName - the name of the resource group. The name is case insensitive.
   123  // ruleName - the name of the rule.
   124  // statusName - the name of the status.
   125  func (client MetricAlertsStatusClient) ListByName(ctx context.Context, resourceGroupName string, ruleName string, statusName string) (result MetricAlertStatusCollection, err error) {
   126  	if tracing.IsEnabled() {
   127  		ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsStatusClient.ListByName")
   128  		defer func() {
   129  			sc := -1
   130  			if result.Response.Response != nil {
   131  				sc = result.Response.Response.StatusCode
   132  			}
   133  			tracing.EndSpan(ctx, sc, err)
   134  		}()
   135  	}
   136  	if err := validation.Validate([]validation.Validation{
   137  		{TargetValue: client.SubscriptionID,
   138  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   139  		{TargetValue: resourceGroupName,
   140  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   141  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   142  		return result, validation.NewError("insights.MetricAlertsStatusClient", "ListByName", err.Error())
   143  	}
   144  
   145  	req, err := client.ListByNamePreparer(ctx, resourceGroupName, ruleName, statusName)
   146  	if err != nil {
   147  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsStatusClient", "ListByName", nil, "Failure preparing request")
   148  		return
   149  	}
   150  
   151  	resp, err := client.ListByNameSender(req)
   152  	if err != nil {
   153  		result.Response = autorest.Response{Response: resp}
   154  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsStatusClient", "ListByName", resp, "Failure sending request")
   155  		return
   156  	}
   157  
   158  	result, err = client.ListByNameResponder(resp)
   159  	if err != nil {
   160  		err = autorest.NewErrorWithError(err, "insights.MetricAlertsStatusClient", "ListByName", resp, "Failure responding to request")
   161  		return
   162  	}
   163  
   164  	return
   165  }
   166  
   167  // ListByNamePreparer prepares the ListByName request.
   168  func (client MetricAlertsStatusClient) ListByNamePreparer(ctx context.Context, resourceGroupName string, ruleName string, statusName string) (*http.Request, error) {
   169  	pathParameters := map[string]interface{}{
   170  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   171  		"ruleName":          autorest.Encode("path", ruleName),
   172  		"statusName":        autorest.Encode("path", statusName),
   173  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   174  	}
   175  
   176  	const APIVersion = "2018-03-01"
   177  	queryParameters := map[string]interface{}{
   178  		"api-version": APIVersion,
   179  	}
   180  
   181  	preparer := autorest.CreatePreparer(
   182  		autorest.AsGet(),
   183  		autorest.WithBaseURL(client.BaseURI),
   184  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}/status/{statusName}", pathParameters),
   185  		autorest.WithQueryParameters(queryParameters))
   186  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   187  }
   188  
   189  // ListByNameSender sends the ListByName request. The method will close the
   190  // http.Response Body if it receives an error.
   191  func (client MetricAlertsStatusClient) ListByNameSender(req *http.Request) (*http.Response, error) {
   192  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   193  }
   194  
   195  // ListByNameResponder handles the response to the ListByName request. The method always
   196  // closes the http.Response Body.
   197  func (client MetricAlertsStatusClient) ListByNameResponder(resp *http.Response) (result MetricAlertStatusCollection, err error) {
   198  	err = autorest.Respond(
   199  		resp,
   200  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   201  		autorest.ByUnmarshallingJSON(&result),
   202  		autorest.ByClosing())
   203  	result.Response = autorest.Response{Response: resp}
   204  	return
   205  }
   206  

View as plain text