...

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

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

View as plain text