1package insights 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/tracing" 25 "net/http" 26) 27 28// MetricAlertsStatusClient is the monitor Management Client 29type MetricAlertsStatusClient struct { 30 BaseClient 31} 32 33// NewMetricAlertsStatusClient creates an instance of the MetricAlertsStatusClient client. 34func NewMetricAlertsStatusClient(subscriptionID string) MetricAlertsStatusClient { 35 return NewMetricAlertsStatusClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewMetricAlertsStatusClientWithBaseURI creates an instance of the MetricAlertsStatusClient client using a custom 39// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 40// stack). 41func NewMetricAlertsStatusClientWithBaseURI(baseURI string, subscriptionID string) MetricAlertsStatusClient { 42 return MetricAlertsStatusClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// List retrieve an alert rule status. 46// Parameters: 47// resourceGroupName - the name of the resource group. 48// ruleName - the name of the rule. 49func (client MetricAlertsStatusClient) List(ctx context.Context, resourceGroupName string, ruleName string) (result MetricAlertStatusCollection, err error) { 50 if tracing.IsEnabled() { 51 ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsStatusClient.List") 52 defer func() { 53 sc := -1 54 if result.Response.Response != nil { 55 sc = result.Response.Response.StatusCode 56 } 57 tracing.EndSpan(ctx, sc, err) 58 }() 59 } 60 req, err := client.ListPreparer(ctx, resourceGroupName, ruleName) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "insights.MetricAlertsStatusClient", "List", nil, "Failure preparing request") 63 return 64 } 65 66 resp, err := client.ListSender(req) 67 if err != nil { 68 result.Response = autorest.Response{Response: resp} 69 err = autorest.NewErrorWithError(err, "insights.MetricAlertsStatusClient", "List", resp, "Failure sending request") 70 return 71 } 72 73 result, err = client.ListResponder(resp) 74 if err != nil { 75 err = autorest.NewErrorWithError(err, "insights.MetricAlertsStatusClient", "List", resp, "Failure responding to request") 76 return 77 } 78 79 return 80} 81 82// ListPreparer prepares the List request. 83func (client MetricAlertsStatusClient) ListPreparer(ctx context.Context, resourceGroupName string, ruleName string) (*http.Request, error) { 84 pathParameters := map[string]interface{}{ 85 "resourceGroupName": autorest.Encode("path", resourceGroupName), 86 "ruleName": autorest.Encode("path", ruleName), 87 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 88 } 89 90 const APIVersion = "2018-03-01" 91 queryParameters := map[string]interface{}{ 92 "api-version": APIVersion, 93 } 94 95 preparer := autorest.CreatePreparer( 96 autorest.AsGet(), 97 autorest.WithBaseURL(client.BaseURI), 98 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}/status", pathParameters), 99 autorest.WithQueryParameters(queryParameters)) 100 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 101} 102 103// ListSender sends the List request. The method will close the 104// http.Response Body if it receives an error. 105func (client MetricAlertsStatusClient) ListSender(req *http.Request) (*http.Response, error) { 106 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 107} 108 109// ListResponder handles the response to the List request. The method always 110// closes the http.Response Body. 111func (client MetricAlertsStatusClient) ListResponder(resp *http.Response) (result MetricAlertStatusCollection, err error) { 112 err = autorest.Respond( 113 resp, 114 azure.WithErrorUnlessStatusCode(http.StatusOK), 115 autorest.ByUnmarshallingJSON(&result), 116 autorest.ByClosing()) 117 result.Response = autorest.Response{Response: resp} 118 return 119} 120 121// ListByName retrieve an alert rule status. 122// Parameters: 123// resourceGroupName - the name of the resource group. 124// ruleName - the name of the rule. 125// statusName - the name of the status. 126func (client MetricAlertsStatusClient) ListByName(ctx context.Context, resourceGroupName string, ruleName string, statusName string) (result MetricAlertStatusCollection, err error) { 127 if tracing.IsEnabled() { 128 ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsStatusClient.ListByName") 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 req, err := client.ListByNamePreparer(ctx, resourceGroupName, ruleName, statusName) 138 if err != nil { 139 err = autorest.NewErrorWithError(err, "insights.MetricAlertsStatusClient", "ListByName", nil, "Failure preparing request") 140 return 141 } 142 143 resp, err := client.ListByNameSender(req) 144 if err != nil { 145 result.Response = autorest.Response{Response: resp} 146 err = autorest.NewErrorWithError(err, "insights.MetricAlertsStatusClient", "ListByName", resp, "Failure sending request") 147 return 148 } 149 150 result, err = client.ListByNameResponder(resp) 151 if err != nil { 152 err = autorest.NewErrorWithError(err, "insights.MetricAlertsStatusClient", "ListByName", resp, "Failure responding to request") 153 return 154 } 155 156 return 157} 158 159// ListByNamePreparer prepares the ListByName request. 160func (client MetricAlertsStatusClient) ListByNamePreparer(ctx context.Context, resourceGroupName string, ruleName string, statusName string) (*http.Request, error) { 161 pathParameters := map[string]interface{}{ 162 "resourceGroupName": autorest.Encode("path", resourceGroupName), 163 "ruleName": autorest.Encode("path", ruleName), 164 "statusName": autorest.Encode("path", statusName), 165 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 166 } 167 168 const APIVersion = "2018-03-01" 169 queryParameters := map[string]interface{}{ 170 "api-version": APIVersion, 171 } 172 173 preparer := autorest.CreatePreparer( 174 autorest.AsGet(), 175 autorest.WithBaseURL(client.BaseURI), 176 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}/status/{statusName}", pathParameters), 177 autorest.WithQueryParameters(queryParameters)) 178 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 179} 180 181// ListByNameSender sends the ListByName request. The method will close the 182// http.Response Body if it receives an error. 183func (client MetricAlertsStatusClient) ListByNameSender(req *http.Request) (*http.Response, error) { 184 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 185} 186 187// ListByNameResponder handles the response to the ListByName request. The method always 188// closes the http.Response Body. 189func (client MetricAlertsStatusClient) ListByNameResponder(resp *http.Response) (result MetricAlertStatusCollection, err error) { 190 err = autorest.Respond( 191 resp, 192 azure.WithErrorUnlessStatusCode(http.StatusOK), 193 autorest.ByUnmarshallingJSON(&result), 194 autorest.ByClosing()) 195 result.Response = autorest.Response{Response: resp} 196 return 197} 198