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 } 77 78 return 79} 80 81// ListPreparer prepares the List request. 82func (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. 104func (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. 110func (client MetricAlertsStatusClient) ListResponder(resp *http.Response) (result MetricAlertStatusCollection, err error) { 111 err = autorest.Respond( 112 resp, 113 client.ByInspecting(), 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 } 154 155 return 156} 157 158// ListByNamePreparer prepares the ListByName request. 159func (client MetricAlertsStatusClient) ListByNamePreparer(ctx context.Context, resourceGroupName string, ruleName string, statusName string) (*http.Request, error) { 160 pathParameters := map[string]interface{}{ 161 "resourceGroupName": autorest.Encode("path", resourceGroupName), 162 "ruleName": autorest.Encode("path", ruleName), 163 "statusName": autorest.Encode("path", statusName), 164 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 165 } 166 167 const APIVersion = "2018-03-01" 168 queryParameters := map[string]interface{}{ 169 "api-version": APIVersion, 170 } 171 172 preparer := autorest.CreatePreparer( 173 autorest.AsGet(), 174 autorest.WithBaseURL(client.BaseURI), 175 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}/status/{statusName}", pathParameters), 176 autorest.WithQueryParameters(queryParameters)) 177 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 178} 179 180// ListByNameSender sends the ListByName request. The method will close the 181// http.Response Body if it receives an error. 182func (client MetricAlertsStatusClient) ListByNameSender(req *http.Request) (*http.Response, error) { 183 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 184} 185 186// ListByNameResponder handles the response to the ListByName request. The method always 187// closes the http.Response Body. 188func (client MetricAlertsStatusClient) ListByNameResponder(resp *http.Response) (result MetricAlertStatusCollection, err error) { 189 err = autorest.Respond( 190 resp, 191 client.ByInspecting(), 192 azure.WithErrorUnlessStatusCode(http.StatusOK), 193 autorest.ByUnmarshallingJSON(&result), 194 autorest.ByClosing()) 195 result.Response = autorest.Response{Response: resp} 196 return 197} 198