...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2016-03-01-preview/monitorlegacy/alertruleincidents.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  // AlertRuleIncidentsClient is the monitor Management Client
    19  type AlertRuleIncidentsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewAlertRuleIncidentsClient creates an instance of the AlertRuleIncidentsClient client.
    24  func NewAlertRuleIncidentsClient(subscriptionID string) AlertRuleIncidentsClient {
    25  	return NewAlertRuleIncidentsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewAlertRuleIncidentsClientWithBaseURI creates an instance of the AlertRuleIncidentsClient 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 NewAlertRuleIncidentsClientWithBaseURI(baseURI string, subscriptionID string) AlertRuleIncidentsClient {
    32  	return AlertRuleIncidentsClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // Get gets an incident associated to an alert rule
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group. The name is case insensitive.
    38  // ruleName - the name of the rule.
    39  // incidentName - the name of the incident to retrieve.
    40  func (client AlertRuleIncidentsClient) Get(ctx context.Context, resourceGroupName string, ruleName string, incidentName string) (result Incident, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/AlertRuleIncidentsClient.Get")
    43  		defer func() {
    44  			sc := -1
    45  			if result.Response.Response != nil {
    46  				sc = result.Response.Response.StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	if err := validation.Validate([]validation.Validation{
    52  		{TargetValue: resourceGroupName,
    53  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    54  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    55  		{TargetValue: client.SubscriptionID,
    56  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
    57  		return result, validation.NewError("monitorlegacy.AlertRuleIncidentsClient", "Get", err.Error())
    58  	}
    59  
    60  	req, err := client.GetPreparer(ctx, resourceGroupName, ruleName, incidentName)
    61  	if err != nil {
    62  		err = autorest.NewErrorWithError(err, "monitorlegacy.AlertRuleIncidentsClient", "Get", nil, "Failure preparing request")
    63  		return
    64  	}
    65  
    66  	resp, err := client.GetSender(req)
    67  	if err != nil {
    68  		result.Response = autorest.Response{Response: resp}
    69  		err = autorest.NewErrorWithError(err, "monitorlegacy.AlertRuleIncidentsClient", "Get", resp, "Failure sending request")
    70  		return
    71  	}
    72  
    73  	result, err = client.GetResponder(resp)
    74  	if err != nil {
    75  		err = autorest.NewErrorWithError(err, "monitorlegacy.AlertRuleIncidentsClient", "Get", resp, "Failure responding to request")
    76  		return
    77  	}
    78  
    79  	return
    80  }
    81  
    82  // GetPreparer prepares the Get request.
    83  func (client AlertRuleIncidentsClient) GetPreparer(ctx context.Context, resourceGroupName string, ruleName string, incidentName string) (*http.Request, error) {
    84  	pathParameters := map[string]interface{}{
    85  		"incidentName":      autorest.Encode("path", incidentName),
    86  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    87  		"ruleName":          autorest.Encode("path", ruleName),
    88  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    89  	}
    90  
    91  	const APIVersion = "2016-03-01"
    92  	queryParameters := map[string]interface{}{
    93  		"api-version": APIVersion,
    94  	}
    95  
    96  	preparer := autorest.CreatePreparer(
    97  		autorest.AsGet(),
    98  		autorest.WithBaseURL(client.BaseURI),
    99  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/alertrules/{ruleName}/incidents/{incidentName}", pathParameters),
   100  		autorest.WithQueryParameters(queryParameters))
   101  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   102  }
   103  
   104  // GetSender sends the Get request. The method will close the
   105  // http.Response Body if it receives an error.
   106  func (client AlertRuleIncidentsClient) GetSender(req *http.Request) (*http.Response, error) {
   107  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   108  }
   109  
   110  // GetResponder handles the response to the Get request. The method always
   111  // closes the http.Response Body.
   112  func (client AlertRuleIncidentsClient) GetResponder(resp *http.Response) (result Incident, err error) {
   113  	err = autorest.Respond(
   114  		resp,
   115  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   116  		autorest.ByUnmarshallingJSON(&result),
   117  		autorest.ByClosing())
   118  	result.Response = autorest.Response{Response: resp}
   119  	return
   120  }
   121  
   122  // ListByAlertRule gets a list of incidents associated to an alert rule
   123  // Parameters:
   124  // resourceGroupName - the name of the resource group. The name is case insensitive.
   125  // ruleName - the name of the rule.
   126  func (client AlertRuleIncidentsClient) ListByAlertRule(ctx context.Context, resourceGroupName string, ruleName string) (result IncidentListResult, err error) {
   127  	if tracing.IsEnabled() {
   128  		ctx = tracing.StartSpan(ctx, fqdn+"/AlertRuleIncidentsClient.ListByAlertRule")
   129  		defer func() {
   130  			sc := -1
   131  			if result.Response.Response != nil {
   132  				sc = result.Response.Response.StatusCode
   133  			}
   134  			tracing.EndSpan(ctx, sc, err)
   135  		}()
   136  	}
   137  	if err := validation.Validate([]validation.Validation{
   138  		{TargetValue: resourceGroupName,
   139  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   140  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   141  		{TargetValue: client.SubscriptionID,
   142  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   143  		return result, validation.NewError("monitorlegacy.AlertRuleIncidentsClient", "ListByAlertRule", err.Error())
   144  	}
   145  
   146  	req, err := client.ListByAlertRulePreparer(ctx, resourceGroupName, ruleName)
   147  	if err != nil {
   148  		err = autorest.NewErrorWithError(err, "monitorlegacy.AlertRuleIncidentsClient", "ListByAlertRule", nil, "Failure preparing request")
   149  		return
   150  	}
   151  
   152  	resp, err := client.ListByAlertRuleSender(req)
   153  	if err != nil {
   154  		result.Response = autorest.Response{Response: resp}
   155  		err = autorest.NewErrorWithError(err, "monitorlegacy.AlertRuleIncidentsClient", "ListByAlertRule", resp, "Failure sending request")
   156  		return
   157  	}
   158  
   159  	result, err = client.ListByAlertRuleResponder(resp)
   160  	if err != nil {
   161  		err = autorest.NewErrorWithError(err, "monitorlegacy.AlertRuleIncidentsClient", "ListByAlertRule", resp, "Failure responding to request")
   162  		return
   163  	}
   164  
   165  	return
   166  }
   167  
   168  // ListByAlertRulePreparer prepares the ListByAlertRule request.
   169  func (client AlertRuleIncidentsClient) ListByAlertRulePreparer(ctx context.Context, resourceGroupName string, ruleName string) (*http.Request, error) {
   170  	pathParameters := map[string]interface{}{
   171  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   172  		"ruleName":          autorest.Encode("path", ruleName),
   173  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   174  	}
   175  
   176  	const APIVersion = "2016-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/alertrules/{ruleName}/incidents", pathParameters),
   185  		autorest.WithQueryParameters(queryParameters))
   186  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   187  }
   188  
   189  // ListByAlertRuleSender sends the ListByAlertRule request. The method will close the
   190  // http.Response Body if it receives an error.
   191  func (client AlertRuleIncidentsClient) ListByAlertRuleSender(req *http.Request) (*http.Response, error) {
   192  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   193  }
   194  
   195  // ListByAlertRuleResponder handles the response to the ListByAlertRule request. The method always
   196  // closes the http.Response Body.
   197  func (client AlertRuleIncidentsClient) ListByAlertRuleResponder(resp *http.Response) (result IncidentListResult, 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