...

Source file src/github.com/Azure/azure-sdk-for-go/services/storsimple8000series/mgmt/2017-06-01/storsimple/alerts.go

Documentation: github.com/Azure/azure-sdk-for-go/services/storsimple8000series/mgmt/2017-06-01/storsimple

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

View as plain text