1package storsimple 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/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// AlertsClient is the client for the Alerts methods of the Storsimple service. 30type AlertsClient struct { 31 BaseClient 32} 33 34// NewAlertsClient creates an instance of the AlertsClient client. 35func NewAlertsClient(subscriptionID string) AlertsClient { 36 return NewAlertsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewAlertsClientWithBaseURI creates an instance of the AlertsClient client using a custom endpoint. Use this when 40// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewAlertsClientWithBaseURI(baseURI string, subscriptionID string) AlertsClient { 42 return AlertsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// Clear clear the alerts. 46// Parameters: 47// parameters - the clear alert request. 48// resourceGroupName - the resource group name 49// managerName - the manager name 50func (client AlertsClient) Clear(ctx context.Context, parameters ClearAlertRequest, resourceGroupName string, managerName string) (result autorest.Response, err error) { 51 if tracing.IsEnabled() { 52 ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.Clear") 53 defer func() { 54 sc := -1 55 if result.Response != nil { 56 sc = result.Response.StatusCode 57 } 58 tracing.EndSpan(ctx, sc, err) 59 }() 60 } 61 if err := validation.Validate([]validation.Validation{ 62 {TargetValue: parameters, 63 Constraints: []validation.Constraint{{Target: "parameters.Alerts", Name: validation.Null, Rule: true, Chain: nil}}}, 64 {TargetValue: managerName, 65 Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 66 {Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil { 67 return result, validation.NewError("storsimple.AlertsClient", "Clear", err.Error()) 68 } 69 70 req, err := client.ClearPreparer(ctx, parameters, resourceGroupName, managerName) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "storsimple.AlertsClient", "Clear", nil, "Failure preparing request") 73 return 74 } 75 76 resp, err := client.ClearSender(req) 77 if err != nil { 78 result.Response = resp 79 err = autorest.NewErrorWithError(err, "storsimple.AlertsClient", "Clear", resp, "Failure sending request") 80 return 81 } 82 83 result, err = client.ClearResponder(resp) 84 if err != nil { 85 err = autorest.NewErrorWithError(err, "storsimple.AlertsClient", "Clear", resp, "Failure responding to request") 86 return 87 } 88 89 return 90} 91 92// ClearPreparer prepares the Clear request. 93func (client AlertsClient) ClearPreparer(ctx context.Context, parameters ClearAlertRequest, resourceGroupName string, managerName string) (*http.Request, error) { 94 pathParameters := map[string]interface{}{ 95 "managerName": managerName, 96 "resourceGroupName": resourceGroupName, 97 "subscriptionId": client.SubscriptionID, 98 } 99 100 const APIVersion = "2017-06-01" 101 queryParameters := map[string]interface{}{ 102 "api-version": APIVersion, 103 } 104 105 preparer := autorest.CreatePreparer( 106 autorest.AsContentType("application/json; charset=utf-8"), 107 autorest.AsPost(), 108 autorest.WithBaseURL(client.BaseURI), 109 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/clearAlerts", pathParameters), 110 autorest.WithJSON(parameters), 111 autorest.WithQueryParameters(queryParameters)) 112 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 113} 114 115// ClearSender sends the Clear request. The method will close the 116// http.Response Body if it receives an error. 117func (client AlertsClient) ClearSender(req *http.Request) (*http.Response, error) { 118 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 119} 120 121// ClearResponder handles the response to the Clear request. The method always 122// closes the http.Response Body. 123func (client AlertsClient) ClearResponder(resp *http.Response) (result autorest.Response, err error) { 124 err = autorest.Respond( 125 resp, 126 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 127 autorest.ByClosing()) 128 result.Response = resp 129 return 130} 131 132// ListByManager retrieves all the alerts in a manager. 133// Parameters: 134// resourceGroupName - the resource group name 135// managerName - the manager name 136// filter - oData Filter options 137func (client AlertsClient) ListByManager(ctx context.Context, resourceGroupName string, managerName string, filter string) (result AlertListPage, err error) { 138 if tracing.IsEnabled() { 139 ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.ListByManager") 140 defer func() { 141 sc := -1 142 if result.al.Response.Response != nil { 143 sc = result.al.Response.Response.StatusCode 144 } 145 tracing.EndSpan(ctx, sc, err) 146 }() 147 } 148 if err := validation.Validate([]validation.Validation{ 149 {TargetValue: managerName, 150 Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 151 {Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil { 152 return result, validation.NewError("storsimple.AlertsClient", "ListByManager", err.Error()) 153 } 154 155 result.fn = client.listByManagerNextResults 156 req, err := client.ListByManagerPreparer(ctx, resourceGroupName, managerName, filter) 157 if err != nil { 158 err = autorest.NewErrorWithError(err, "storsimple.AlertsClient", "ListByManager", nil, "Failure preparing request") 159 return 160 } 161 162 resp, err := client.ListByManagerSender(req) 163 if err != nil { 164 result.al.Response = autorest.Response{Response: resp} 165 err = autorest.NewErrorWithError(err, "storsimple.AlertsClient", "ListByManager", resp, "Failure sending request") 166 return 167 } 168 169 result.al, err = client.ListByManagerResponder(resp) 170 if err != nil { 171 err = autorest.NewErrorWithError(err, "storsimple.AlertsClient", "ListByManager", resp, "Failure responding to request") 172 return 173 } 174 if result.al.hasNextLink() && result.al.IsEmpty() { 175 err = result.NextWithContext(ctx) 176 return 177 } 178 179 return 180} 181 182// ListByManagerPreparer prepares the ListByManager request. 183func (client AlertsClient) ListByManagerPreparer(ctx context.Context, resourceGroupName string, managerName string, filter string) (*http.Request, error) { 184 pathParameters := map[string]interface{}{ 185 "managerName": managerName, 186 "resourceGroupName": resourceGroupName, 187 "subscriptionId": client.SubscriptionID, 188 } 189 190 const APIVersion = "2017-06-01" 191 queryParameters := map[string]interface{}{ 192 "api-version": APIVersion, 193 } 194 if len(filter) > 0 { 195 queryParameters["$filter"] = autorest.Encode("query", filter) 196 } 197 198 preparer := autorest.CreatePreparer( 199 autorest.AsGet(), 200 autorest.WithBaseURL(client.BaseURI), 201 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/alerts", pathParameters), 202 autorest.WithQueryParameters(queryParameters)) 203 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 204} 205 206// ListByManagerSender sends the ListByManager request. The method will close the 207// http.Response Body if it receives an error. 208func (client AlertsClient) ListByManagerSender(req *http.Request) (*http.Response, error) { 209 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 210} 211 212// ListByManagerResponder handles the response to the ListByManager request. The method always 213// closes the http.Response Body. 214func (client AlertsClient) ListByManagerResponder(resp *http.Response) (result AlertList, err error) { 215 err = autorest.Respond( 216 resp, 217 azure.WithErrorUnlessStatusCode(http.StatusOK), 218 autorest.ByUnmarshallingJSON(&result), 219 autorest.ByClosing()) 220 result.Response = autorest.Response{Response: resp} 221 return 222} 223 224// listByManagerNextResults retrieves the next set of results, if any. 225func (client AlertsClient) listByManagerNextResults(ctx context.Context, lastResults AlertList) (result AlertList, err error) { 226 req, err := lastResults.alertListPreparer(ctx) 227 if err != nil { 228 return result, autorest.NewErrorWithError(err, "storsimple.AlertsClient", "listByManagerNextResults", nil, "Failure preparing next results request") 229 } 230 if req == nil { 231 return 232 } 233 resp, err := client.ListByManagerSender(req) 234 if err != nil { 235 result.Response = autorest.Response{Response: resp} 236 return result, autorest.NewErrorWithError(err, "storsimple.AlertsClient", "listByManagerNextResults", resp, "Failure sending next results request") 237 } 238 result, err = client.ListByManagerResponder(resp) 239 if err != nil { 240 err = autorest.NewErrorWithError(err, "storsimple.AlertsClient", "listByManagerNextResults", resp, "Failure responding to next results request") 241 } 242 return 243} 244 245// ListByManagerComplete enumerates all values, automatically crossing page boundaries as required. 246func (client AlertsClient) ListByManagerComplete(ctx context.Context, resourceGroupName string, managerName string, filter string) (result AlertListIterator, err error) { 247 if tracing.IsEnabled() { 248 ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.ListByManager") 249 defer func() { 250 sc := -1 251 if result.Response().Response.Response != nil { 252 sc = result.page.Response().Response.Response.StatusCode 253 } 254 tracing.EndSpan(ctx, sc, err) 255 }() 256 } 257 result.page, err = client.ListByManager(ctx, resourceGroupName, managerName, filter) 258 return 259} 260 261// SendTestEmail sends a test alert email. 262// Parameters: 263// deviceName - the device name 264// parameters - the send test alert email request. 265// resourceGroupName - the resource group name 266// managerName - the manager name 267func (client AlertsClient) SendTestEmail(ctx context.Context, deviceName string, parameters SendTestAlertEmailRequest, resourceGroupName string, managerName string) (result autorest.Response, err error) { 268 if tracing.IsEnabled() { 269 ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.SendTestEmail") 270 defer func() { 271 sc := -1 272 if result.Response != nil { 273 sc = result.Response.StatusCode 274 } 275 tracing.EndSpan(ctx, sc, err) 276 }() 277 } 278 if err := validation.Validate([]validation.Validation{ 279 {TargetValue: parameters, 280 Constraints: []validation.Constraint{{Target: "parameters.EmailList", Name: validation.Null, Rule: true, Chain: nil}}}, 281 {TargetValue: managerName, 282 Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 283 {Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil { 284 return result, validation.NewError("storsimple.AlertsClient", "SendTestEmail", err.Error()) 285 } 286 287 req, err := client.SendTestEmailPreparer(ctx, deviceName, parameters, resourceGroupName, managerName) 288 if err != nil { 289 err = autorest.NewErrorWithError(err, "storsimple.AlertsClient", "SendTestEmail", nil, "Failure preparing request") 290 return 291 } 292 293 resp, err := client.SendTestEmailSender(req) 294 if err != nil { 295 result.Response = resp 296 err = autorest.NewErrorWithError(err, "storsimple.AlertsClient", "SendTestEmail", resp, "Failure sending request") 297 return 298 } 299 300 result, err = client.SendTestEmailResponder(resp) 301 if err != nil { 302 err = autorest.NewErrorWithError(err, "storsimple.AlertsClient", "SendTestEmail", resp, "Failure responding to request") 303 return 304 } 305 306 return 307} 308 309// SendTestEmailPreparer prepares the SendTestEmail request. 310func (client AlertsClient) SendTestEmailPreparer(ctx context.Context, deviceName string, parameters SendTestAlertEmailRequest, resourceGroupName string, managerName string) (*http.Request, error) { 311 pathParameters := map[string]interface{}{ 312 "deviceName": deviceName, 313 "managerName": managerName, 314 "resourceGroupName": resourceGroupName, 315 "subscriptionId": client.SubscriptionID, 316 } 317 318 const APIVersion = "2017-06-01" 319 queryParameters := map[string]interface{}{ 320 "api-version": APIVersion, 321 } 322 323 preparer := autorest.CreatePreparer( 324 autorest.AsContentType("application/json; charset=utf-8"), 325 autorest.AsPost(), 326 autorest.WithBaseURL(client.BaseURI), 327 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/sendTestAlertEmail", pathParameters), 328 autorest.WithJSON(parameters), 329 autorest.WithQueryParameters(queryParameters)) 330 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 331} 332 333// SendTestEmailSender sends the SendTestEmail request. The method will close the 334// http.Response Body if it receives an error. 335func (client AlertsClient) SendTestEmailSender(req *http.Request) (*http.Response, error) { 336 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 337} 338 339// SendTestEmailResponder handles the response to the SendTestEmail request. The method always 340// closes the http.Response Body. 341func (client AlertsClient) SendTestEmailResponder(resp *http.Response) (result autorest.Response, err error) { 342 err = autorest.Respond( 343 resp, 344 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 345 autorest.ByClosing()) 346 result.Response = resp 347 return 348} 349