1package infrastructureinsights 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 "net/http" 25) 26 27// AlertsClient is the infrastructureInsights Admin Client 28type AlertsClient struct { 29 BaseClient 30} 31 32// NewAlertsClient creates an instance of the AlertsClient client. 33func NewAlertsClient(subscriptionID string) AlertsClient { 34 return NewAlertsClientWithBaseURI(DefaultBaseURI, subscriptionID) 35} 36 37// NewAlertsClientWithBaseURI creates an instance of the AlertsClient client. 38func NewAlertsClientWithBaseURI(baseURI string, subscriptionID string) AlertsClient { 39 return AlertsClient{NewWithBaseURI(baseURI, subscriptionID)} 40} 41 42// Close close an alert. 43// 44// location is location name. alertName is name of the alert. userParameter is the username used to perform the 45// operation. alert is updated Alert Parameter. 46func (client AlertsClient) Close(ctx context.Context, location string, alertName string, userParameter string, alert Alert) (result Alert, err error) { 47 req, err := client.ClosePreparer(ctx, location, alertName, userParameter, alert) 48 if err != nil { 49 err = autorest.NewErrorWithError(err, "infrastructureinsights.AlertsClient", "Close", nil, "Failure preparing request") 50 return 51 } 52 53 resp, err := client.CloseSender(req) 54 if err != nil { 55 result.Response = autorest.Response{Response: resp} 56 err = autorest.NewErrorWithError(err, "infrastructureinsights.AlertsClient", "Close", resp, "Failure sending request") 57 return 58 } 59 60 result, err = client.CloseResponder(resp) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "infrastructureinsights.AlertsClient", "Close", resp, "Failure responding to request") 63 } 64 65 return 66} 67 68// ClosePreparer prepares the Close request. 69func (client AlertsClient) ClosePreparer(ctx context.Context, location string, alertName string, userParameter string, alert Alert) (*http.Request, error) { 70 pathParameters := map[string]interface{}{ 71 "alertName": autorest.Encode("path", alertName), 72 "location": autorest.Encode("path", location), 73 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 74 } 75 76 const APIVersion = "2016-05-01" 77 queryParameters := map[string]interface{}{ 78 "api-version": APIVersion, 79 "user": autorest.Encode("query", userParameter), 80 } 81 82 preparer := autorest.CreatePreparer( 83 autorest.AsContentType("application/json; charset=utf-8"), 84 autorest.AsPut(), 85 autorest.WithBaseURL(client.BaseURI), 86 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/System.{location}/providers/Microsoft.InfrastructureInsights.Admin/regionHealths/{location}/alerts/{alertName}", pathParameters), 87 autorest.WithJSON(alert), 88 autorest.WithQueryParameters(queryParameters)) 89 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 90} 91 92// CloseSender sends the Close request. The method will close the 93// http.Response Body if it receives an error. 94func (client AlertsClient) CloseSender(req *http.Request) (*http.Response, error) { 95 return autorest.SendWithSender(client, req, 96 azure.DoRetryWithRegistration(client.Client)) 97} 98 99// CloseResponder handles the response to the Close request. The method always 100// closes the http.Response Body. 101func (client AlertsClient) CloseResponder(resp *http.Response) (result Alert, err error) { 102 err = autorest.Respond( 103 resp, 104 client.ByInspecting(), 105 azure.WithErrorUnlessStatusCode(http.StatusOK), 106 autorest.ByUnmarshallingJSON(&result), 107 autorest.ByClosing()) 108 result.Response = autorest.Response{Response: resp} 109 return 110} 111 112// Get get an alert. 113// 114// location is location name. alertName is name of the alert. 115func (client AlertsClient) Get(ctx context.Context, location string, alertName string) (result Alert, err error) { 116 req, err := client.GetPreparer(ctx, location, alertName) 117 if err != nil { 118 err = autorest.NewErrorWithError(err, "infrastructureinsights.AlertsClient", "Get", nil, "Failure preparing request") 119 return 120 } 121 122 resp, err := client.GetSender(req) 123 if err != nil { 124 result.Response = autorest.Response{Response: resp} 125 err = autorest.NewErrorWithError(err, "infrastructureinsights.AlertsClient", "Get", resp, "Failure sending request") 126 return 127 } 128 129 result, err = client.GetResponder(resp) 130 if err != nil { 131 err = autorest.NewErrorWithError(err, "infrastructureinsights.AlertsClient", "Get", resp, "Failure responding to request") 132 } 133 134 return 135} 136 137// GetPreparer prepares the Get request. 138func (client AlertsClient) GetPreparer(ctx context.Context, location string, alertName string) (*http.Request, error) { 139 pathParameters := map[string]interface{}{ 140 "alertName": autorest.Encode("path", alertName), 141 "location": autorest.Encode("path", location), 142 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 143 } 144 145 const APIVersion = "2016-05-01" 146 queryParameters := map[string]interface{}{ 147 "api-version": APIVersion, 148 } 149 150 preparer := autorest.CreatePreparer( 151 autorest.AsGet(), 152 autorest.WithBaseURL(client.BaseURI), 153 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/System.{location}/providers/Microsoft.InfrastructureInsights.Admin/regionHealths/{location}/alerts/{alertName}", pathParameters), 154 autorest.WithQueryParameters(queryParameters)) 155 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 156} 157 158// GetSender sends the Get request. The method will close the 159// http.Response Body if it receives an error. 160func (client AlertsClient) GetSender(req *http.Request) (*http.Response, error) { 161 return autorest.SendWithSender(client, req, 162 azure.DoRetryWithRegistration(client.Client)) 163} 164 165// GetResponder handles the response to the Get request. The method always 166// closes the http.Response Body. 167func (client AlertsClient) GetResponder(resp *http.Response) (result Alert, err error) { 168 err = autorest.Respond( 169 resp, 170 client.ByInspecting(), 171 azure.WithErrorUnlessStatusCode(http.StatusOK), 172 autorest.ByUnmarshallingJSON(&result), 173 autorest.ByClosing()) 174 result.Response = autorest.Response{Response: resp} 175 return 176} 177 178// List returns the list of all alerts in a given location. 179// 180// location is location name. filter is oData filter parameter. 181func (client AlertsClient) List(ctx context.Context, location string, filter string) (result AlertListPage, err error) { 182 result.fn = client.listNextResults 183 req, err := client.ListPreparer(ctx, location, filter) 184 if err != nil { 185 err = autorest.NewErrorWithError(err, "infrastructureinsights.AlertsClient", "List", nil, "Failure preparing request") 186 return 187 } 188 189 resp, err := client.ListSender(req) 190 if err != nil { 191 result.al.Response = autorest.Response{Response: resp} 192 err = autorest.NewErrorWithError(err, "infrastructureinsights.AlertsClient", "List", resp, "Failure sending request") 193 return 194 } 195 196 result.al, err = client.ListResponder(resp) 197 if err != nil { 198 err = autorest.NewErrorWithError(err, "infrastructureinsights.AlertsClient", "List", resp, "Failure responding to request") 199 } 200 201 return 202} 203 204// ListPreparer prepares the List request. 205func (client AlertsClient) ListPreparer(ctx context.Context, location string, filter string) (*http.Request, error) { 206 pathParameters := map[string]interface{}{ 207 "location": autorest.Encode("path", location), 208 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 209 } 210 211 const APIVersion = "2016-05-01" 212 queryParameters := map[string]interface{}{ 213 "api-version": APIVersion, 214 } 215 if len(filter) > 0 { 216 queryParameters["$filter"] = autorest.Encode("query", filter) 217 } 218 219 preparer := autorest.CreatePreparer( 220 autorest.AsGet(), 221 autorest.WithBaseURL(client.BaseURI), 222 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/System.{location}/providers/Microsoft.InfrastructureInsights.Admin/regionHealths/{location}/alerts", pathParameters), 223 autorest.WithQueryParameters(queryParameters)) 224 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 225} 226 227// ListSender sends the List request. The method will close the 228// http.Response Body if it receives an error. 229func (client AlertsClient) ListSender(req *http.Request) (*http.Response, error) { 230 return autorest.SendWithSender(client, req, 231 azure.DoRetryWithRegistration(client.Client)) 232} 233 234// ListResponder handles the response to the List request. The method always 235// closes the http.Response Body. 236func (client AlertsClient) ListResponder(resp *http.Response) (result AlertList, err error) { 237 err = autorest.Respond( 238 resp, 239 client.ByInspecting(), 240 azure.WithErrorUnlessStatusCode(http.StatusOK), 241 autorest.ByUnmarshallingJSON(&result), 242 autorest.ByClosing()) 243 result.Response = autorest.Response{Response: resp} 244 return 245} 246 247// listNextResults retrieves the next set of results, if any. 248func (client AlertsClient) listNextResults(lastResults AlertList) (result AlertList, err error) { 249 req, err := lastResults.alertListPreparer() 250 if err != nil { 251 return result, autorest.NewErrorWithError(err, "infrastructureinsights.AlertsClient", "listNextResults", nil, "Failure preparing next results request") 252 } 253 if req == nil { 254 return 255 } 256 resp, err := client.ListSender(req) 257 if err != nil { 258 result.Response = autorest.Response{Response: resp} 259 return result, autorest.NewErrorWithError(err, "infrastructureinsights.AlertsClient", "listNextResults", resp, "Failure sending next results request") 260 } 261 result, err = client.ListResponder(resp) 262 if err != nil { 263 err = autorest.NewErrorWithError(err, "infrastructureinsights.AlertsClient", "listNextResults", resp, "Failure responding to next results request") 264 } 265 return 266} 267 268// ListComplete enumerates all values, automatically crossing page boundaries as required. 269func (client AlertsClient) ListComplete(ctx context.Context, location string, filter string) (result AlertListIterator, err error) { 270 result.page, err = client.List(ctx, location, filter) 271 return 272} 273