...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2015-11-01-preview/servicemap/summaries.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2015-11-01-preview/servicemap

     1  package servicemap
     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/date"
    14  	"github.com/Azure/go-autorest/autorest/validation"
    15  	"github.com/Azure/go-autorest/tracing"
    16  	"net/http"
    17  )
    18  
    19  // SummariesClient is the service Map API Reference
    20  type SummariesClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewSummariesClient creates an instance of the SummariesClient client.
    25  func NewSummariesClient(subscriptionID string) SummariesClient {
    26  	return NewSummariesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    27  }
    28  
    29  // NewSummariesClientWithBaseURI creates an instance of the SummariesClient client using a custom endpoint.  Use this
    30  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    31  func NewSummariesClientWithBaseURI(baseURI string, subscriptionID string) SummariesClient {
    32  	return SummariesClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // GetMachines returns summary information about the machines in the workspace.
    36  // Parameters:
    37  // resourceGroupName - resource group name within the specified subscriptionId.
    38  // workspaceName - OMS workspace containing the resources of interest.
    39  // startTime - UTC date and time specifying the start time of an interval. When not specified the service uses
    40  // DateTime.UtcNow - 10m
    41  // endTime - UTC date and time specifying the end time of an interval. When not specified the service uses
    42  // DateTime.UtcNow
    43  func (client SummariesClient) GetMachines(ctx context.Context, resourceGroupName string, workspaceName string, startTime *date.Time, endTime *date.Time) (result MachinesSummary, err error) {
    44  	if tracing.IsEnabled() {
    45  		ctx = tracing.StartSpan(ctx, fqdn+"/SummariesClient.GetMachines")
    46  		defer func() {
    47  			sc := -1
    48  			if result.Response.Response != nil {
    49  				sc = result.Response.Response.StatusCode
    50  			}
    51  			tracing.EndSpan(ctx, sc, err)
    52  		}()
    53  	}
    54  	if err := validation.Validate([]validation.Validation{
    55  		{TargetValue: resourceGroupName,
    56  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil},
    57  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
    58  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `[a-zA-Z0-9_-]+`, Chain: nil}}},
    59  		{TargetValue: workspaceName,
    60  			Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 63, Chain: nil},
    61  				{Target: "workspaceName", Name: validation.MinLength, Rule: 3, Chain: nil},
    62  				{Target: "workspaceName", Name: validation.Pattern, Rule: `[a-zA-Z0-9_][a-zA-Z0-9_-]+[a-zA-Z0-9_]`, Chain: nil}}}}); err != nil {
    63  		return result, validation.NewError("servicemap.SummariesClient", "GetMachines", err.Error())
    64  	}
    65  
    66  	req, err := client.GetMachinesPreparer(ctx, resourceGroupName, workspaceName, startTime, endTime)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "servicemap.SummariesClient", "GetMachines", nil, "Failure preparing request")
    69  		return
    70  	}
    71  
    72  	resp, err := client.GetMachinesSender(req)
    73  	if err != nil {
    74  		result.Response = autorest.Response{Response: resp}
    75  		err = autorest.NewErrorWithError(err, "servicemap.SummariesClient", "GetMachines", resp, "Failure sending request")
    76  		return
    77  	}
    78  
    79  	result, err = client.GetMachinesResponder(resp)
    80  	if err != nil {
    81  		err = autorest.NewErrorWithError(err, "servicemap.SummariesClient", "GetMachines", resp, "Failure responding to request")
    82  		return
    83  	}
    84  
    85  	return
    86  }
    87  
    88  // GetMachinesPreparer prepares the GetMachines request.
    89  func (client SummariesClient) GetMachinesPreparer(ctx context.Context, resourceGroupName string, workspaceName string, startTime *date.Time, endTime *date.Time) (*http.Request, error) {
    90  	pathParameters := map[string]interface{}{
    91  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    92  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    93  		"workspaceName":     autorest.Encode("path", workspaceName),
    94  	}
    95  
    96  	const APIVersion = "2015-11-01-preview"
    97  	queryParameters := map[string]interface{}{
    98  		"api-version": APIVersion,
    99  	}
   100  	if startTime != nil {
   101  		queryParameters["startTime"] = autorest.Encode("query", *startTime)
   102  	}
   103  	if endTime != nil {
   104  		queryParameters["endTime"] = autorest.Encode("query", *endTime)
   105  	}
   106  
   107  	preparer := autorest.CreatePreparer(
   108  		autorest.AsGet(),
   109  		autorest.WithBaseURL(client.BaseURI),
   110  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/features/serviceMap/summaries/machines", pathParameters),
   111  		autorest.WithQueryParameters(queryParameters))
   112  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   113  }
   114  
   115  // GetMachinesSender sends the GetMachines request. The method will close the
   116  // http.Response Body if it receives an error.
   117  func (client SummariesClient) GetMachinesSender(req *http.Request) (*http.Response, error) {
   118  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   119  }
   120  
   121  // GetMachinesResponder handles the response to the GetMachines request. The method always
   122  // closes the http.Response Body.
   123  func (client SummariesClient) GetMachinesResponder(resp *http.Response) (result MachinesSummary, err error) {
   124  	err = autorest.Respond(
   125  		resp,
   126  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   127  		autorest.ByUnmarshallingJSON(&result),
   128  		autorest.ByClosing())
   129  	result.Response = autorest.Response{Response: resp}
   130  	return
   131  }
   132  

View as plain text