From cf51bdd0d87d33f503b6e6b994bb063c152fde9a Mon Sep 17 00:00:00 2001 From: Dominik Lekse Date: Tue, 31 Oct 2017 16:01:14 +0100 Subject: [PATCH 01/12] Added vendor dependency for github.com/Azure/azure-sdk-for-go/arm/monitor --- .../arm/monitor/actiongroups.go | 445 ++++++ .../arm/monitor/activitylogalerts.go | 441 ++++++ .../arm/monitor/alertruleincidents.go | 171 +++ .../arm/monitor/alertrules.go | 379 +++++ .../arm/monitor/autoscalesettings.go | 447 ++++++ .../azure-sdk-for-go/arm/monitor/client.go | 51 + .../arm/monitor/diagnosticsettings.go | 296 ++++ .../arm/monitor/diagnosticsettingscategory.go | 166 +++ .../arm/monitor/logprofiles.go | 374 +++++ .../azure-sdk-for-go/arm/monitor/models.go | 1260 +++++++++++++++++ .../arm/monitor/operations.go | 96 ++ .../azure-sdk-for-go/arm/monitor/version.go | 28 + vendor/vendor.json | 8 + 13 files changed, 4162 insertions(+) create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/actiongroups.go create mode 100755 vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/activitylogalerts.go create mode 100755 vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/alertruleincidents.go create mode 100755 vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/alertrules.go create mode 100755 vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/autoscalesettings.go create mode 100755 vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/client.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/diagnosticsettings.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/diagnosticsettingscategory.go create mode 100755 vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/logprofiles.go create mode 100755 vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/models.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/operations.go create mode 100755 vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/version.go diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/actiongroups.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/actiongroups.go new file mode 100644 index 000000000000..9df12ff00a25 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/actiongroups.go @@ -0,0 +1,445 @@ +package monitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// ActionGroupsClient is the monitor Management Client +type ActionGroupsClient struct { + ManagementClient +} + +// NewActionGroupsClient creates an instance of the ActionGroupsClient client. +func NewActionGroupsClient(subscriptionID string) ActionGroupsClient { + return NewActionGroupsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewActionGroupsClientWithBaseURI creates an instance of the ActionGroupsClient client. +func NewActionGroupsClientWithBaseURI(baseURI string, subscriptionID string) ActionGroupsClient { + return ActionGroupsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate create a new action group or update an existing one. +// +// resourceGroupName is the name of the resource group. actionGroupName is the name of the action group. actionGroup is +// the action group to create or use for the update. +func (client ActionGroupsClient) CreateOrUpdate(resourceGroupName string, actionGroupName string, actionGroup ActionGroupResource) (result ActionGroupResource, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: actionGroup, + Constraints: []validation.Constraint{{Target: "actionGroup.ActionGroup", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "actionGroup.ActionGroup.GroupShortName", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "actionGroup.ActionGroup.GroupShortName", Name: validation.MaxLength, Rule: 15, Chain: nil}}}, + {Target: "actionGroup.ActionGroup.Enabled", Name: validation.Null, Rule: true, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "monitor.ActionGroupsClient", "CreateOrUpdate") + } + + req, err := client.CreateOrUpdatePreparer(resourceGroupName, actionGroupName, actionGroup) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client ActionGroupsClient) CreateOrUpdatePreparer(resourceGroupName string, actionGroupName string, actionGroup ActionGroupResource) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "actionGroupName": autorest.Encode("path", actionGroupName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/actionGroups/{actionGroupName}", pathParameters), + autorest.WithJSON(actionGroup), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client ActionGroupsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client ActionGroupsClient) CreateOrUpdateResponder(resp *http.Response) (result ActionGroupResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete delete an action group. +// +// resourceGroupName is the name of the resource group. actionGroupName is the name of the action group. +func (client ActionGroupsClient) Delete(resourceGroupName string, actionGroupName string) (result autorest.Response, err error) { + req, err := client.DeletePreparer(resourceGroupName, actionGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client ActionGroupsClient) DeletePreparer(resourceGroupName string, actionGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "actionGroupName": autorest.Encode("path", actionGroupName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/actionGroups/{actionGroupName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client ActionGroupsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client ActionGroupsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// EnableReceiver enable a receiver in an action group. This changes the receiver's status from Disabled to Enabled. +// +// resourceGroupName is the name of the resource group. actionGroupName is the name of the action group. enableRequest +// is the receiver to re-enable. +func (client ActionGroupsClient) EnableReceiver(resourceGroupName string, actionGroupName string, enableRequest EnableRequest) (result autorest.Response, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: enableRequest, + Constraints: []validation.Constraint{{Target: "enableRequest.ReceiverName", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "monitor.ActionGroupsClient", "EnableReceiver") + } + + req, err := client.EnableReceiverPreparer(resourceGroupName, actionGroupName, enableRequest) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "EnableReceiver", nil, "Failure preparing request") + return + } + + resp, err := client.EnableReceiverSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "EnableReceiver", resp, "Failure sending request") + return + } + + result, err = client.EnableReceiverResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "EnableReceiver", resp, "Failure responding to request") + } + + return +} + +// EnableReceiverPreparer prepares the EnableReceiver request. +func (client ActionGroupsClient) EnableReceiverPreparer(resourceGroupName string, actionGroupName string, enableRequest EnableRequest) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "actionGroupName": autorest.Encode("path", actionGroupName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/actionGroups/{actionGroupName}/subscribe", pathParameters), + autorest.WithJSON(enableRequest), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// EnableReceiverSender sends the EnableReceiver request. The method will close the +// http.Response Body if it receives an error. +func (client ActionGroupsClient) EnableReceiverSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// EnableReceiverResponder handles the response to the EnableReceiver request. The method always +// closes the http.Response Body. +func (client ActionGroupsClient) EnableReceiverResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusConflict), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get get an action group. +// +// resourceGroupName is the name of the resource group. actionGroupName is the name of the action group. +func (client ActionGroupsClient) Get(resourceGroupName string, actionGroupName string) (result ActionGroupResource, err error) { + req, err := client.GetPreparer(resourceGroupName, actionGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client ActionGroupsClient) GetPreparer(resourceGroupName string, actionGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "actionGroupName": autorest.Encode("path", actionGroupName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/actionGroups/{actionGroupName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client ActionGroupsClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ActionGroupsClient) GetResponder(resp *http.Response) (result ActionGroupResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByResourceGroup get a list of all action groups in a resource group. +// +// resourceGroupName is the name of the resource group. +func (client ActionGroupsClient) ListByResourceGroup(resourceGroupName string) (result ActionGroupList, err error) { + req, err := client.ListByResourceGroupPreparer(resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "ListByResourceGroup", resp, "Failure sending request") + return + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "ListByResourceGroup", resp, "Failure responding to request") + } + + return +} + +// ListByResourceGroupPreparer prepares the ListByResourceGroup request. +func (client ActionGroupsClient) ListByResourceGroupPreparer(resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/actionGroups", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client ActionGroupsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (client ActionGroupsClient) ListByResourceGroupResponder(resp *http.Response) (result ActionGroupList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListBySubscriptionID get a list of all action groups in a subscription. +func (client ActionGroupsClient) ListBySubscriptionID() (result ActionGroupList, err error) { + req, err := client.ListBySubscriptionIDPreparer() + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "ListBySubscriptionID", nil, "Failure preparing request") + return + } + + resp, err := client.ListBySubscriptionIDSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "ListBySubscriptionID", resp, "Failure sending request") + return + } + + result, err = client.ListBySubscriptionIDResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActionGroupsClient", "ListBySubscriptionID", resp, "Failure responding to request") + } + + return +} + +// ListBySubscriptionIDPreparer prepares the ListBySubscriptionID request. +func (client ActionGroupsClient) ListBySubscriptionIDPreparer() (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/actionGroups", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListBySubscriptionIDSender sends the ListBySubscriptionID request. The method will close the +// http.Response Body if it receives an error. +func (client ActionGroupsClient) ListBySubscriptionIDSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListBySubscriptionIDResponder handles the response to the ListBySubscriptionID request. The method always +// closes the http.Response Body. +func (client ActionGroupsClient) ListBySubscriptionIDResponder(resp *http.Response) (result ActionGroupList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/activitylogalerts.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/activitylogalerts.go new file mode 100755 index 000000000000..9801cbb00204 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/activitylogalerts.go @@ -0,0 +1,441 @@ +package monitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// ActivityLogAlertsClient is the monitor Management Client +type ActivityLogAlertsClient struct { + ManagementClient +} + +// NewActivityLogAlertsClient creates an instance of the ActivityLogAlertsClient client. +func NewActivityLogAlertsClient(subscriptionID string) ActivityLogAlertsClient { + return NewActivityLogAlertsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewActivityLogAlertsClientWithBaseURI creates an instance of the ActivityLogAlertsClient client. +func NewActivityLogAlertsClientWithBaseURI(baseURI string, subscriptionID string) ActivityLogAlertsClient { + return ActivityLogAlertsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate create a new activity log alert or update an existing one. +// +// resourceGroupName is the name of the resource group. activityLogAlertName is the name of the activity log alert. +// activityLogAlert is the activity log alert to create or use for the update. +func (client ActivityLogAlertsClient) CreateOrUpdate(resourceGroupName string, activityLogAlertName string, activityLogAlert ActivityLogAlertResource) (result ActivityLogAlertResource, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: activityLogAlert, + Constraints: []validation.Constraint{{Target: "activityLogAlert.ActivityLogAlert", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "activityLogAlert.ActivityLogAlert.Scopes", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "activityLogAlert.ActivityLogAlert.Condition", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "activityLogAlert.ActivityLogAlert.Condition.AllOf", Name: validation.Null, Rule: true, Chain: nil}}}, + {Target: "activityLogAlert.ActivityLogAlert.Actions", Name: validation.Null, Rule: true, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "monitor.ActivityLogAlertsClient", "CreateOrUpdate") + } + + req, err := client.CreateOrUpdatePreparer(resourceGroupName, activityLogAlertName, activityLogAlert) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client ActivityLogAlertsClient) CreateOrUpdatePreparer(resourceGroupName string, activityLogAlertName string, activityLogAlert ActivityLogAlertResource) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "activityLogAlertName": autorest.Encode("path", activityLogAlertName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/activityLogAlerts/{activityLogAlertName}", pathParameters), + autorest.WithJSON(activityLogAlert), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client ActivityLogAlertsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client ActivityLogAlertsClient) CreateOrUpdateResponder(resp *http.Response) (result ActivityLogAlertResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete delete an activity log alert. +// +// resourceGroupName is the name of the resource group. activityLogAlertName is the name of the activity log alert. +func (client ActivityLogAlertsClient) Delete(resourceGroupName string, activityLogAlertName string) (result autorest.Response, err error) { + req, err := client.DeletePreparer(resourceGroupName, activityLogAlertName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client ActivityLogAlertsClient) DeletePreparer(resourceGroupName string, activityLogAlertName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "activityLogAlertName": autorest.Encode("path", activityLogAlertName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/activityLogAlerts/{activityLogAlertName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client ActivityLogAlertsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client ActivityLogAlertsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get get an activity log alert. +// +// resourceGroupName is the name of the resource group. activityLogAlertName is the name of the activity log alert. +func (client ActivityLogAlertsClient) Get(resourceGroupName string, activityLogAlertName string) (result ActivityLogAlertResource, err error) { + req, err := client.GetPreparer(resourceGroupName, activityLogAlertName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client ActivityLogAlertsClient) GetPreparer(resourceGroupName string, activityLogAlertName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "activityLogAlertName": autorest.Encode("path", activityLogAlertName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/activityLogAlerts/{activityLogAlertName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client ActivityLogAlertsClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ActivityLogAlertsClient) GetResponder(resp *http.Response) (result ActivityLogAlertResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByResourceGroup get a list of all activity log alerts in a resource group. +// +// resourceGroupName is the name of the resource group. +func (client ActivityLogAlertsClient) ListByResourceGroup(resourceGroupName string) (result ActivityLogAlertList, err error) { + req, err := client.ListByResourceGroupPreparer(resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "ListByResourceGroup", resp, "Failure sending request") + return + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "ListByResourceGroup", resp, "Failure responding to request") + } + + return +} + +// ListByResourceGroupPreparer prepares the ListByResourceGroup request. +func (client ActivityLogAlertsClient) ListByResourceGroupPreparer(resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/activityLogAlerts", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client ActivityLogAlertsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (client ActivityLogAlertsClient) ListByResourceGroupResponder(resp *http.Response) (result ActivityLogAlertList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListBySubscriptionID get a list of all activity log alerts in a subscription. +func (client ActivityLogAlertsClient) ListBySubscriptionID() (result ActivityLogAlertList, err error) { + req, err := client.ListBySubscriptionIDPreparer() + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "ListBySubscriptionID", nil, "Failure preparing request") + return + } + + resp, err := client.ListBySubscriptionIDSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "ListBySubscriptionID", resp, "Failure sending request") + return + } + + result, err = client.ListBySubscriptionIDResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "ListBySubscriptionID", resp, "Failure responding to request") + } + + return +} + +// ListBySubscriptionIDPreparer prepares the ListBySubscriptionID request. +func (client ActivityLogAlertsClient) ListBySubscriptionIDPreparer() (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/activityLogAlerts", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListBySubscriptionIDSender sends the ListBySubscriptionID request. The method will close the +// http.Response Body if it receives an error. +func (client ActivityLogAlertsClient) ListBySubscriptionIDSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListBySubscriptionIDResponder handles the response to the ListBySubscriptionID request. The method always +// closes the http.Response Body. +func (client ActivityLogAlertsClient) ListBySubscriptionIDResponder(resp *http.Response) (result ActivityLogAlertList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Update updates an existing ActivityLogAlertResource's tags. To update other fields use the CreateOrUpdate method. +// +// resourceGroupName is the name of the resource group. activityLogAlertName is the name of the activity log alert. +// activityLogAlertPatch is parameters supplied to the operation. +func (client ActivityLogAlertsClient) Update(resourceGroupName string, activityLogAlertName string, activityLogAlertPatch ActivityLogAlertPatchBody) (result ActivityLogAlertResource, err error) { + req, err := client.UpdatePreparer(resourceGroupName, activityLogAlertName, activityLogAlertPatch) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.ActivityLogAlertsClient", "Update", resp, "Failure responding to request") + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client ActivityLogAlertsClient) UpdatePreparer(resourceGroupName string, activityLogAlertName string, activityLogAlertPatch ActivityLogAlertPatchBody) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "activityLogAlertName": autorest.Encode("path", activityLogAlertName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/activityLogAlerts/{activityLogAlertName}", pathParameters), + autorest.WithJSON(activityLogAlertPatch), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client ActivityLogAlertsClient) UpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client ActivityLogAlertsClient) UpdateResponder(resp *http.Response) (result ActivityLogAlertResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/alertruleincidents.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/alertruleincidents.go new file mode 100755 index 000000000000..fafabe35ca82 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/alertruleincidents.go @@ -0,0 +1,171 @@ +package monitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" +) + +// AlertRuleIncidentsClient is the monitor Management Client +type AlertRuleIncidentsClient struct { + ManagementClient +} + +// NewAlertRuleIncidentsClient creates an instance of the AlertRuleIncidentsClient client. +func NewAlertRuleIncidentsClient(subscriptionID string) AlertRuleIncidentsClient { + return NewAlertRuleIncidentsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewAlertRuleIncidentsClientWithBaseURI creates an instance of the AlertRuleIncidentsClient client. +func NewAlertRuleIncidentsClientWithBaseURI(baseURI string, subscriptionID string) AlertRuleIncidentsClient { + return AlertRuleIncidentsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// Get gets an incident associated to an alert rule +// +// resourceGroupName is the name of the resource group. ruleName is the name of the rule. incidentName is the name of +// the incident to retrieve. +func (client AlertRuleIncidentsClient) Get(resourceGroupName string, ruleName string, incidentName string) (result Incident, err error) { + req, err := client.GetPreparer(resourceGroupName, ruleName, incidentName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AlertRuleIncidentsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.AlertRuleIncidentsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AlertRuleIncidentsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client AlertRuleIncidentsClient) GetPreparer(resourceGroupName string, ruleName string, incidentName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "incidentName": autorest.Encode("path", incidentName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "ruleName": autorest.Encode("path", ruleName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2016-03-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/alertrules/{ruleName}/incidents/{incidentName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client AlertRuleIncidentsClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client AlertRuleIncidentsClient) GetResponder(resp *http.Response) (result Incident, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByAlertRule gets a list of incidents associated to an alert rule +// +// resourceGroupName is the name of the resource group. ruleName is the name of the rule. +func (client AlertRuleIncidentsClient) ListByAlertRule(resourceGroupName string, ruleName string) (result IncidentListResult, err error) { + req, err := client.ListByAlertRulePreparer(resourceGroupName, ruleName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AlertRuleIncidentsClient", "ListByAlertRule", nil, "Failure preparing request") + return + } + + resp, err := client.ListByAlertRuleSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.AlertRuleIncidentsClient", "ListByAlertRule", resp, "Failure sending request") + return + } + + result, err = client.ListByAlertRuleResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AlertRuleIncidentsClient", "ListByAlertRule", resp, "Failure responding to request") + } + + return +} + +// ListByAlertRulePreparer prepares the ListByAlertRule request. +func (client AlertRuleIncidentsClient) ListByAlertRulePreparer(resourceGroupName string, ruleName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "ruleName": autorest.Encode("path", ruleName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2016-03-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/alertrules/{ruleName}/incidents", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListByAlertRuleSender sends the ListByAlertRule request. The method will close the +// http.Response Body if it receives an error. +func (client AlertRuleIncidentsClient) ListByAlertRuleSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListByAlertRuleResponder handles the response to the ListByAlertRule request. The method always +// closes the http.Response Body. +func (client AlertRuleIncidentsClient) ListByAlertRuleResponder(resp *http.Response) (result IncidentListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/alertrules.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/alertrules.go new file mode 100755 index 000000000000..f344ff54ec69 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/alertrules.go @@ -0,0 +1,379 @@ +package monitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// AlertRulesClient is the monitor Management Client +type AlertRulesClient struct { + ManagementClient +} + +// NewAlertRulesClient creates an instance of the AlertRulesClient client. +func NewAlertRulesClient(subscriptionID string) AlertRulesClient { + return NewAlertRulesClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewAlertRulesClientWithBaseURI creates an instance of the AlertRulesClient client. +func NewAlertRulesClientWithBaseURI(baseURI string, subscriptionID string) AlertRulesClient { + return AlertRulesClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates or updates an alert rule. +// +// resourceGroupName is the name of the resource group. ruleName is the name of the rule. parameters is the parameters +// of the rule to create or update. +func (client AlertRulesClient) CreateOrUpdate(resourceGroupName string, ruleName string, parameters AlertRuleResource) (result AlertRuleResource, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.AlertRule", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "parameters.AlertRule.Name", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "parameters.AlertRule.IsEnabled", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "parameters.AlertRule.Condition", Name: validation.Null, Rule: true, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "monitor.AlertRulesClient", "CreateOrUpdate") + } + + req, err := client.CreateOrUpdatePreparer(resourceGroupName, ruleName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AlertRulesClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.AlertRulesClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AlertRulesClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client AlertRulesClient) CreateOrUpdatePreparer(resourceGroupName string, ruleName string, parameters AlertRuleResource) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "ruleName": autorest.Encode("path", ruleName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2016-03-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/alertrules/{ruleName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client AlertRulesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client AlertRulesClient) CreateOrUpdateResponder(resp *http.Response) (result AlertRuleResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete deletes an alert rule +// +// resourceGroupName is the name of the resource group. ruleName is the name of the rule. +func (client AlertRulesClient) Delete(resourceGroupName string, ruleName string) (result autorest.Response, err error) { + req, err := client.DeletePreparer(resourceGroupName, ruleName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AlertRulesClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "monitor.AlertRulesClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AlertRulesClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client AlertRulesClient) DeletePreparer(resourceGroupName string, ruleName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "ruleName": autorest.Encode("path", ruleName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2016-03-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/alertrules/{ruleName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client AlertRulesClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client AlertRulesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get gets an alert rule +// +// resourceGroupName is the name of the resource group. ruleName is the name of the rule. +func (client AlertRulesClient) Get(resourceGroupName string, ruleName string) (result AlertRuleResource, err error) { + req, err := client.GetPreparer(resourceGroupName, ruleName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AlertRulesClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.AlertRulesClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AlertRulesClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client AlertRulesClient) GetPreparer(resourceGroupName string, ruleName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "ruleName": autorest.Encode("path", ruleName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2016-03-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/alertrules/{ruleName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client AlertRulesClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client AlertRulesClient) GetResponder(resp *http.Response) (result AlertRuleResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByResourceGroup list the alert rules within a resource group. +// +// resourceGroupName is the name of the resource group. +func (client AlertRulesClient) ListByResourceGroup(resourceGroupName string) (result AlertRuleResourceCollection, err error) { + req, err := client.ListByResourceGroupPreparer(resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AlertRulesClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.AlertRulesClient", "ListByResourceGroup", resp, "Failure sending request") + return + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AlertRulesClient", "ListByResourceGroup", resp, "Failure responding to request") + } + + return +} + +// ListByResourceGroupPreparer prepares the ListByResourceGroup request. +func (client AlertRulesClient) ListByResourceGroupPreparer(resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2016-03-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/alertrules", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client AlertRulesClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (client AlertRulesClient) ListByResourceGroupResponder(resp *http.Response) (result AlertRuleResourceCollection, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Update updates an existing AlertRuleResource. To update other fields use the CreateOrUpdate method. +// +// resourceGroupName is the name of the resource group. ruleName is the name of the rule. alertRulesResource is +// parameters supplied to the operation. +func (client AlertRulesClient) Update(resourceGroupName string, ruleName string, alertRulesResource AlertRuleResourcePatch) (result AlertRuleResource, err error) { + req, err := client.UpdatePreparer(resourceGroupName, ruleName, alertRulesResource) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AlertRulesClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.AlertRulesClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AlertRulesClient", "Update", resp, "Failure responding to request") + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client AlertRulesClient) UpdatePreparer(resourceGroupName string, ruleName string, alertRulesResource AlertRuleResourcePatch) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "ruleName": autorest.Encode("path", ruleName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2016-03-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/alertrules/{ruleName}", pathParameters), + autorest.WithJSON(alertRulesResource), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client AlertRulesClient) UpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client AlertRulesClient) UpdateResponder(resp *http.Response) (result AlertRuleResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/autoscalesettings.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/autoscalesettings.go new file mode 100755 index 000000000000..9f12f04bf47e --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/autoscalesettings.go @@ -0,0 +1,447 @@ +package monitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// AutoscaleSettingsClient is the monitor Management Client +type AutoscaleSettingsClient struct { + ManagementClient +} + +// NewAutoscaleSettingsClient creates an instance of the AutoscaleSettingsClient client. +func NewAutoscaleSettingsClient(subscriptionID string) AutoscaleSettingsClient { + return NewAutoscaleSettingsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewAutoscaleSettingsClientWithBaseURI creates an instance of the AutoscaleSettingsClient client. +func NewAutoscaleSettingsClientWithBaseURI(baseURI string, subscriptionID string) AutoscaleSettingsClient { + return AutoscaleSettingsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates or updates an autoscale setting. +// +// resourceGroupName is the name of the resource group. autoscaleSettingName is the autoscale setting name. parameters +// is parameters supplied to the operation. +func (client AutoscaleSettingsClient) CreateOrUpdate(resourceGroupName string, autoscaleSettingName string, parameters AutoscaleSettingResource) (result AutoscaleSettingResource, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.AutoscaleSetting", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "parameters.AutoscaleSetting.Profiles", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "parameters.AutoscaleSetting.Profiles", Name: validation.MaxItems, Rule: 20, Chain: nil}}}, + }}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "monitor.AutoscaleSettingsClient", "CreateOrUpdate") + } + + req, err := client.CreateOrUpdatePreparer(resourceGroupName, autoscaleSettingName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client AutoscaleSettingsClient) CreateOrUpdatePreparer(resourceGroupName string, autoscaleSettingName string, parameters AutoscaleSettingResource) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "autoscaleSettingName": autorest.Encode("path", autoscaleSettingName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/autoscalesettings/{autoscaleSettingName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client AutoscaleSettingsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client AutoscaleSettingsClient) CreateOrUpdateResponder(resp *http.Response) (result AutoscaleSettingResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete deletes and autoscale setting +// +// resourceGroupName is the name of the resource group. autoscaleSettingName is the autoscale setting name. +func (client AutoscaleSettingsClient) Delete(resourceGroupName string, autoscaleSettingName string) (result autorest.Response, err error) { + req, err := client.DeletePreparer(resourceGroupName, autoscaleSettingName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client AutoscaleSettingsClient) DeletePreparer(resourceGroupName string, autoscaleSettingName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "autoscaleSettingName": autorest.Encode("path", autoscaleSettingName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/autoscalesettings/{autoscaleSettingName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client AutoscaleSettingsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client AutoscaleSettingsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get gets an autoscale setting +// +// resourceGroupName is the name of the resource group. autoscaleSettingName is the autoscale setting name. +func (client AutoscaleSettingsClient) Get(resourceGroupName string, autoscaleSettingName string) (result AutoscaleSettingResource, err error) { + req, err := client.GetPreparer(resourceGroupName, autoscaleSettingName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client AutoscaleSettingsClient) GetPreparer(resourceGroupName string, autoscaleSettingName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "autoscaleSettingName": autorest.Encode("path", autoscaleSettingName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/autoscalesettings/{autoscaleSettingName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client AutoscaleSettingsClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client AutoscaleSettingsClient) GetResponder(resp *http.Response) (result AutoscaleSettingResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByResourceGroup lists the autoscale settings for a resource group +// +// resourceGroupName is the name of the resource group. +func (client AutoscaleSettingsClient) ListByResourceGroup(resourceGroupName string) (result AutoscaleSettingResourceCollection, err error) { + req, err := client.ListByResourceGroupPreparer(resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "ListByResourceGroup", resp, "Failure sending request") + return + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "ListByResourceGroup", resp, "Failure responding to request") + } + + return +} + +// ListByResourceGroupPreparer prepares the ListByResourceGroup request. +func (client AutoscaleSettingsClient) ListByResourceGroupPreparer(resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/autoscalesettings", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client AutoscaleSettingsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (client AutoscaleSettingsClient) ListByResourceGroupResponder(resp *http.Response) (result AutoscaleSettingResourceCollection, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByResourceGroupNextResults retrieves the next set of results, if any. +func (client AutoscaleSettingsClient) ListByResourceGroupNextResults(lastResults AutoscaleSettingResourceCollection) (result AutoscaleSettingResourceCollection, err error) { + req, err := lastResults.AutoscaleSettingResourceCollectionPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "ListByResourceGroup", nil, "Failure preparing next results request") + } + if req == nil { + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "ListByResourceGroup", resp, "Failure sending next results request") + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "ListByResourceGroup", resp, "Failure responding to next results request") + } + + return +} + +// ListByResourceGroupComplete gets all elements from the list without paging. +func (client AutoscaleSettingsClient) ListByResourceGroupComplete(resourceGroupName string, cancel <-chan struct{}) (<-chan AutoscaleSettingResource, <-chan error) { + resultChan := make(chan AutoscaleSettingResource) + errChan := make(chan error, 1) + go func() { + defer func() { + close(resultChan) + close(errChan) + }() + list, err := client.ListByResourceGroup(resourceGroupName) + if err != nil { + errChan <- err + return + } + if list.Value != nil { + for _, item := range *list.Value { + select { + case <-cancel: + return + case resultChan <- item: + // Intentionally left blank + } + } + } + for list.NextLink != nil { + list, err = client.ListByResourceGroupNextResults(list) + if err != nil { + errChan <- err + return + } + if list.Value != nil { + for _, item := range *list.Value { + select { + case <-cancel: + return + case resultChan <- item: + // Intentionally left blank + } + } + } + } + }() + return resultChan, errChan +} + +// Update updates an existing AutoscaleSettingsResource. To update other fields use the CreateOrUpdate method. +// +// resourceGroupName is the name of the resource group. autoscaleSettingName is the autoscale setting name. +// autoscaleSettingResource is parameters supplied to the operation. +func (client AutoscaleSettingsClient) Update(resourceGroupName string, autoscaleSettingName string, autoscaleSettingResource AutoscaleSettingResourcePatch) (result AutoscaleSettingResource, err error) { + req, err := client.UpdatePreparer(resourceGroupName, autoscaleSettingName, autoscaleSettingResource) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.AutoscaleSettingsClient", "Update", resp, "Failure responding to request") + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client AutoscaleSettingsClient) UpdatePreparer(resourceGroupName string, autoscaleSettingName string, autoscaleSettingResource AutoscaleSettingResourcePatch) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "autoscaleSettingName": autorest.Encode("path", autoscaleSettingName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/autoscalesettings/{autoscaleSettingName}", pathParameters), + autorest.WithJSON(autoscaleSettingResource), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client AutoscaleSettingsClient) UpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client AutoscaleSettingsClient) UpdateResponder(resp *http.Response) (result AutoscaleSettingResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/client.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/client.go new file mode 100755 index 000000000000..ef04adcb8760 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/client.go @@ -0,0 +1,51 @@ +// Package monitor implements the Azure ARM Monitor service API version . +// +// Monitor Management Client +package monitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" +) + +const ( + // DefaultBaseURI is the default URI used for the service Monitor + DefaultBaseURI = "https://management.azure.com" +) + +// ManagementClient is the base client for Monitor. +type ManagementClient struct { + autorest.Client + BaseURI string + SubscriptionID string +} + +// New creates an instance of the ManagementClient client. +func New(subscriptionID string) ManagementClient { + return NewWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewWithBaseURI creates an instance of the ManagementClient client. +func NewWithBaseURI(baseURI string, subscriptionID string) ManagementClient { + return ManagementClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseURI: baseURI, + SubscriptionID: subscriptionID, + } +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/diagnosticsettings.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/diagnosticsettings.go new file mode 100644 index 000000000000..a0da9c77c3d0 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/diagnosticsettings.go @@ -0,0 +1,296 @@ +package monitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" +) + +// DiagnosticSettingsClient is the monitor Management Client +type DiagnosticSettingsClient struct { + ManagementClient +} + +// NewDiagnosticSettingsClient creates an instance of the DiagnosticSettingsClient client. +func NewDiagnosticSettingsClient(subscriptionID string) DiagnosticSettingsClient { + return NewDiagnosticSettingsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewDiagnosticSettingsClientWithBaseURI creates an instance of the DiagnosticSettingsClient client. +func NewDiagnosticSettingsClientWithBaseURI(baseURI string, subscriptionID string) DiagnosticSettingsClient { + return DiagnosticSettingsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates or updates diagnostic settings for the specified resource. +// +// resourceURI is the identifier of the resource. parameters is parameters supplied to the operation. name is the name +// of the diagnostic setting. +func (client DiagnosticSettingsClient) CreateOrUpdate(resourceURI string, parameters DiagnosticSettingsResource, name string) (result DiagnosticSettingsResource, err error) { + req, err := client.CreateOrUpdatePreparer(resourceURI, parameters, name) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client DiagnosticSettingsClient) CreateOrUpdatePreparer(resourceURI string, parameters DiagnosticSettingsResource, name string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "name": autorest.Encode("path", name), + "resourceUri": autorest.Encode("path", resourceURI), + } + + const APIVersion = "2017-05-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceUri}/providers/microsoft.insights/diagnosticSettings/{name}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client DiagnosticSettingsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client DiagnosticSettingsClient) CreateOrUpdateResponder(resp *http.Response) (result DiagnosticSettingsResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete deletes existing diagnostic settings for the specified resource. +// +// resourceURI is the identifier of the resource. name is the name of the diagnostic setting. +func (client DiagnosticSettingsClient) Delete(resourceURI string, name string) (result autorest.Response, err error) { + req, err := client.DeletePreparer(resourceURI, name) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client DiagnosticSettingsClient) DeletePreparer(resourceURI string, name string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "name": autorest.Encode("path", name), + "resourceUri": autorest.Encode("path", resourceURI), + } + + const APIVersion = "2017-05-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceUri}/providers/microsoft.insights/diagnosticSettings/{name}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client DiagnosticSettingsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client DiagnosticSettingsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get gets the active diagnostic settings for the specified resource. +// +// resourceURI is the identifier of the resource. name is the name of the diagnostic setting. +func (client DiagnosticSettingsClient) Get(resourceURI string, name string) (result DiagnosticSettingsResource, err error) { + req, err := client.GetPreparer(resourceURI, name) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client DiagnosticSettingsClient) GetPreparer(resourceURI string, name string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "name": autorest.Encode("path", name), + "resourceUri": autorest.Encode("path", resourceURI), + } + + const APIVersion = "2017-05-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceUri}/providers/microsoft.insights/diagnosticSettings/{name}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client DiagnosticSettingsClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client DiagnosticSettingsClient) GetResponder(resp *http.Response) (result DiagnosticSettingsResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List gets the active diagnostic settings list for the specified resource. +// +// resourceURI is the identifier of the resource. +func (client DiagnosticSettingsClient) List(resourceURI string) (result DiagnosticSettingsResourceCollection, err error) { + req, err := client.ListPreparer(resourceURI) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client DiagnosticSettingsClient) ListPreparer(resourceURI string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceUri": autorest.Encode("path", resourceURI), + } + + const APIVersion = "2017-05-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceUri}/providers/microsoft.insights/diagnosticSettings", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client DiagnosticSettingsClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client DiagnosticSettingsClient) ListResponder(resp *http.Response) (result DiagnosticSettingsResourceCollection, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/diagnosticsettingscategory.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/diagnosticsettingscategory.go new file mode 100644 index 000000000000..da7c096ae635 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/diagnosticsettingscategory.go @@ -0,0 +1,166 @@ +package monitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" +) + +// DiagnosticSettingsCategoryClient is the monitor Management Client +type DiagnosticSettingsCategoryClient struct { + ManagementClient +} + +// NewDiagnosticSettingsCategoryClient creates an instance of the DiagnosticSettingsCategoryClient client. +func NewDiagnosticSettingsCategoryClient(subscriptionID string) DiagnosticSettingsCategoryClient { + return NewDiagnosticSettingsCategoryClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewDiagnosticSettingsCategoryClientWithBaseURI creates an instance of the DiagnosticSettingsCategoryClient client. +func NewDiagnosticSettingsCategoryClientWithBaseURI(baseURI string, subscriptionID string) DiagnosticSettingsCategoryClient { + return DiagnosticSettingsCategoryClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// Get gets the diagnostic settings category for the specified resource. +// +// resourceURI is the identifier of the resource. name is the name of the diagnostic setting. +func (client DiagnosticSettingsCategoryClient) Get(resourceURI string, name string) (result DiagnosticSettingsCategoryResource, err error) { + req, err := client.GetPreparer(resourceURI, name) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsCategoryClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsCategoryClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsCategoryClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client DiagnosticSettingsCategoryClient) GetPreparer(resourceURI string, name string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "name": autorest.Encode("path", name), + "resourceUri": autorest.Encode("path", resourceURI), + } + + const APIVersion = "2017-05-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceUri}/providers/microsoft.insights/diagnosticSettingsCategories/{name}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client DiagnosticSettingsCategoryClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client DiagnosticSettingsCategoryClient) GetResponder(resp *http.Response) (result DiagnosticSettingsCategoryResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List lists the diagnostic settings categories for the specified resource. +// +// resourceURI is the identifier of the resource. +func (client DiagnosticSettingsCategoryClient) List(resourceURI string) (result DiagnosticSettingsCategoryResourceCollection, err error) { + req, err := client.ListPreparer(resourceURI) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsCategoryClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsCategoryClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.DiagnosticSettingsCategoryClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client DiagnosticSettingsCategoryClient) ListPreparer(resourceURI string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceUri": autorest.Encode("path", resourceURI), + } + + const APIVersion = "2017-05-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceUri}/providers/microsoft.insights/diagnosticSettingsCategories", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client DiagnosticSettingsCategoryClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client DiagnosticSettingsCategoryClient) ListResponder(resp *http.Response) (result DiagnosticSettingsCategoryResourceCollection, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/logprofiles.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/logprofiles.go new file mode 100755 index 000000000000..e7f8d7292246 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/logprofiles.go @@ -0,0 +1,374 @@ +package monitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// LogProfilesClient is the monitor Management Client +type LogProfilesClient struct { + ManagementClient +} + +// NewLogProfilesClient creates an instance of the LogProfilesClient client. +func NewLogProfilesClient(subscriptionID string) LogProfilesClient { + return NewLogProfilesClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewLogProfilesClientWithBaseURI creates an instance of the LogProfilesClient client. +func NewLogProfilesClientWithBaseURI(baseURI string, subscriptionID string) LogProfilesClient { + return LogProfilesClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate create or update a log profile in Azure Monitoring REST API. +// +// logProfileName is the name of the log profile. parameters is parameters supplied to the operation. +func (client LogProfilesClient) CreateOrUpdate(logProfileName string, parameters LogProfileResource) (result LogProfileResource, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.LogProfileProperties", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "parameters.LogProfileProperties.Locations", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "parameters.LogProfileProperties.Categories", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "parameters.LogProfileProperties.RetentionPolicy", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "parameters.LogProfileProperties.RetentionPolicy.Enabled", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "parameters.LogProfileProperties.RetentionPolicy.Days", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "parameters.LogProfileProperties.RetentionPolicy.Days", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}, + }}, + }}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "monitor.LogProfilesClient", "CreateOrUpdate") + } + + req, err := client.CreateOrUpdatePreparer(logProfileName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.LogProfilesClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.LogProfilesClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.LogProfilesClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client LogProfilesClient) CreateOrUpdatePreparer(logProfileName string, parameters LogProfileResource) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "logProfileName": autorest.Encode("path", logProfileName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2016-03-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/logprofiles/{logProfileName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client LogProfilesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client LogProfilesClient) CreateOrUpdateResponder(resp *http.Response) (result LogProfileResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete deletes the log profile. +// +// logProfileName is the name of the log profile. +func (client LogProfilesClient) Delete(logProfileName string) (result autorest.Response, err error) { + req, err := client.DeletePreparer(logProfileName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.LogProfilesClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "monitor.LogProfilesClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.LogProfilesClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client LogProfilesClient) DeletePreparer(logProfileName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "logProfileName": autorest.Encode("path", logProfileName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2016-03-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/logprofiles/{logProfileName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client LogProfilesClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client LogProfilesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get gets the log profile. +// +// logProfileName is the name of the log profile. +func (client LogProfilesClient) Get(logProfileName string) (result LogProfileResource, err error) { + req, err := client.GetPreparer(logProfileName) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.LogProfilesClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.LogProfilesClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.LogProfilesClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client LogProfilesClient) GetPreparer(logProfileName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "logProfileName": autorest.Encode("path", logProfileName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2016-03-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/logprofiles/{logProfileName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client LogProfilesClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client LogProfilesClient) GetResponder(resp *http.Response) (result LogProfileResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List list the log profiles. +func (client LogProfilesClient) List() (result LogProfileCollection, err error) { + req, err := client.ListPreparer() + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.LogProfilesClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.LogProfilesClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.LogProfilesClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client LogProfilesClient) ListPreparer() (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2016-03-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/logprofiles", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client LogProfilesClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client LogProfilesClient) ListResponder(resp *http.Response) (result LogProfileCollection, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Update updates an existing LogProfilesResource. To update other fields use the CreateOrUpdate method. +// +// logProfileName is the name of the log profile. logProfilesResource is parameters supplied to the operation. +func (client LogProfilesClient) Update(logProfileName string, logProfilesResource LogProfileResourcePatch) (result LogProfileResource, err error) { + req, err := client.UpdatePreparer(logProfileName, logProfilesResource) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.LogProfilesClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.LogProfilesClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.LogProfilesClient", "Update", resp, "Failure responding to request") + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client LogProfilesClient) UpdatePreparer(logProfileName string, logProfilesResource LogProfileResourcePatch) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "logProfileName": autorest.Encode("path", logProfileName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2016-03-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/logprofiles/{logProfileName}", pathParameters), + autorest.WithJSON(logProfilesResource), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client LogProfilesClient) UpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client LogProfilesClient) UpdateResponder(resp *http.Response) (result LogProfileResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/models.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/models.go new file mode 100755 index 000000000000..272ae76bf886 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/models.go @@ -0,0 +1,1260 @@ +package monitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "encoding/json" + "errors" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/date" + "github.com/Azure/go-autorest/autorest/to" + "net/http" +) + +// CategoryType enumerates the values for category type. +type CategoryType string + +const ( + // Logs specifies the logs state for category type. + Logs CategoryType = "Logs" + // Metrics specifies the metrics state for category type. + Metrics CategoryType = "Metrics" +) + +// ComparisonOperationType enumerates the values for comparison operation type. +type ComparisonOperationType string + +const ( + // Equals specifies the equals state for comparison operation type. + Equals ComparisonOperationType = "Equals" + // GreaterThan specifies the greater than state for comparison operation type. + GreaterThan ComparisonOperationType = "GreaterThan" + // GreaterThanOrEqual specifies the greater than or equal state for comparison operation type. + GreaterThanOrEqual ComparisonOperationType = "GreaterThanOrEqual" + // LessThan specifies the less than state for comparison operation type. + LessThan ComparisonOperationType = "LessThan" + // LessThanOrEqual specifies the less than or equal state for comparison operation type. + LessThanOrEqual ComparisonOperationType = "LessThanOrEqual" + // NotEquals specifies the not equals state for comparison operation type. + NotEquals ComparisonOperationType = "NotEquals" +) + +// ConditionOperator enumerates the values for condition operator. +type ConditionOperator string + +const ( + // ConditionOperatorGreaterThan specifies the condition operator greater than state for condition operator. + ConditionOperatorGreaterThan ConditionOperator = "GreaterThan" + // ConditionOperatorGreaterThanOrEqual specifies the condition operator greater than or equal state for condition + // operator. + ConditionOperatorGreaterThanOrEqual ConditionOperator = "GreaterThanOrEqual" + // ConditionOperatorLessThan specifies the condition operator less than state for condition operator. + ConditionOperatorLessThan ConditionOperator = "LessThan" + // ConditionOperatorLessThanOrEqual specifies the condition operator less than or equal state for condition operator. + ConditionOperatorLessThanOrEqual ConditionOperator = "LessThanOrEqual" +) + +// MetricStatisticType enumerates the values for metric statistic type. +type MetricStatisticType string + +const ( + // Average specifies the average state for metric statistic type. + Average MetricStatisticType = "Average" + // Max specifies the max state for metric statistic type. + Max MetricStatisticType = "Max" + // Min specifies the min state for metric statistic type. + Min MetricStatisticType = "Min" + // Sum specifies the sum state for metric statistic type. + Sum MetricStatisticType = "Sum" +) + +// OdataType enumerates the values for odata type. +type OdataType string + +const ( + // OdataTypeMicrosoftAzureManagementInsightsModelsRuleManagementEventDataSource specifies the odata type microsoft + // azure management insights models rule management event data source state for odata type. + OdataTypeMicrosoftAzureManagementInsightsModelsRuleManagementEventDataSource OdataType = "Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource" + // OdataTypeMicrosoftAzureManagementInsightsModelsRuleMetricDataSource specifies the odata type microsoft azure + // management insights models rule metric data source state for odata type. + OdataTypeMicrosoftAzureManagementInsightsModelsRuleMetricDataSource OdataType = "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource" +) + +// OdataType1 enumerates the values for odata type 1. +type OdataType1 string + +const ( + // OdataTypeMicrosoftAzureManagementInsightsModelsLocationThresholdRuleCondition specifies the odata type microsoft + // azure management insights models location threshold rule condition state for odata type 1. + OdataTypeMicrosoftAzureManagementInsightsModelsLocationThresholdRuleCondition OdataType1 = "Microsoft.Azure.Management.Insights.Models.LocationThresholdRuleCondition" + // OdataTypeMicrosoftAzureManagementInsightsModelsManagementEventRuleCondition specifies the odata type microsoft azure + // management insights models management event rule condition state for odata type 1. + OdataTypeMicrosoftAzureManagementInsightsModelsManagementEventRuleCondition OdataType1 = "Microsoft.Azure.Management.Insights.Models.ManagementEventRuleCondition" + // OdataTypeMicrosoftAzureManagementInsightsModelsThresholdRuleCondition specifies the odata type microsoft azure + // management insights models threshold rule condition state for odata type 1. + OdataTypeMicrosoftAzureManagementInsightsModelsThresholdRuleCondition OdataType1 = "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition" +) + +// OdataType2 enumerates the values for odata type 2. +type OdataType2 string + +const ( + // OdataTypeMicrosoftAzureManagementInsightsModelsRuleEmailAction specifies the odata type microsoft azure management + // insights models rule email action state for odata type 2. + OdataTypeMicrosoftAzureManagementInsightsModelsRuleEmailAction OdataType2 = "Microsoft.Azure.Management.Insights.Models.RuleEmailAction" + // OdataTypeMicrosoftAzureManagementInsightsModelsRuleWebhookAction specifies the odata type microsoft azure management + // insights models rule webhook action state for odata type 2. + OdataTypeMicrosoftAzureManagementInsightsModelsRuleWebhookAction OdataType2 = "Microsoft.Azure.Management.Insights.Models.RuleWebhookAction" +) + +// ReceiverStatus enumerates the values for receiver status. +type ReceiverStatus string + +const ( + // Disabled specifies the disabled state for receiver status. + Disabled ReceiverStatus = "Disabled" + // Enabled specifies the enabled state for receiver status. + Enabled ReceiverStatus = "Enabled" + // NotSpecified specifies the not specified state for receiver status. + NotSpecified ReceiverStatus = "NotSpecified" +) + +// RecurrenceFrequency enumerates the values for recurrence frequency. +type RecurrenceFrequency string + +const ( + // Day specifies the day state for recurrence frequency. + Day RecurrenceFrequency = "Day" + // Hour specifies the hour state for recurrence frequency. + Hour RecurrenceFrequency = "Hour" + // Minute specifies the minute state for recurrence frequency. + Minute RecurrenceFrequency = "Minute" + // Month specifies the month state for recurrence frequency. + Month RecurrenceFrequency = "Month" + // None specifies the none state for recurrence frequency. + None RecurrenceFrequency = "None" + // Second specifies the second state for recurrence frequency. + Second RecurrenceFrequency = "Second" + // Week specifies the week state for recurrence frequency. + Week RecurrenceFrequency = "Week" + // Year specifies the year state for recurrence frequency. + Year RecurrenceFrequency = "Year" +) + +// ScaleDirection enumerates the values for scale direction. +type ScaleDirection string + +const ( + // ScaleDirectionDecrease specifies the scale direction decrease state for scale direction. + ScaleDirectionDecrease ScaleDirection = "Decrease" + // ScaleDirectionIncrease specifies the scale direction increase state for scale direction. + ScaleDirectionIncrease ScaleDirection = "Increase" + // ScaleDirectionNone specifies the scale direction none state for scale direction. + ScaleDirectionNone ScaleDirection = "None" +) + +// ScaleType enumerates the values for scale type. +type ScaleType string + +const ( + // ChangeCount specifies the change count state for scale type. + ChangeCount ScaleType = "ChangeCount" + // ExactCount specifies the exact count state for scale type. + ExactCount ScaleType = "ExactCount" + // PercentChangeCount specifies the percent change count state for scale type. + PercentChangeCount ScaleType = "PercentChangeCount" +) + +// TimeAggregationOperator enumerates the values for time aggregation operator. +type TimeAggregationOperator string + +const ( + // TimeAggregationOperatorAverage specifies the time aggregation operator average state for time aggregation operator. + TimeAggregationOperatorAverage TimeAggregationOperator = "Average" + // TimeAggregationOperatorLast specifies the time aggregation operator last state for time aggregation operator. + TimeAggregationOperatorLast TimeAggregationOperator = "Last" + // TimeAggregationOperatorMaximum specifies the time aggregation operator maximum state for time aggregation operator. + TimeAggregationOperatorMaximum TimeAggregationOperator = "Maximum" + // TimeAggregationOperatorMinimum specifies the time aggregation operator minimum state for time aggregation operator. + TimeAggregationOperatorMinimum TimeAggregationOperator = "Minimum" + // TimeAggregationOperatorTotal specifies the time aggregation operator total state for time aggregation operator. + TimeAggregationOperatorTotal TimeAggregationOperator = "Total" +) + +// TimeAggregationType enumerates the values for time aggregation type. +type TimeAggregationType string + +const ( + // TimeAggregationTypeAverage specifies the time aggregation type average state for time aggregation type. + TimeAggregationTypeAverage TimeAggregationType = "Average" + // TimeAggregationTypeCount specifies the time aggregation type count state for time aggregation type. + TimeAggregationTypeCount TimeAggregationType = "Count" + // TimeAggregationTypeMaximum specifies the time aggregation type maximum state for time aggregation type. + TimeAggregationTypeMaximum TimeAggregationType = "Maximum" + // TimeAggregationTypeMinimum specifies the time aggregation type minimum state for time aggregation type. + TimeAggregationTypeMinimum TimeAggregationType = "Minimum" + // TimeAggregationTypeTotal specifies the time aggregation type total state for time aggregation type. + TimeAggregationTypeTotal TimeAggregationType = "Total" +) + +// ActionGroup is an Azure action group. +type ActionGroup struct { + GroupShortName *string `json:"groupShortName,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + EmailReceivers *[]EmailReceiver `json:"emailReceivers,omitempty"` + SmsReceivers *[]SmsReceiver `json:"smsReceivers,omitempty"` + WebhookReceivers *[]WebhookReceiver `json:"webhookReceivers,omitempty"` +} + +// ActionGroupList is a list of action groups. +type ActionGroupList struct { + autorest.Response `json:"-"` + Value *[]ActionGroupResource `json:"value,omitempty"` + NextLink *string `json:"nextLink,omitempty"` +} + +// ActionGroupResource is an action group resource. +type ActionGroupResource struct { + autorest.Response `json:"-"` + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + Location *string `json:"location,omitempty"` + Tags *map[string]*string `json:"tags,omitempty"` + *ActionGroup `json:"properties,omitempty"` +} + +// ActivityLogAlert is an Azure activity log alert. +type ActivityLogAlert struct { + Scopes *[]string `json:"scopes,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + Condition *ActivityLogAlertAllOfCondition `json:"condition,omitempty"` + Actions *ActivityLogAlertActionList `json:"actions,omitempty"` + Description *string `json:"description,omitempty"` +} + +// ActivityLogAlertActionGroup is a pointer to an Azure Action Group. +type ActivityLogAlertActionGroup struct { + ActionGroupID *string `json:"actionGroupId,omitempty"` + WebhookProperties *map[string]*string `json:"webhookProperties,omitempty"` +} + +// ActivityLogAlertActionList is a list of activity log alert actions. +type ActivityLogAlertActionList struct { + ActionGroups *[]ActivityLogAlertActionGroup `json:"actionGroups,omitempty"` +} + +// ActivityLogAlertAllOfCondition is an Activity Log alert condition that is met when all its member conditions are +// met. +type ActivityLogAlertAllOfCondition struct { + AllOf *[]ActivityLogAlertLeafCondition `json:"allOf,omitempty"` +} + +// ActivityLogAlertLeafCondition is an Activity Log alert condition that is met by comparing an activity log field and +// value. +type ActivityLogAlertLeafCondition struct { + Field *string `json:"field,omitempty"` + Equals *string `json:"equals,omitempty"` +} + +// ActivityLogAlertList is a list of activity log alerts. +type ActivityLogAlertList struct { + autorest.Response `json:"-"` + Value *[]ActivityLogAlertResource `json:"value,omitempty"` + NextLink *string `json:"nextLink,omitempty"` +} + +// ActivityLogAlertPatch is an Azure activity log alert for patch operations. +type ActivityLogAlertPatch struct { + Enabled *bool `json:"enabled,omitempty"` +} + +// ActivityLogAlertPatchBody is an activity log alert object for the body of patch operations. +type ActivityLogAlertPatchBody struct { + Tags *map[string]*string `json:"tags,omitempty"` + *ActivityLogAlertPatch `json:"properties,omitempty"` +} + +// ActivityLogAlertResource is an activity log alert resource. +type ActivityLogAlertResource struct { + autorest.Response `json:"-"` + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + Location *string `json:"location,omitempty"` + Tags *map[string]*string `json:"tags,omitempty"` + *ActivityLogAlert `json:"properties,omitempty"` +} + +// AlertRule is an alert rule. +type AlertRule struct { + Name *string `json:"name,omitempty"` + Description *string `json:"description,omitempty"` + IsEnabled *bool `json:"isEnabled,omitempty"` + Condition RuleCondition `json:"condition,omitempty"` + Actions *[]RuleAction `json:"actions,omitempty"` + LastUpdatedTime *date.Time `json:"lastUpdatedTime,omitempty"` +} + +// UnmarshalJSON is the custom unmarshaler for AlertRule struct. +func (ar *AlertRule) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + var v *json.RawMessage + + v = m["name"] + if v != nil { + var name string + err = json.Unmarshal(*m["name"], &name) + if err != nil { + return err + } + ar.Name = &name + } + + v = m["description"] + if v != nil { + var description string + err = json.Unmarshal(*m["description"], &description) + if err != nil { + return err + } + ar.Description = &description + } + + v = m["isEnabled"] + if v != nil { + var isEnabled bool + err = json.Unmarshal(*m["isEnabled"], &isEnabled) + if err != nil { + return err + } + ar.IsEnabled = &isEnabled + } + + v = m["condition"] + if v != nil { + condition, err := unmarshalRuleCondition(*m["condition"]) + if err != nil { + return err + } + ar.Condition = condition + } + + v = m["actions"] + if v != nil { + actions, err := unmarshalRuleActionArray(*m["actions"]) + if err != nil { + return err + } + ar.Actions = &actions + } + + v = m["lastUpdatedTime"] + if v != nil { + var lastUpdatedTime date.Time + err = json.Unmarshal(*m["lastUpdatedTime"], &lastUpdatedTime) + if err != nil { + return err + } + ar.LastUpdatedTime = &lastUpdatedTime + } + + return nil +} + +// AlertRuleResource is the alert rule resource. +type AlertRuleResource struct { + autorest.Response `json:"-"` + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + Location *string `json:"location,omitempty"` + Tags *map[string]*string `json:"tags,omitempty"` + *AlertRule `json:"properties,omitempty"` +} + +// AlertRuleResourceCollection is represents a collection of alert rule resources. +type AlertRuleResourceCollection struct { + autorest.Response `json:"-"` + Value *[]AlertRuleResource `json:"value,omitempty"` +} + +// AlertRuleResourcePatch is the alert rule object for patch operations. +type AlertRuleResourcePatch struct { + Tags *map[string]*string `json:"tags,omitempty"` + *AlertRule `json:"properties,omitempty"` +} + +// AutoscaleNotification is autoscale notification. +type AutoscaleNotification struct { + Operation *string `json:"operation,omitempty"` + Email *EmailNotification `json:"email,omitempty"` + Webhooks *[]WebhookNotification `json:"webhooks,omitempty"` +} + +// AutoscaleProfile is autoscale profile. +type AutoscaleProfile struct { + Name *string `json:"name,omitempty"` + Capacity *ScaleCapacity `json:"capacity,omitempty"` + Rules *[]ScaleRule `json:"rules,omitempty"` + FixedDate *TimeWindow `json:"fixedDate,omitempty"` + Recurrence *Recurrence `json:"recurrence,omitempty"` +} + +// AutoscaleSetting is a setting that contains all of the configuration for the automatic scaling of a resource. +type AutoscaleSetting struct { + Profiles *[]AutoscaleProfile `json:"profiles,omitempty"` + Notifications *[]AutoscaleNotification `json:"notifications,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + Name *string `json:"name,omitempty"` + TargetResourceURI *string `json:"targetResourceUri,omitempty"` +} + +// AutoscaleSettingResource is the autoscale setting resource. +type AutoscaleSettingResource struct { + autorest.Response `json:"-"` + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + Location *string `json:"location,omitempty"` + Tags *map[string]*string `json:"tags,omitempty"` + *AutoscaleSetting `json:"properties,omitempty"` +} + +// AutoscaleSettingResourceCollection is represents a collection of autoscale setting resources. +type AutoscaleSettingResourceCollection struct { + autorest.Response `json:"-"` + Value *[]AutoscaleSettingResource `json:"value,omitempty"` + NextLink *string `json:"nextLink,omitempty"` +} + +// AutoscaleSettingResourceCollectionPreparer prepares a request to retrieve the next set of results. It returns +// nil if no more results exist. +func (client AutoscaleSettingResourceCollection) AutoscaleSettingResourceCollectionPreparer() (*http.Request, error) { + if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(client.NextLink))) +} + +// AutoscaleSettingResourcePatch is the autoscale setting object for patch operations. +type AutoscaleSettingResourcePatch struct { + Tags *map[string]*string `json:"tags,omitempty"` + *AutoscaleSetting `json:"properties,omitempty"` +} + +// DiagnosticSettings is the diagnostic settings. +type DiagnosticSettings struct { + StorageAccountID *string `json:"storageAccountId,omitempty"` + EventHubAuthorizationRuleID *string `json:"eventHubAuthorizationRuleId,omitempty"` + EventHubName *string `json:"eventHubName,omitempty"` + Metrics *[]MetricSettings `json:"metrics,omitempty"` + Logs *[]LogSettings `json:"logs,omitempty"` + WorkspaceID *string `json:"workspaceId,omitempty"` +} + +// DiagnosticSettingsCategory is the diagnostic settings Category. +type DiagnosticSettingsCategory struct { + CategoryType CategoryType `json:"categoryType,omitempty"` +} + +// DiagnosticSettingsCategoryResource is the diagnostic settings category resource. +type DiagnosticSettingsCategoryResource struct { + autorest.Response `json:"-"` + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + *DiagnosticSettingsCategory `json:"properties,omitempty"` +} + +// DiagnosticSettingsCategoryResourceCollection is represents a collection of diagnostic setting category resources. +type DiagnosticSettingsCategoryResourceCollection struct { + autorest.Response `json:"-"` + Value *[]DiagnosticSettingsCategoryResource `json:"value,omitempty"` +} + +// DiagnosticSettingsResource is the diagnostic setting resource. +type DiagnosticSettingsResource struct { + autorest.Response `json:"-"` + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + *DiagnosticSettings `json:"properties,omitempty"` +} + +// DiagnosticSettingsResourceCollection is represents a collection of alert rule resources. +type DiagnosticSettingsResourceCollection struct { + autorest.Response `json:"-"` + Value *[]DiagnosticSettingsResource `json:"value,omitempty"` +} + +// EmailNotification is email notification of an autoscale event. +type EmailNotification struct { + SendToSubscriptionAdministrator *bool `json:"sendToSubscriptionAdministrator,omitempty"` + SendToSubscriptionCoAdministrators *bool `json:"sendToSubscriptionCoAdministrators,omitempty"` + CustomEmails *[]string `json:"customEmails,omitempty"` +} + +// EmailReceiver is an email receiver. +type EmailReceiver struct { + Name *string `json:"name,omitempty"` + EmailAddress *string `json:"emailAddress,omitempty"` + Status ReceiverStatus `json:"status,omitempty"` +} + +// EnableRequest is describes a receiver that should be resubscribed. +type EnableRequest struct { + ReceiverName *string `json:"receiverName,omitempty"` +} + +// ErrorResponse is describes the format of Error response. +type ErrorResponse struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} + +// Incident is an alert incident indicates the activation status of an alert rule. +type Incident struct { + autorest.Response `json:"-"` + Name *string `json:"name,omitempty"` + RuleName *string `json:"ruleName,omitempty"` + IsActive *bool `json:"isActive,omitempty"` + ActivatedTime *date.Time `json:"activatedTime,omitempty"` + ResolvedTime *date.Time `json:"resolvedTime,omitempty"` +} + +// IncidentListResult is the List incidents operation response. +type IncidentListResult struct { + autorest.Response `json:"-"` + Value *[]Incident `json:"value,omitempty"` +} + +// LocationThresholdRuleCondition is a rule condition based on a certain number of locations failing. +type LocationThresholdRuleCondition struct { + DataSource RuleDataSource `json:"dataSource,omitempty"` + OdataType OdataType1 `json:"odata.type,omitempty"` + WindowSize *string `json:"windowSize,omitempty"` + FailedLocationCount *int32 `json:"failedLocationCount,omitempty"` +} + +// MarshalJSON is the custom marshaler for LocationThresholdRuleCondition. +func (ltrc LocationThresholdRuleCondition) MarshalJSON() ([]byte, error) { + ltrc.OdataType = OdataTypeMicrosoftAzureManagementInsightsModelsLocationThresholdRuleCondition + type Alias LocationThresholdRuleCondition + return json.Marshal(&struct { + Alias + }{ + Alias: (Alias)(ltrc), + }) +} + +// AsThresholdRuleCondition is the RuleCondition implementation for LocationThresholdRuleCondition. +func (ltrc LocationThresholdRuleCondition) AsThresholdRuleCondition() (*ThresholdRuleCondition, bool) { + return nil, false +} + +// AsLocationThresholdRuleCondition is the RuleCondition implementation for LocationThresholdRuleCondition. +func (ltrc LocationThresholdRuleCondition) AsLocationThresholdRuleCondition() (*LocationThresholdRuleCondition, bool) { + return <rc, true +} + +// AsManagementEventRuleCondition is the RuleCondition implementation for LocationThresholdRuleCondition. +func (ltrc LocationThresholdRuleCondition) AsManagementEventRuleCondition() (*ManagementEventRuleCondition, bool) { + return nil, false +} + +// UnmarshalJSON is the custom unmarshaler for LocationThresholdRuleCondition struct. +func (ltrc *LocationThresholdRuleCondition) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + var v *json.RawMessage + + v = m["windowSize"] + if v != nil { + var windowSize string + err = json.Unmarshal(*m["windowSize"], &windowSize) + if err != nil { + return err + } + ltrc.WindowSize = &windowSize + } + + v = m["failedLocationCount"] + if v != nil { + var failedLocationCount int32 + err = json.Unmarshal(*m["failedLocationCount"], &failedLocationCount) + if err != nil { + return err + } + ltrc.FailedLocationCount = &failedLocationCount + } + + v = m["dataSource"] + if v != nil { + dataSource, err := unmarshalRuleDataSource(*m["dataSource"]) + if err != nil { + return err + } + ltrc.DataSource = dataSource + } + + v = m["odata.type"] + if v != nil { + var odatatype OdataType1 + err = json.Unmarshal(*m["odata.type"], &odatatype) + if err != nil { + return err + } + ltrc.OdataType = odatatype + } + + return nil +} + +// LogProfileCollection is represents a collection of log profiles. +type LogProfileCollection struct { + autorest.Response `json:"-"` + Value *[]LogProfileResource `json:"value,omitempty"` +} + +// LogProfileProperties is the log profile properties. +type LogProfileProperties struct { + StorageAccountID *string `json:"storageAccountId,omitempty"` + ServiceBusRuleID *string `json:"serviceBusRuleId,omitempty"` + Locations *[]string `json:"locations,omitempty"` + Categories *[]string `json:"categories,omitempty"` + RetentionPolicy *RetentionPolicy `json:"retentionPolicy,omitempty"` +} + +// LogProfileResource is the log profile resource. +type LogProfileResource struct { + autorest.Response `json:"-"` + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + Location *string `json:"location,omitempty"` + Tags *map[string]*string `json:"tags,omitempty"` + *LogProfileProperties `json:"properties,omitempty"` +} + +// LogProfileResourcePatch is the log profile resource for patch operations. +type LogProfileResourcePatch struct { + Tags *map[string]*string `json:"tags,omitempty"` + *LogProfileProperties `json:"properties,omitempty"` +} + +// LogSettings is part of MultiTenantDiagnosticSettings. Specifies the settings for a particular log. +type LogSettings struct { + Category *string `json:"category,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + RetentionPolicy *RetentionPolicy `json:"retentionPolicy,omitempty"` +} + +// ManagementEventAggregationCondition is how the data that is collected should be combined over time. +type ManagementEventAggregationCondition struct { + Operator ConditionOperator `json:"operator,omitempty"` + Threshold *float64 `json:"threshold,omitempty"` + WindowSize *string `json:"windowSize,omitempty"` +} + +// ManagementEventRuleCondition is a management event rule condition. +type ManagementEventRuleCondition struct { + DataSource RuleDataSource `json:"dataSource,omitempty"` + OdataType OdataType1 `json:"odata.type,omitempty"` + Aggregation *ManagementEventAggregationCondition `json:"aggregation,omitempty"` +} + +// MarshalJSON is the custom marshaler for ManagementEventRuleCondition. +func (merc ManagementEventRuleCondition) MarshalJSON() ([]byte, error) { + merc.OdataType = OdataTypeMicrosoftAzureManagementInsightsModelsManagementEventRuleCondition + type Alias ManagementEventRuleCondition + return json.Marshal(&struct { + Alias + }{ + Alias: (Alias)(merc), + }) +} + +// AsThresholdRuleCondition is the RuleCondition implementation for ManagementEventRuleCondition. +func (merc ManagementEventRuleCondition) AsThresholdRuleCondition() (*ThresholdRuleCondition, bool) { + return nil, false +} + +// AsLocationThresholdRuleCondition is the RuleCondition implementation for ManagementEventRuleCondition. +func (merc ManagementEventRuleCondition) AsLocationThresholdRuleCondition() (*LocationThresholdRuleCondition, bool) { + return nil, false +} + +// AsManagementEventRuleCondition is the RuleCondition implementation for ManagementEventRuleCondition. +func (merc ManagementEventRuleCondition) AsManagementEventRuleCondition() (*ManagementEventRuleCondition, bool) { + return &merc, true +} + +// UnmarshalJSON is the custom unmarshaler for ManagementEventRuleCondition struct. +func (merc *ManagementEventRuleCondition) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + var v *json.RawMessage + + v = m["aggregation"] + if v != nil { + var aggregation ManagementEventAggregationCondition + err = json.Unmarshal(*m["aggregation"], &aggregation) + if err != nil { + return err + } + merc.Aggregation = &aggregation + } + + v = m["dataSource"] + if v != nil { + dataSource, err := unmarshalRuleDataSource(*m["dataSource"]) + if err != nil { + return err + } + merc.DataSource = dataSource + } + + v = m["odata.type"] + if v != nil { + var odatatype OdataType1 + err = json.Unmarshal(*m["odata.type"], &odatatype) + if err != nil { + return err + } + merc.OdataType = odatatype + } + + return nil +} + +// MetricSettings is part of MultiTenantDiagnosticSettings. Specifies the settings for a particular metric. +type MetricSettings struct { + TimeGrain *string `json:"timeGrain,omitempty"` + Category *string `json:"category,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + RetentionPolicy *RetentionPolicy `json:"retentionPolicy,omitempty"` +} + +// MetricTrigger is the trigger that results in a scaling action. +type MetricTrigger struct { + MetricName *string `json:"metricName,omitempty"` + MetricResourceURI *string `json:"metricResourceUri,omitempty"` + TimeGrain *string `json:"timeGrain,omitempty"` + Statistic MetricStatisticType `json:"statistic,omitempty"` + TimeWindow *string `json:"timeWindow,omitempty"` + TimeAggregation TimeAggregationType `json:"timeAggregation,omitempty"` + Operator ComparisonOperationType `json:"operator,omitempty"` + Threshold *float64 `json:"threshold,omitempty"` +} + +// Operation is microsoft Insights API operation definition. +type Operation struct { + Name *string `json:"name,omitempty"` + Display *OperationDisplay `json:"display,omitempty"` +} + +// OperationDisplay is display metadata associated with the operation. +type OperationDisplay struct { + Provider *string `json:"provider,omitempty"` + Resource *string `json:"resource,omitempty"` + Operation *string `json:"operation,omitempty"` +} + +// OperationListResult is result of the request to list Microsoft.Insights operations. It contains a list of operations +// and a URL link to get the next set of results. +type OperationListResult struct { + autorest.Response `json:"-"` + Value *[]Operation `json:"value,omitempty"` + NextLink *string `json:"nextLink,omitempty"` +} + +// ProxyOnlyResource is a proxy only azure resource object +type ProxyOnlyResource struct { + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} + +// Recurrence is the repeating times at which this profile begins. This element is not used if the FixedDate element is +// used. +type Recurrence struct { + Frequency RecurrenceFrequency `json:"frequency,omitempty"` + Schedule *RecurrentSchedule `json:"schedule,omitempty"` +} + +// RecurrentSchedule is the scheduling constraints for when the profile begins. +type RecurrentSchedule struct { + TimeZone *string `json:"timeZone,omitempty"` + Days *[]string `json:"days,omitempty"` + Hours *[]int32 `json:"hours,omitempty"` + Minutes *[]int32 `json:"minutes,omitempty"` +} + +// Resource is an azure resource object +type Resource struct { + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + Location *string `json:"location,omitempty"` + Tags *map[string]*string `json:"tags,omitempty"` +} + +// RetentionPolicy is specifies the retention policy for the log. +type RetentionPolicy struct { + Enabled *bool `json:"enabled,omitempty"` + Days *int32 `json:"days,omitempty"` +} + +// RuleAction is the action that is performed when the alert rule becomes active, and when an alert condition is +// resolved. +type RuleAction interface { + AsRuleEmailAction() (*RuleEmailAction, bool) + AsRuleWebhookAction() (*RuleWebhookAction, bool) +} + +func unmarshalRuleAction(body []byte) (RuleAction, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["odata.type"] { + case string(OdataTypeMicrosoftAzureManagementInsightsModelsRuleEmailAction): + var rea RuleEmailAction + err := json.Unmarshal(body, &rea) + return rea, err + case string(OdataTypeMicrosoftAzureManagementInsightsModelsRuleWebhookAction): + var rwa RuleWebhookAction + err := json.Unmarshal(body, &rwa) + return rwa, err + default: + return nil, errors.New("Unsupported type") + } +} +func unmarshalRuleActionArray(body []byte) ([]RuleAction, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + raArray := make([]RuleAction, len(rawMessages)) + + for index, rawMessage := range rawMessages { + ra, err := unmarshalRuleAction(*rawMessage) + if err != nil { + return nil, err + } + raArray[index] = ra + } + return raArray, nil +} + +// RuleCondition is the condition that results in the alert rule being activated. +type RuleCondition interface { + AsThresholdRuleCondition() (*ThresholdRuleCondition, bool) + AsLocationThresholdRuleCondition() (*LocationThresholdRuleCondition, bool) + AsManagementEventRuleCondition() (*ManagementEventRuleCondition, bool) +} + +func unmarshalRuleCondition(body []byte) (RuleCondition, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["odata.type"] { + case string(OdataTypeMicrosoftAzureManagementInsightsModelsThresholdRuleCondition): + var trc ThresholdRuleCondition + err := json.Unmarshal(body, &trc) + return trc, err + case string(OdataTypeMicrosoftAzureManagementInsightsModelsLocationThresholdRuleCondition): + var ltrc LocationThresholdRuleCondition + err := json.Unmarshal(body, <rc) + return ltrc, err + case string(OdataTypeMicrosoftAzureManagementInsightsModelsManagementEventRuleCondition): + var merc ManagementEventRuleCondition + err := json.Unmarshal(body, &merc) + return merc, err + default: + return nil, errors.New("Unsupported type") + } +} +func unmarshalRuleConditionArray(body []byte) ([]RuleCondition, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + rcArray := make([]RuleCondition, len(rawMessages)) + + for index, rawMessage := range rawMessages { + rc, err := unmarshalRuleCondition(*rawMessage) + if err != nil { + return nil, err + } + rcArray[index] = rc + } + return rcArray, nil +} + +// RuleDataSource is the resource from which the rule collects its data. +type RuleDataSource interface { + AsRuleMetricDataSource() (*RuleMetricDataSource, bool) + AsRuleManagementEventDataSource() (*RuleManagementEventDataSource, bool) +} + +func unmarshalRuleDataSource(body []byte) (RuleDataSource, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["odata.type"] { + case string(OdataTypeMicrosoftAzureManagementInsightsModelsRuleMetricDataSource): + var rmds RuleMetricDataSource + err := json.Unmarshal(body, &rmds) + return rmds, err + case string(OdataTypeMicrosoftAzureManagementInsightsModelsRuleManagementEventDataSource): + var rmeds RuleManagementEventDataSource + err := json.Unmarshal(body, &rmeds) + return rmeds, err + default: + return nil, errors.New("Unsupported type") + } +} +func unmarshalRuleDataSourceArray(body []byte) ([]RuleDataSource, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + rdsArray := make([]RuleDataSource, len(rawMessages)) + + for index, rawMessage := range rawMessages { + rds, err := unmarshalRuleDataSource(*rawMessage) + if err != nil { + return nil, err + } + rdsArray[index] = rds + } + return rdsArray, nil +} + +// RuleEmailAction is specifies the action to send email when the rule condition is evaluated. The discriminator is +// always RuleEmailAction in this case. +type RuleEmailAction struct { + OdataType OdataType2 `json:"odata.type,omitempty"` + SendToServiceOwners *bool `json:"sendToServiceOwners,omitempty"` + CustomEmails *[]string `json:"customEmails,omitempty"` +} + +// MarshalJSON is the custom marshaler for RuleEmailAction. +func (rea RuleEmailAction) MarshalJSON() ([]byte, error) { + rea.OdataType = OdataTypeMicrosoftAzureManagementInsightsModelsRuleEmailAction + type Alias RuleEmailAction + return json.Marshal(&struct { + Alias + }{ + Alias: (Alias)(rea), + }) +} + +// AsRuleEmailAction is the RuleAction implementation for RuleEmailAction. +func (rea RuleEmailAction) AsRuleEmailAction() (*RuleEmailAction, bool) { + return &rea, true +} + +// AsRuleWebhookAction is the RuleAction implementation for RuleEmailAction. +func (rea RuleEmailAction) AsRuleWebhookAction() (*RuleWebhookAction, bool) { + return nil, false +} + +// RuleManagementEventClaimsDataSource is the claims for a rule management event data source. +type RuleManagementEventClaimsDataSource struct { + EmailAddress *string `json:"emailAddress,omitempty"` +} + +// RuleManagementEventDataSource is a rule management event data source. The discriminator fields is always +// RuleManagementEventDataSource in this case. +type RuleManagementEventDataSource struct { + ResourceURI *string `json:"resourceUri,omitempty"` + OdataType OdataType `json:"odata.type,omitempty"` + EventName *string `json:"eventName,omitempty"` + EventSource *string `json:"eventSource,omitempty"` + Level *string `json:"level,omitempty"` + OperationName *string `json:"operationName,omitempty"` + ResourceGroupName *string `json:"resourceGroupName,omitempty"` + ResourceProviderName *string `json:"resourceProviderName,omitempty"` + Status *string `json:"status,omitempty"` + SubStatus *string `json:"subStatus,omitempty"` + Claims *RuleManagementEventClaimsDataSource `json:"claims,omitempty"` +} + +// MarshalJSON is the custom marshaler for RuleManagementEventDataSource. +func (rmeds RuleManagementEventDataSource) MarshalJSON() ([]byte, error) { + rmeds.OdataType = OdataTypeMicrosoftAzureManagementInsightsModelsRuleManagementEventDataSource + type Alias RuleManagementEventDataSource + return json.Marshal(&struct { + Alias + }{ + Alias: (Alias)(rmeds), + }) +} + +// AsRuleMetricDataSource is the RuleDataSource implementation for RuleManagementEventDataSource. +func (rmeds RuleManagementEventDataSource) AsRuleMetricDataSource() (*RuleMetricDataSource, bool) { + return nil, false +} + +// AsRuleManagementEventDataSource is the RuleDataSource implementation for RuleManagementEventDataSource. +func (rmeds RuleManagementEventDataSource) AsRuleManagementEventDataSource() (*RuleManagementEventDataSource, bool) { + return &rmeds, true +} + +// RuleMetricDataSource is a rule metric data source. The discriminator value is always RuleMetricDataSource in this +// case. +type RuleMetricDataSource struct { + ResourceURI *string `json:"resourceUri,omitempty"` + OdataType OdataType `json:"odata.type,omitempty"` + MetricName *string `json:"metricName,omitempty"` +} + +// MarshalJSON is the custom marshaler for RuleMetricDataSource. +func (rmds RuleMetricDataSource) MarshalJSON() ([]byte, error) { + rmds.OdataType = OdataTypeMicrosoftAzureManagementInsightsModelsRuleMetricDataSource + type Alias RuleMetricDataSource + return json.Marshal(&struct { + Alias + }{ + Alias: (Alias)(rmds), + }) +} + +// AsRuleMetricDataSource is the RuleDataSource implementation for RuleMetricDataSource. +func (rmds RuleMetricDataSource) AsRuleMetricDataSource() (*RuleMetricDataSource, bool) { + return &rmds, true +} + +// AsRuleManagementEventDataSource is the RuleDataSource implementation for RuleMetricDataSource. +func (rmds RuleMetricDataSource) AsRuleManagementEventDataSource() (*RuleManagementEventDataSource, bool) { + return nil, false +} + +// RuleWebhookAction is specifies the action to post to service when the rule condition is evaluated. The discriminator +// is always RuleWebhookAction in this case. +type RuleWebhookAction struct { + OdataType OdataType2 `json:"odata.type,omitempty"` + ServiceURI *string `json:"serviceUri,omitempty"` + Properties *map[string]*string `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for RuleWebhookAction. +func (rwa RuleWebhookAction) MarshalJSON() ([]byte, error) { + rwa.OdataType = OdataTypeMicrosoftAzureManagementInsightsModelsRuleWebhookAction + type Alias RuleWebhookAction + return json.Marshal(&struct { + Alias + }{ + Alias: (Alias)(rwa), + }) +} + +// AsRuleEmailAction is the RuleAction implementation for RuleWebhookAction. +func (rwa RuleWebhookAction) AsRuleEmailAction() (*RuleEmailAction, bool) { + return nil, false +} + +// AsRuleWebhookAction is the RuleAction implementation for RuleWebhookAction. +func (rwa RuleWebhookAction) AsRuleWebhookAction() (*RuleWebhookAction, bool) { + return &rwa, true +} + +// ScaleAction is the parameters for the scaling action. +type ScaleAction struct { + Direction ScaleDirection `json:"direction,omitempty"` + Type ScaleType `json:"type,omitempty"` + Value *string `json:"value,omitempty"` + Cooldown *string `json:"cooldown,omitempty"` +} + +// ScaleCapacity is the number of instances that can be used during this profile. +type ScaleCapacity struct { + Minimum *string `json:"minimum,omitempty"` + Maximum *string `json:"maximum,omitempty"` + Default *string `json:"default,omitempty"` +} + +// ScaleRule is a rule that provide the triggers and parameters for the scaling action. +type ScaleRule struct { + MetricTrigger *MetricTrigger `json:"metricTrigger,omitempty"` + ScaleAction *ScaleAction `json:"scaleAction,omitempty"` +} + +// SmsReceiver is an SMS receiver. +type SmsReceiver struct { + Name *string `json:"name,omitempty"` + CountryCode *string `json:"countryCode,omitempty"` + PhoneNumber *string `json:"phoneNumber,omitempty"` + Status ReceiverStatus `json:"status,omitempty"` +} + +// ThresholdRuleCondition is a rule condition based on a metric crossing a threshold. +type ThresholdRuleCondition struct { + DataSource RuleDataSource `json:"dataSource,omitempty"` + OdataType OdataType1 `json:"odata.type,omitempty"` + Operator ConditionOperator `json:"operator,omitempty"` + Threshold *float64 `json:"threshold,omitempty"` + WindowSize *string `json:"windowSize,omitempty"` + TimeAggregation TimeAggregationOperator `json:"timeAggregation,omitempty"` +} + +// MarshalJSON is the custom marshaler for ThresholdRuleCondition. +func (trc ThresholdRuleCondition) MarshalJSON() ([]byte, error) { + trc.OdataType = OdataTypeMicrosoftAzureManagementInsightsModelsThresholdRuleCondition + type Alias ThresholdRuleCondition + return json.Marshal(&struct { + Alias + }{ + Alias: (Alias)(trc), + }) +} + +// AsThresholdRuleCondition is the RuleCondition implementation for ThresholdRuleCondition. +func (trc ThresholdRuleCondition) AsThresholdRuleCondition() (*ThresholdRuleCondition, bool) { + return &trc, true +} + +// AsLocationThresholdRuleCondition is the RuleCondition implementation for ThresholdRuleCondition. +func (trc ThresholdRuleCondition) AsLocationThresholdRuleCondition() (*LocationThresholdRuleCondition, bool) { + return nil, false +} + +// AsManagementEventRuleCondition is the RuleCondition implementation for ThresholdRuleCondition. +func (trc ThresholdRuleCondition) AsManagementEventRuleCondition() (*ManagementEventRuleCondition, bool) { + return nil, false +} + +// UnmarshalJSON is the custom unmarshaler for ThresholdRuleCondition struct. +func (trc *ThresholdRuleCondition) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + var v *json.RawMessage + + v = m["operator"] + if v != nil { + var operator ConditionOperator + err = json.Unmarshal(*m["operator"], &operator) + if err != nil { + return err + } + trc.Operator = operator + } + + v = m["threshold"] + if v != nil { + var threshold float64 + err = json.Unmarshal(*m["threshold"], &threshold) + if err != nil { + return err + } + trc.Threshold = &threshold + } + + v = m["windowSize"] + if v != nil { + var windowSize string + err = json.Unmarshal(*m["windowSize"], &windowSize) + if err != nil { + return err + } + trc.WindowSize = &windowSize + } + + v = m["timeAggregation"] + if v != nil { + var timeAggregation TimeAggregationOperator + err = json.Unmarshal(*m["timeAggregation"], &timeAggregation) + if err != nil { + return err + } + trc.TimeAggregation = timeAggregation + } + + v = m["dataSource"] + if v != nil { + dataSource, err := unmarshalRuleDataSource(*m["dataSource"]) + if err != nil { + return err + } + trc.DataSource = dataSource + } + + v = m["odata.type"] + if v != nil { + var odatatype OdataType1 + err = json.Unmarshal(*m["odata.type"], &odatatype) + if err != nil { + return err + } + trc.OdataType = odatatype + } + + return nil +} + +// TimeWindow is a specific date-time for the profile. +type TimeWindow struct { + TimeZone *string `json:"timeZone,omitempty"` + Start *date.Time `json:"start,omitempty"` + End *date.Time `json:"end,omitempty"` +} + +// WebhookNotification is webhook notification of an autoscale event. +type WebhookNotification struct { + ServiceURI *string `json:"serviceUri,omitempty"` + Properties *map[string]*string `json:"properties,omitempty"` +} + +// WebhookReceiver is a webhook receiver. +type WebhookReceiver struct { + Name *string `json:"name,omitempty"` + ServiceURI *string `json:"serviceUri,omitempty"` +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/operations.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/operations.go new file mode 100644 index 000000000000..b825494ca536 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/operations.go @@ -0,0 +1,96 @@ +package monitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" +) + +// OperationsClient is the monitor Management Client +type OperationsClient struct { + ManagementClient +} + +// NewOperationsClient creates an instance of the OperationsClient client. +func NewOperationsClient(subscriptionID string) OperationsClient { + return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewOperationsClientWithBaseURI creates an instance of the OperationsClient client. +func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient { + return OperationsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List lists all of the available operations from Microsoft.Insights provider. +func (client OperationsClient) List() (result OperationListResult, err error) { + req, err := client.ListPreparer() + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.OperationsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "monitor.OperationsClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "monitor.OperationsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client OperationsClient) ListPreparer() (*http.Request, error) { + const APIVersion = "2015-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/microsoft.insights/operations"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client OperationsClient) ListResponder(resp *http.Response) (result OperationListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/version.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/version.go new file mode 100755 index 000000000000..1500a1502d65 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/version.go @@ -0,0 +1,28 @@ +package monitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// UserAgent returns the UserAgent string to use when sending http.Requests. +func UserAgent() string { + return "Azure-SDK-For-Go/v11.0.0-beta arm-monitor/" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return "v11.0.0-beta" +} diff --git a/vendor/vendor.json b/vendor/vendor.json index c713a5e3d24f..c45d580cf56d 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -122,6 +122,14 @@ "version": "v11.1.0-beta", "versionExact": "v11.1.0-beta" }, + { + "checksumSHA1": "gkxb82xA+IZAuKPZedGZnlWd1mE=", + "path": "github.com/Azure/azure-sdk-for-go/arm/monitor", + "revision": "80f6cbcb1d6295ebb8fbeb5afab826a94aa67d11", + "revisionTime": "2017-10-06T17:43:09Z", + "version": "=v11.1.0-beta", + "versionExact": "v11.1.0-beta" + }, { "checksumSHA1": "CUnwQihTgQ2V6Vv4WsXR+7D86oo=", "path": "github.com/Azure/azure-sdk-for-go/arm/mysql", From 307ba31bd6c22ac4fdd0dbd914721932ca46c0d6 Mon Sep 17 00:00:00 2001 From: Dominik Lekse Date: Tue, 31 Oct 2017 16:20:39 +0100 Subject: [PATCH 02/12] Changed field AlertRule from an implicitly to an explicitly defined field to solve nil dereference issues when using the AlertRulesClient in azure-sdk-for-go/arm/monitor --- vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/models.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/models.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/models.go index 272ae76bf886..b9523f660fe6 100755 --- a/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/models.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/monitor/models.go @@ -389,7 +389,8 @@ type AlertRuleResource struct { Type *string `json:"type,omitempty"` Location *string `json:"location,omitempty"` Tags *map[string]*string `json:"tags,omitempty"` - *AlertRule `json:"properties,omitempty"` +// The field AlertRule has been changed from an implicitly to an explicitly defined field to solve nil dereference issues when using the AlertRulesClient + AlertRule *AlertRule `json:"properties,omitempty"` } // AlertRuleResourceCollection is represents a collection of alert rule resources. From 719ecfa73b55d3e4998ae9d11ca0fa09e628ebb3 Mon Sep 17 00:00:00 2001 From: Dominik Lekse Date: Tue, 31 Oct 2017 16:20:49 +0100 Subject: [PATCH 03/12] Added resource azurerm_metric_alertrule --- azurerm/config.go | 12 + azurerm/import_arm_metric_alertrule_test.go | 31 ++ azurerm/provider.go | 1 + azurerm/resource_arm_metric_alertrule.go | 395 ++++++++++++++++++ azurerm/resource_arm_metric_alertrule_test.go | 204 +++++++++ azurerm/validators.go | 17 + 6 files changed, 660 insertions(+) create mode 100644 azurerm/import_arm_metric_alertrule_test.go create mode 100644 azurerm/resource_arm_metric_alertrule.go create mode 100644 azurerm/resource_arm_metric_alertrule_test.go diff --git a/azurerm/config.go b/azurerm/config.go index 82a87e867c32..213d03314f0f 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -22,6 +22,7 @@ import ( "github.com/Azure/azure-sdk-for-go/arm/eventhub" "github.com/Azure/azure-sdk-for-go/arm/graphrbac" "github.com/Azure/azure-sdk-for-go/arm/keyvault" + "github.com/Azure/azure-sdk-for-go/arm/monitor" "github.com/Azure/azure-sdk-for-go/arm/mysql" "github.com/Azure/azure-sdk-for-go/arm/network" "github.com/Azure/azure-sdk-for-go/arm/operationalinsights" @@ -157,6 +158,8 @@ type ArmClient struct { sqlElasticPoolsClient sql.ElasticPoolsClient sqlFirewallRulesClient sql.FirewallRulesClient sqlServersClient sql.ServersClient + + monitorAlertRulesClient monitor.AlertRulesClient } func withRequestLogging() autorest.SendDecorator { @@ -653,6 +656,7 @@ func (c *Config) getArmClient() (*ArmClient, error) { client.registerDatabases(endpoint, c.SubscriptionID, auth, sender) client.registerDisks(endpoint, c.SubscriptionID, auth, sender) client.registerKeyVaultClients(endpoint, c.SubscriptionID, auth, keyVaultAuth, sender) + client.registerMonitorClients(endpoint, c.SubscriptionID, auth, sender) return &client, nil } @@ -782,6 +786,14 @@ func (c *ArmClient) registerKeyVaultClients(endpoint, subscriptionId string, aut c.keyVaultManagementClient = keyVaultManagementClient } +func (c *ArmClient) registerMonitorClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) { + arc := monitor.NewAlertRulesClientWithBaseURI(endpoint, subscriptionId) + setUserAgent(&arc.Client) + arc.Authorizer = auth + arc.Sender = autorest.CreateSender(withRequestLogging()) + c.monitorAlertRulesClient = arc +} + func (armClient *ArmClient) getKeyForStorageAccount(resourceGroupName, storageAccountName string) (string, bool, error) { accountKeys, err := armClient.storageServiceClient.ListKeys(resourceGroupName, storageAccountName) if accountKeys.StatusCode == http.StatusNotFound { diff --git a/azurerm/import_arm_metric_alertrule_test.go b/azurerm/import_arm_metric_alertrule_test.go new file mode 100644 index 000000000000..61fa6fa29e3d --- /dev/null +++ b/azurerm/import_arm_metric_alertrule_test.go @@ -0,0 +1,31 @@ +package azurerm + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAzureRMMetricAlertRule_importVirtualMachineCpu(t *testing.T) { + resourceName := "azurerm_metric_alertrule.test" + + ri := acctest.RandInt() + config := testAccAzureRMMetricAlertRule_virtualMachineCpu(ri, testLocation(), true) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMMetricAlertRuleDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/azurerm/provider.go b/azurerm/provider.go index 8bf452d849a3..421c1439f782 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -127,6 +127,7 @@ func Provider() terraform.ResourceProvider { "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), "azurerm_log_analytics_workspace": resourceArmLogAnalyticsWorkspace(), "azurerm_managed_disk": resourceArmManagedDisk(), + "azurerm_metric_alertrule": resourceArmMetricAlertRule(), "azurerm_mysql_configuration": resourceArmMySQLConfiguration(), "azurerm_mysql_database": resourceArmMySqlDatabase(), "azurerm_mysql_firewall_rule": resourceArmMySqlFirewallRule(), diff --git a/azurerm/resource_arm_metric_alertrule.go b/azurerm/resource_arm_metric_alertrule.go new file mode 100644 index 000000000000..d252dcd25590 --- /dev/null +++ b/azurerm/resource_arm_metric_alertrule.go @@ -0,0 +1,395 @@ +package azurerm + +import ( + "fmt" + "github.com/Azure/azure-sdk-for-go/arm/monitor" + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" + "log" +) + +func resourceArmMetricAlertRule() *schema.Resource { + return &schema.Resource{ + Create: resourceArmMetricAlertRuleCreateOrUpdate, + Read: resourceArmMetricAlertRuleRead, + Update: resourceArmMetricAlertRuleCreateOrUpdate, + Delete: resourceArmMetricAlertRuleDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "resource_group_name": resourceGroupNameSchema(), + + "location": locationSchema(), + + "description": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + + "enabled": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + + "resource": { + Type: schema.TypeString, + Required: true, + }, + + "metric_name": { + Type: schema.TypeString, + Required: true, + }, + + "operator": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + ValidateFunc: validation.StringInSlice([]string{ + string(monitor.ConditionOperatorGreaterThan), + string(monitor.ConditionOperatorGreaterThanOrEqual), + string(monitor.ConditionOperatorLessThan), + string(monitor.ConditionOperatorLessThanOrEqual), + }, true), + }, + + "threshold": { + Type: schema.TypeFloat, + Required: true, + }, + + "period": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validateIso8601Duration(), + }, + + "aggregation": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + ValidateFunc: validation.StringInSlice([]string{ + string(monitor.TimeAggregationOperatorAverage), + string(monitor.TimeAggregationOperatorLast), + string(monitor.TimeAggregationOperatorMaximum), + string(monitor.TimeAggregationOperatorMinimum), + string(monitor.TimeAggregationOperatorTotal), + }, true), + }, + + "email_action": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "service_owners": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + + "custom_emails": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + + "webhook_action": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "service_uri": { + Type: schema.TypeString, + Required: true, + }, + + "properties": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + + "tags": tagsSchema(), + }, + } +} + +func resourceArmMetricAlertRuleCreateOrUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).monitorAlertRulesClient + + log.Printf("[INFO] preparing arguments for AzureRM Alert Rule creation.") + + name := d.Get("name").(string) + resGroup := d.Get("resource_group_name").(string) + location := d.Get("location").(string) + tags := d.Get("tags").(map[string]interface{}) + + alertRule, _ := expandAzureRmMetricThresholdAlertRule(d) + + alertRuleResource := monitor.AlertRuleResource{ + Name: &name, + Location: &location, + Tags: expandTags(tags), + AlertRule: alertRule, + } + + _, err := client.CreateOrUpdate(resGroup, name, alertRuleResource) + if err != nil { + return err + } + + read, err := client.Get(resGroup, name) + if err != nil { + return err + } + if read.ID == nil { + return fmt.Errorf("Cannot read AzureRM Alert Rule '%s' (Resource Group %s) ID", name, resGroup) + } + + d.SetId(*read.ID) + + return resourceArmMetricAlertRuleRead(d, meta) +} + +func resourceArmMetricAlertRuleRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).monitorAlertRulesClient + + resGroup, name, err := resourceGroupAndAlertRuleNameFromId(d.Id()) + if err != nil { + return err + } + + resp, err := client.Get(resGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[DEBUG] Metric Alert Rule %q (resource group %q) was not found - removing from state", name, resGroup) + d.SetId("") + return nil + } + + return fmt.Errorf("Error making Read request on AzureRM Metric Alert Rule '%s': %s", name, err) + } + + d.Set("name", name) + d.Set("resource_group_name", resGroup) + d.Set("location", azureRMNormalizeLocation(*resp.Location)) + + alertRule := resp.AlertRule + + if alertRule != nil { + d.Set("description", *alertRule.Description) + d.Set("enabled", *alertRule.IsEnabled) + + ruleCondition := alertRule.Condition + + if ruleCondition != nil { + thresholdRuleCondition, _ := ruleCondition.AsThresholdRuleCondition() + + d.Set("operator", string(thresholdRuleCondition.Operator)) + d.Set("threshold", float64(*thresholdRuleCondition.Threshold)) + d.Set("period", *thresholdRuleCondition.WindowSize) + d.Set("aggregation", string(thresholdRuleCondition.TimeAggregation)) + + dataSource := thresholdRuleCondition.DataSource + + if dataSource != nil { + metricDataSource, _ := dataSource.AsRuleMetricDataSource() + + d.Set("resource", *metricDataSource.ResourceURI) + d.Set("metric_name", *metricDataSource.MetricName) + } + } + + email_actions := make([]interface{}, 0) + webhook_actions := make([]interface{}, 0) + + for _, ruleAction := range *alertRule.Actions { + if emailAction, ok := ruleAction.AsRuleEmailAction(); ok { + email_action := make(map[string]interface{}, 1) + + email_action["service_owners"] = *emailAction.SendToServiceOwners + + custom_emails := []string{} + for _, custom_email := range *emailAction.CustomEmails { + custom_emails = append(custom_emails, custom_email) + } + + email_action["custom_emails"] = custom_emails + + email_actions = append(email_actions, email_action) + } else if webhookAction, ok := ruleAction.AsRuleWebhookAction(); ok { + webhook_action := make(map[string]interface{}, 1) + + webhook_action["service_uri"] = *webhookAction.ServiceURI + + properties := make(map[string]string, len(*webhookAction.Properties)) + for k, v := range *webhookAction.Properties { + if k != "$type" { + properties[k] = *v + } + } + webhook_action["properties"] = properties + + webhook_actions = append(webhook_actions, webhook_action) + } + } + + d.Set("email_action", email_actions) + d.Set("webhook_action", webhook_actions) + } + + flattenAndSetTags(d, resp.Tags) + + return nil +} + +func resourceArmMetricAlertRuleDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).monitorAlertRulesClient + + resGroup, name, err := resourceGroupAndAlertRuleNameFromId(d.Id()) + if err != nil { + return err + } + + _, err = client.Delete(resGroup, name) + + return err +} + +func expandAzureRmMetricThresholdAlertRule(d *schema.ResourceData) (*monitor.AlertRule, error) { + name := d.Get("name").(string) + + resource := d.Get("resource").(string) + metric_name := d.Get("metric_name").(string) + + metricDataSource := monitor.RuleMetricDataSource{ + ResourceURI: &resource, + MetricName: &metric_name, + } + + operator := d.Get("operator").(string) + threshold := d.Get("threshold").(float64) + period := d.Get("period").(string) + aggregation := d.Get("aggregation").(string) + + thresholdRuleCondition := monitor.ThresholdRuleCondition{ + DataSource: metricDataSource, + Operator: monitor.ConditionOperator(operator), + Threshold: &threshold, + TimeAggregation: monitor.TimeAggregationOperator(aggregation), + WindowSize: &period, + } + + actions := make([]monitor.RuleAction, 0, 2) + + // Email action + + email_actions := d.Get("email_action").([]interface{}) + + if len(email_actions) > 0 { + email_action := email_actions[0].(map[string]interface{}) + emailAction := monitor.RuleEmailAction{} + + if v, ok := email_action["custom_emails"]; ok { + custom_emails := v.([]interface{}) + + customEmails := make([]string, 0) + for _, customEmail := range custom_emails { + custom_email := customEmail.(string) + customEmails = append(customEmails, custom_email) + } + + emailAction.CustomEmails = &customEmails + } + + if v, ok := email_action["service_owners"]; ok { + sendToServiceOwners := v.(bool) + emailAction.SendToServiceOwners = &sendToServiceOwners + } + + actions = append(actions, emailAction) + } + + // Webhook action + + webhook_actions := d.Get("webhook_action").([]interface{}) + + if len(webhook_actions) > 0 { + webhook_action := webhook_actions[0].(map[string]interface{}) + + service_uri := webhook_action["service_uri"].(string) + + webhook_properties := make(map[string]*string) + + if v, ok := webhook_action["properties"]; ok { + properties := v.(map[string]interface{}) + + for property_key, property_value := range properties { + property_string := property_value.(string) + webhook_properties[property_key] = &property_string + } + } + + webhookAction := monitor.RuleWebhookAction{ + ServiceURI: &service_uri, + Properties: &webhook_properties, + } + + actions = append(actions, webhookAction) + } + + enabled := d.Get("enabled").(bool) + + alertRule := monitor.AlertRule{ + Name: &name, + Condition: &thresholdRuleCondition, + Actions: &actions, + IsEnabled: &enabled, + } + + if v, ok := d.GetOk("description"); ok { + description := v.(string) + alertRule.Description = &description + } + + return &alertRule, nil +} + +func resourceGroupAndAlertRuleNameFromId(alertRuleId string) (string, string, error) { + id, err := parseAzureResourceID(alertRuleId) + if err != nil { + return "", "", err + } + name := id.Path["alertrules"] + resGroup := id.ResourceGroup + + return resGroup, name, nil +} diff --git a/azurerm/resource_arm_metric_alertrule_test.go b/azurerm/resource_arm_metric_alertrule_test.go new file mode 100644 index 000000000000..0c5950be8479 --- /dev/null +++ b/azurerm/resource_arm_metric_alertrule_test.go @@ -0,0 +1,204 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMMetricAlertRule_virtualMachineCpu(t *testing.T) { + resourceName := "azurerm_metric_alertrule.test" + ri := acctest.RandInt() + preConfig := testAccAzureRMMetricAlertRule_virtualMachineCpu(ri, testLocation(), true) + postConfig := testAccAzureRMMetricAlertRule_virtualMachineCpu(ri, testLocation(), false) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMMetricAlertRuleDestroy, + Steps: []resource.TestStep{ + { + Config: preConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMMetricAlertRuleExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "enabled", "true"), + ), + }, + { + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMMetricAlertRuleExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "enabled", "false"), + ), + }, + }, + }) +} + +func TestAccAzureRMMetricAlertRule_sqlDatabaseStorage(t *testing.T) { + resourceName := "azurerm_metric_alertrule.test" + ri := acctest.RandInt() + config := testAccAzureRMMetricAlertRule_sqlDatabaseStorage(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMMetricAlertRuleDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMMetricAlertRuleExists(resourceName), + ), + }, + }, + }) +} + +func testCheckAzureRMMetricAlertRuleExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + name := rs.Primary.Attributes["name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for Alert Rule: %s", name) + } + + client := testAccProvider.Meta().(*ArmClient).monitorAlertRulesClient + + resp, err := client.Get(resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Alert Rule %q (resource group: %q) does not exist", name, resourceGroup) + } + + return fmt.Errorf("Bad: Get on monitorAlertRulesClient: %+v", err) + } + + return nil + } +} + +func testCheckAzureRMMetricAlertRuleDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).monitorAlertRulesClient + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_metric_alertrule" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.Get(resourceGroup, name) + + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return nil + } + + return err + } + + return fmt.Errorf("Alert Rule still exists:\n%#v", resp) + } + + return nil +} + +func testAccAzureRMMetricAlertRule_virtualMachineCpu(rInt int, location string, enabled bool) string { + basicLinuxMachine := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(rInt, location) + + var enabledString string + + if enabled { + enabledString = "true" + } else { + enabledString = "false" + } + + return fmt.Sprintf(` +%s + +resource "azurerm_metric_alertrule" "test" { + name = "${azurerm_virtual_machine.test.name}-cpu" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + + description = "An alert rule to watch the metric Percentage CPU" + + enabled = %s + + resource = "${azurerm_virtual_machine.test.id}" + metric_name = "Percentage CPU" + operator = "GreaterThan" + threshold = 75 + aggregation = "Average" + period = "PT5M" + + email_action { + service_owners = false + custom_emails = [ + "support@azure.microsoft.com", + ] + } + + webhook_action { + service_uri = "https://requestb.in/18jamc41" + properties = { + severity = "incredible" + acceptance_test = "true" + } + } +} +`, basicLinuxMachine, enabledString) +} + +func testAccAzureRMMetricAlertRule_sqlDatabaseStorage(rInt int, location string) string { + basicSqlServerDatabase := testAccAzureRMSqlDatabase_basic(rInt, location) + + return fmt.Sprintf(` +%s + +resource "azurerm_metric_alertrule" "test" { + name = "${azurerm_sql_database.test.name}-storage" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + + description = "An alert rule to watch the metric Storage" + + enabled = true + + resource = "${azurerm_sql_database.test.id}" + metric_name = "storage" + operator = "GreaterThan" + threshold = 1073741824 + aggregation = "Maximum" + period = "PT10M" + + email_action { + service_owners = false + custom_emails = [ + "support@azure.microsoft.com", + ] + } + + webhook_action { + service_uri = "https://requestb.in/18jamc41" + properties = { + severity = "incredible" + acceptance_test = "true" + } + } +} +`, basicSqlServerDatabase) +} diff --git a/azurerm/validators.go b/azurerm/validators.go index a6405ed8ea6b..7a6489fcee45 100644 --- a/azurerm/validators.go +++ b/azurerm/validators.go @@ -74,3 +74,20 @@ func validateStringLength(maxLength int) schema.SchemaValidateFunc { return } } + +func validateIso8601Duration() schema.SchemaValidateFunc { + return func(i interface{}, k string) (s []string, es []error) { + v, ok := i.(string) + if !ok { + es = append(es, fmt.Errorf("expected type of %s to be string", k)) + return + } + + matched, _ := regexp.MatchString(`^P(([0-9]+Y)?([0-9]+M)?([0-9]+W)?([0-9]+D)?(T([0-9]+H)?([0-9]+M)?([0-9]+(\.?[0-9]+)?S)?))?$`, v) + + if !matched { + es = append(es, fmt.Errorf("expected %s to be in ISO 8601 duration format, got %s", k, v)) + } + return + } +} From 58f792c251beaaf7f3a76513811b461cbbd5ddcb Mon Sep 17 00:00:00 2001 From: Dominik Lekse Date: Wed, 1 Nov 2017 12:49:45 +0100 Subject: [PATCH 04/12] Added documentation for azurerm_metric_alertrule resource --- website/azurerm.erb | 12 +- website/docs/r/metric_alertrule.html.markdown | 152 ++++++++++++++++++ 2 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 website/docs/r/metric_alertrule.html.markdown diff --git a/website/azurerm.erb b/website/azurerm.erb index 878a78775c8c..00a6741410e2 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -411,12 +411,20 @@ + > + Monitor Resources + + + > Network Resources