diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/CHANGELOG.md b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/CHANGELOG.md new file mode 100644 index 000000000000..f3d80a0b8362 --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/CHANGELOG.md @@ -0,0 +1,5 @@ +# Release History + +## 0.1.0 (2021-10-26) + +- Initial preview release. diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/LICENSE.txt b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/LICENSE.txt new file mode 100644 index 000000000000..dc0c2ffb3dc1 --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Microsoft Corporation. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/README.md b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/README.md new file mode 100644 index 000000000000..e9653d1e2db2 --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/README.md @@ -0,0 +1,76 @@ +# Azure Alerts Management Module for Go + +[![PkgGoDev](https://pkg.go.dev/badge/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/alertsmanagement/armalertsmanagement)](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/alertsmanagement/armalertsmanagement) + +The `armalertsmanagement` module provides operations for working with Azure Alerts Management. + +[Source code](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/resourcemanager/alertsmanagement/armalertsmanagement) + +# Getting started + +## Prerequisites + +- an [Azure subscription](https://azure.microsoft.com/free/) +- Go 1.13 or above + +## Install the package + +This project uses [Go modules](https://github.com/golang/go/wiki/Modules) for versioning and dependency management. + +Install the Azure Alerts Management module: + +```sh +go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/alertsmanagement/armalertsmanagement +``` + +## Authorization + +When creating a client, you will need to provide a credential for authenticating with Azure Alerts Management. The `azidentity` module provides facilities for various ways of authenticating with Azure including client/secret, certificate, managed identity, and more. + +```go +cred, err := azidentity.NewDefaultAzureCredential(nil) +``` + +For more information on authentication, please see the documentation for `azidentity` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity). + +## Connecting to Azure Alerts Management + +Once you have a credential, create a connection to the desired ARM endpoint. The `github.com/Azure/azure-sdk-for-go/sdk/azcore/arm` package provides facilities for connecting with ARM endpoints including public and sovereign clouds as well as Azure Stack. + +```go +con := arm.NewDefaultConnection(cred, nil) +``` + +For more information on ARM connections, please see the documentation for `azcore` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore). + +## Clients + +Azure Alerts Management modules consist of one or more clients. A client groups a set of related APIs, providing access to its functionality within the specified subscription. Create one or more clients to access the APIs you require using your `arm.Connection`. + +```go +client := armalertsmanagement.NewAlertsClient(conn,"") +``` + +## Provide Feedback + +If you encounter bugs or have suggestions, please +[open an issue](https://github.com/Azure/azure-sdk-for-go/issues) and assign the `Alerts Management` label. + +# Contributing + +This project welcomes contributions and suggestions. Most contributions require +you to agree to a Contributor License Agreement (CLA) declaring that you have +the right to, and actually do, grant us the rights to use your contribution. +For details, visit [https://cla.microsoft.com](https://cla.microsoft.com). + +When you submit a pull request, a CLA-bot will automatically determine whether +you need to provide a CLA and decorate the PR appropriately (e.g., label, +comment). Simply follow the instructions provided by the bot. You will only +need to do this once across all repos using our CLA. + +This project has adopted the +[Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information, see the +[Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) +or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any +additional questions or comments. \ No newline at end of file diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/autorest.md b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/autorest.md new file mode 100644 index 000000000000..30cff12f9137 --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/autorest.md @@ -0,0 +1,14 @@ +### AutoRest Configuration + +> see https://aka.ms/autorest + +``` yaml +azure-arm: true +require: +- https://github.com/Azure/azure-rest-api-specs/blob/3c16aae50c7110e1aad241ac93995621d4093d46/specification/alertsmanagement/resource-manager/readme.md +- https://github.com/Azure/azure-rest-api-specs/blob/3c16aae50c7110e1aad241ac93995621d4093d46/specification/alertsmanagement/resource-manager/readme.go.md +license-header: MICROSOFT_MIT_NO_VERSION +module-version: 0.1.0 +modelerfour: + lenient-model-deduplication: true +``` \ No newline at end of file diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/build.go b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/build.go new file mode 100644 index 000000000000..771b03a15719 --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/build.go @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +// This file enables 'go generate' to regenerate this specific SDK +//go:generate pwsh.exe ../../../../eng/scripts/build.ps1 -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/alertsmanagement/armalertsmanagement + +package armalertsmanagement diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/ci.yml b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/ci.yml new file mode 100644 index 000000000000..8cf9a019b72e --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/ci.yml @@ -0,0 +1,27 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. +trigger: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/alertsmanagement/armalertsmanagement/ + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/alertsmanagement/armalertsmanagement/ + +stages: +- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml + parameters: + ServiceDirectory: 'resourcemanager/alertsmanagement/armalertsmanagement' diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/go.mod b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/go.mod new file mode 100644 index 000000000000..7e3d5c8c0a29 --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/go.mod @@ -0,0 +1,8 @@ +module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/alertsmanagement/armalertsmanagement + +go 1.16 + +require ( + github.com/Azure/azure-sdk-for-go v58.2.0+incompatible + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0 +) diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/go.sum b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/go.sum new file mode 100644 index 000000000000..c8ff7a2143ad --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/go.sum @@ -0,0 +1,30 @@ +github.com/Azure/azure-sdk-for-go v58.2.0+incompatible h1:iCb2tuoEm3N7ZpUDOvu1Yxl1B3iOVDmaD6weaRuIPzs= +github.com/Azure/azure-sdk-for-go v58.2.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0 h1:lhSJz9RMbJcTgxifR1hUNJnn6CNYtbgEDtQV22/9RBA= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0/go.mod h1:h6H6c8enJmmocHUbLiiGY6sx7f9i+X3m1CHdd5c6Rdw= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0 h1:v9p9TfTbf7AwNb5NYQt7hI41IfPoLFiFkLtb+bmGjT0= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0/go.mod h1:yqy467j36fJxcRV2TzfVZ1pCb5vxm4BtZPUdYWe/Xo8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= +github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/net v0.0.0-20210610132358-84b48f89b13b h1:k+E048sYJHyVnsr1GDrRZWQ32D2C7lWs9JRc0bel53A= +golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/go_mod_tidy_hack.go b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/go_mod_tidy_hack.go new file mode 100644 index 000000000000..76461c035342 --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/go_mod_tidy_hack.go @@ -0,0 +1,13 @@ +//go:build modhack +// +build modhack + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +// This file, and the github.com/Azure/azure-sdk-for-go import, won't actually become part of +// the resultant binary. + +package armalertsmanagement + +// Necessary for safely adding multi-module repo. See: https://github.com/golang/go/wiki/Modules#is-it-possible-to-add-a-module-to-a-multi-module-repository +import _ "github.com/Azure/azure-sdk-for-go" diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_actionrules_client.go b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_actionrules_client.go new file mode 100644 index 000000000000..4b63632357ca --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_actionrules_client.go @@ -0,0 +1,484 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armalertsmanagement + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strings" +) + +// ActionRulesClient contains the methods for the ActionRules group. +// Don't use this type directly, use NewActionRulesClient() instead. +type ActionRulesClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewActionRulesClient creates a new instance of ActionRulesClient with the specified values. +func NewActionRulesClient(con *arm.Connection, subscriptionID string) *ActionRulesClient { + return &ActionRulesClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version), subscriptionID: subscriptionID} +} + +// CreateUpdate - Creates/Updates a specific action rule +// If the operation fails it returns the *ErrorResponse error type. +func (client *ActionRulesClient) CreateUpdate(ctx context.Context, resourceGroupName string, actionRuleName string, actionRule ActionRule, options *ActionRulesCreateUpdateOptions) (ActionRulesCreateUpdateResponse, error) { + req, err := client.createUpdateCreateRequest(ctx, resourceGroupName, actionRuleName, actionRule, options) + if err != nil { + return ActionRulesCreateUpdateResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ActionRulesCreateUpdateResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ActionRulesCreateUpdateResponse{}, client.createUpdateHandleError(resp) + } + return client.createUpdateHandleResponse(resp) +} + +// createUpdateCreateRequest creates the CreateUpdate request. +func (client *ActionRulesClient) createUpdateCreateRequest(ctx context.Context, resourceGroupName string, actionRuleName string, actionRule ActionRule, options *ActionRulesCreateUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AlertsManagement/actionRules/{actionRuleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if actionRuleName == "" { + return nil, errors.New("parameter actionRuleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{actionRuleName}", url.PathEscape(actionRuleName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-05-05-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, actionRule) +} + +// createUpdateHandleResponse handles the CreateUpdate response. +func (client *ActionRulesClient) createUpdateHandleResponse(resp *http.Response) (ActionRulesCreateUpdateResponse, error) { + result := ActionRulesCreateUpdateResponse{RawResponse: resp} + if val := resp.Header.Get("x-ms-request-id"); val != "" { + result.XMSRequestID = &val + } + if err := runtime.UnmarshalAsJSON(resp, &result.ActionRule); err != nil { + return ActionRulesCreateUpdateResponse{}, err + } + return result, nil +} + +// createUpdateHandleError handles the CreateUpdate error response. +func (client *ActionRulesClient) createUpdateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Delete - Deletes a given action rule +// If the operation fails it returns the *ErrorResponse error type. +func (client *ActionRulesClient) Delete(ctx context.Context, resourceGroupName string, actionRuleName string, options *ActionRulesDeleteOptions) (ActionRulesDeleteResponse, error) { + req, err := client.deleteCreateRequest(ctx, resourceGroupName, actionRuleName, options) + if err != nil { + return ActionRulesDeleteResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ActionRulesDeleteResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ActionRulesDeleteResponse{}, client.deleteHandleError(resp) + } + return client.deleteHandleResponse(resp) +} + +// deleteCreateRequest creates the Delete request. +func (client *ActionRulesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, actionRuleName string, options *ActionRulesDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AlertsManagement/actionRules/{actionRuleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if actionRuleName == "" { + return nil, errors.New("parameter actionRuleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{actionRuleName}", url.PathEscape(actionRuleName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-05-05-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// deleteHandleResponse handles the Delete response. +func (client *ActionRulesClient) deleteHandleResponse(resp *http.Response) (ActionRulesDeleteResponse, error) { + result := ActionRulesDeleteResponse{RawResponse: resp} + if val := resp.Header.Get("x-ms-request-id"); val != "" { + result.XMSRequestID = &val + } + if err := runtime.UnmarshalAsJSON(resp, &result.Value); err != nil { + return ActionRulesDeleteResponse{}, err + } + return result, nil +} + +// deleteHandleError handles the Delete error response. +func (client *ActionRulesClient) deleteHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// GetByName - Get a specific action rule +// If the operation fails it returns the *ErrorResponse error type. +func (client *ActionRulesClient) GetByName(ctx context.Context, resourceGroupName string, actionRuleName string, options *ActionRulesGetByNameOptions) (ActionRulesGetByNameResponse, error) { + req, err := client.getByNameCreateRequest(ctx, resourceGroupName, actionRuleName, options) + if err != nil { + return ActionRulesGetByNameResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ActionRulesGetByNameResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ActionRulesGetByNameResponse{}, client.getByNameHandleError(resp) + } + return client.getByNameHandleResponse(resp) +} + +// getByNameCreateRequest creates the GetByName request. +func (client *ActionRulesClient) getByNameCreateRequest(ctx context.Context, resourceGroupName string, actionRuleName string, options *ActionRulesGetByNameOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AlertsManagement/actionRules/{actionRuleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if actionRuleName == "" { + return nil, errors.New("parameter actionRuleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{actionRuleName}", url.PathEscape(actionRuleName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-05-05-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getByNameHandleResponse handles the GetByName response. +func (client *ActionRulesClient) getByNameHandleResponse(resp *http.Response) (ActionRulesGetByNameResponse, error) { + result := ActionRulesGetByNameResponse{RawResponse: resp} + if val := resp.Header.Get("x-ms-request-id"); val != "" { + result.XMSRequestID = &val + } + if err := runtime.UnmarshalAsJSON(resp, &result.ActionRule); err != nil { + return ActionRulesGetByNameResponse{}, err + } + return result, nil +} + +// getByNameHandleError handles the GetByName error response. +func (client *ActionRulesClient) getByNameHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// ListByResourceGroup - List all action rules of the subscription, created in given resource group and given input filters +// If the operation fails it returns the *ErrorResponse error type. +func (client *ActionRulesClient) ListByResourceGroup(resourceGroupName string, options *ActionRulesListByResourceGroupOptions) *ActionRulesListByResourceGroupPager { + return &ActionRulesListByResourceGroupPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) + }, + advancer: func(ctx context.Context, resp ActionRulesListByResourceGroupResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ActionRulesList.NextLink) + }, + } +} + +// listByResourceGroupCreateRequest creates the ListByResourceGroup request. +func (client *ActionRulesClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, options *ActionRulesListByResourceGroupOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AlertsManagement/actionRules" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + if options != nil && options.TargetResourceGroup != nil { + reqQP.Set("targetResourceGroup", *options.TargetResourceGroup) + } + if options != nil && options.TargetResourceType != nil { + reqQP.Set("targetResourceType", *options.TargetResourceType) + } + if options != nil && options.TargetResource != nil { + reqQP.Set("targetResource", *options.TargetResource) + } + if options != nil && options.Severity != nil { + reqQP.Set("severity", string(*options.Severity)) + } + if options != nil && options.MonitorService != nil { + reqQP.Set("monitorService", string(*options.MonitorService)) + } + if options != nil && options.ImpactedScope != nil { + reqQP.Set("impactedScope", *options.ImpactedScope) + } + if options != nil && options.Description != nil { + reqQP.Set("description", *options.Description) + } + if options != nil && options.AlertRuleID != nil { + reqQP.Set("alertRuleId", *options.AlertRuleID) + } + if options != nil && options.ActionGroup != nil { + reqQP.Set("actionGroup", *options.ActionGroup) + } + if options != nil && options.Name != nil { + reqQP.Set("name", *options.Name) + } + reqQP.Set("api-version", "2019-05-05-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listByResourceGroupHandleResponse handles the ListByResourceGroup response. +func (client *ActionRulesClient) listByResourceGroupHandleResponse(resp *http.Response) (ActionRulesListByResourceGroupResponse, error) { + result := ActionRulesListByResourceGroupResponse{RawResponse: resp} + if val := resp.Header.Get("x-ms-request-id"); val != "" { + result.XMSRequestID = &val + } + if err := runtime.UnmarshalAsJSON(resp, &result.ActionRulesList); err != nil { + return ActionRulesListByResourceGroupResponse{}, err + } + return result, nil +} + +// listByResourceGroupHandleError handles the ListByResourceGroup error response. +func (client *ActionRulesClient) listByResourceGroupHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// ListBySubscription - List all action rules of the subscription and given input filters +// If the operation fails it returns the *ErrorResponse error type. +func (client *ActionRulesClient) ListBySubscription(options *ActionRulesListBySubscriptionOptions) *ActionRulesListBySubscriptionPager { + return &ActionRulesListBySubscriptionPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listBySubscriptionCreateRequest(ctx, options) + }, + advancer: func(ctx context.Context, resp ActionRulesListBySubscriptionResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ActionRulesList.NextLink) + }, + } +} + +// listBySubscriptionCreateRequest creates the ListBySubscription request. +func (client *ActionRulesClient) listBySubscriptionCreateRequest(ctx context.Context, options *ActionRulesListBySubscriptionOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/actionRules" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + if options != nil && options.TargetResourceGroup != nil { + reqQP.Set("targetResourceGroup", *options.TargetResourceGroup) + } + if options != nil && options.TargetResourceType != nil { + reqQP.Set("targetResourceType", *options.TargetResourceType) + } + if options != nil && options.TargetResource != nil { + reqQP.Set("targetResource", *options.TargetResource) + } + if options != nil && options.Severity != nil { + reqQP.Set("severity", string(*options.Severity)) + } + if options != nil && options.MonitorService != nil { + reqQP.Set("monitorService", string(*options.MonitorService)) + } + if options != nil && options.ImpactedScope != nil { + reqQP.Set("impactedScope", *options.ImpactedScope) + } + if options != nil && options.Description != nil { + reqQP.Set("description", *options.Description) + } + if options != nil && options.AlertRuleID != nil { + reqQP.Set("alertRuleId", *options.AlertRuleID) + } + if options != nil && options.ActionGroup != nil { + reqQP.Set("actionGroup", *options.ActionGroup) + } + if options != nil && options.Name != nil { + reqQP.Set("name", *options.Name) + } + reqQP.Set("api-version", "2019-05-05-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listBySubscriptionHandleResponse handles the ListBySubscription response. +func (client *ActionRulesClient) listBySubscriptionHandleResponse(resp *http.Response) (ActionRulesListBySubscriptionResponse, error) { + result := ActionRulesListBySubscriptionResponse{RawResponse: resp} + if val := resp.Header.Get("x-ms-request-id"); val != "" { + result.XMSRequestID = &val + } + if err := runtime.UnmarshalAsJSON(resp, &result.ActionRulesList); err != nil { + return ActionRulesListBySubscriptionResponse{}, err + } + return result, nil +} + +// listBySubscriptionHandleError handles the ListBySubscription error response. +func (client *ActionRulesClient) listBySubscriptionHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Update - Update enabled flag and/or tags for the given action rule +// If the operation fails it returns the *ErrorResponse error type. +func (client *ActionRulesClient) Update(ctx context.Context, resourceGroupName string, actionRuleName string, actionRulePatch PatchObject, options *ActionRulesUpdateOptions) (ActionRulesUpdateResponse, error) { + req, err := client.updateCreateRequest(ctx, resourceGroupName, actionRuleName, actionRulePatch, options) + if err != nil { + return ActionRulesUpdateResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ActionRulesUpdateResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ActionRulesUpdateResponse{}, client.updateHandleError(resp) + } + return client.updateHandleResponse(resp) +} + +// updateCreateRequest creates the Update request. +func (client *ActionRulesClient) updateCreateRequest(ctx context.Context, resourceGroupName string, actionRuleName string, actionRulePatch PatchObject, options *ActionRulesUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AlertsManagement/actionRules/{actionRuleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if actionRuleName == "" { + return nil, errors.New("parameter actionRuleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{actionRuleName}", url.PathEscape(actionRuleName)) + req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-05-05-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, actionRulePatch) +} + +// updateHandleResponse handles the Update response. +func (client *ActionRulesClient) updateHandleResponse(resp *http.Response) (ActionRulesUpdateResponse, error) { + result := ActionRulesUpdateResponse{RawResponse: resp} + if val := resp.Header.Get("x-ms-request-id"); val != "" { + result.XMSRequestID = &val + } + if err := runtime.UnmarshalAsJSON(resp, &result.ActionRule); err != nil { + return ActionRulesUpdateResponse{}, err + } + return result, nil +} + +// updateHandleError handles the Update error response. +func (client *ActionRulesClient) updateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_alerts_client.go b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_alerts_client.go new file mode 100644 index 000000000000..a0ae16dd536a --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_alerts_client.go @@ -0,0 +1,470 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armalertsmanagement + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strconv" + "strings" +) + +// AlertsClient contains the methods for the Alerts group. +// Don't use this type directly, use NewAlertsClient() instead. +type AlertsClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewAlertsClient creates a new instance of AlertsClient with the specified values. +func NewAlertsClient(con *arm.Connection, subscriptionID string) *AlertsClient { + return &AlertsClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version), subscriptionID: subscriptionID} +} + +// ChangeState - Change the state of an alert. +// If the operation fails it returns the *ErrorResponseAutoGenerated error type. +func (client *AlertsClient) ChangeState(ctx context.Context, alertID string, newState AlertState, options *AlertsChangeStateOptions) (AlertsChangeStateResponse, error) { + req, err := client.changeStateCreateRequest(ctx, alertID, newState, options) + if err != nil { + return AlertsChangeStateResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return AlertsChangeStateResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return AlertsChangeStateResponse{}, client.changeStateHandleError(resp) + } + return client.changeStateHandleResponse(resp) +} + +// changeStateCreateRequest creates the ChangeState request. +func (client *AlertsClient) changeStateCreateRequest(ctx context.Context, alertID string, newState AlertState, options *AlertsChangeStateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/alerts/{alertId}/changestate" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if alertID == "" { + return nil, errors.New("parameter alertID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{alertId}", url.PathEscape(alertID)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-05-05-preview") + reqQP.Set("newState", string(newState)) + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// changeStateHandleResponse handles the ChangeState response. +func (client *AlertsClient) changeStateHandleResponse(resp *http.Response) (AlertsChangeStateResponse, error) { + result := AlertsChangeStateResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.Alert); err != nil { + return AlertsChangeStateResponse{}, err + } + return result, nil +} + +// changeStateHandleError handles the ChangeState error response. +func (client *AlertsClient) changeStateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseAutoGenerated{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// GetAll - List all existing alerts, where the results can be filtered on the basis of multiple parameters (e.g. time range). The results can then be sorted +// on the basis specific fields, with the default being +// lastModifiedDateTime. +// If the operation fails it returns the *ErrorResponseAutoGenerated error type. +func (client *AlertsClient) GetAll(options *AlertsGetAllOptions) *AlertsGetAllPager { + return &AlertsGetAllPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.getAllCreateRequest(ctx, options) + }, + advancer: func(ctx context.Context, resp AlertsGetAllResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.AlertsList.NextLink) + }, + } +} + +// getAllCreateRequest creates the GetAll request. +func (client *AlertsClient) getAllCreateRequest(ctx context.Context, options *AlertsGetAllOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/alerts" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + if options != nil && options.TargetResource != nil { + reqQP.Set("targetResource", *options.TargetResource) + } + if options != nil && options.TargetResourceType != nil { + reqQP.Set("targetResourceType", *options.TargetResourceType) + } + if options != nil && options.TargetResourceGroup != nil { + reqQP.Set("targetResourceGroup", *options.TargetResourceGroup) + } + if options != nil && options.MonitorService != nil { + reqQP.Set("monitorService", string(*options.MonitorService)) + } + if options != nil && options.MonitorCondition != nil { + reqQP.Set("monitorCondition", string(*options.MonitorCondition)) + } + if options != nil && options.Severity != nil { + reqQP.Set("severity", string(*options.Severity)) + } + if options != nil && options.AlertState != nil { + reqQP.Set("alertState", string(*options.AlertState)) + } + if options != nil && options.AlertRule != nil { + reqQP.Set("alertRule", *options.AlertRule) + } + if options != nil && options.SmartGroupID != nil { + reqQP.Set("smartGroupId", *options.SmartGroupID) + } + if options != nil && options.IncludeContext != nil { + reqQP.Set("includeContext", strconv.FormatBool(*options.IncludeContext)) + } + if options != nil && options.IncludeEgressConfig != nil { + reqQP.Set("includeEgressConfig", strconv.FormatBool(*options.IncludeEgressConfig)) + } + if options != nil && options.PageCount != nil { + reqQP.Set("pageCount", strconv.FormatInt(int64(*options.PageCount), 10)) + } + if options != nil && options.SortBy != nil { + reqQP.Set("sortBy", string(*options.SortBy)) + } + if options != nil && options.SortOrder != nil { + reqQP.Set("sortOrder", string(*options.SortOrder)) + } + if options != nil && options.Select != nil { + reqQP.Set("select", *options.Select) + } + if options != nil && options.TimeRange != nil { + reqQP.Set("timeRange", string(*options.TimeRange)) + } + if options != nil && options.CustomTimeRange != nil { + reqQP.Set("customTimeRange", *options.CustomTimeRange) + } + reqQP.Set("api-version", "2019-05-05-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getAllHandleResponse handles the GetAll response. +func (client *AlertsClient) getAllHandleResponse(resp *http.Response) (AlertsGetAllResponse, error) { + result := AlertsGetAllResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.AlertsList); err != nil { + return AlertsGetAllResponse{}, err + } + return result, nil +} + +// getAllHandleError handles the GetAll error response. +func (client *AlertsClient) getAllHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseAutoGenerated{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// GetByID - Get information related to a specific alert +// If the operation fails it returns the *ErrorResponseAutoGenerated error type. +func (client *AlertsClient) GetByID(ctx context.Context, alertID string, options *AlertsGetByIDOptions) (AlertsGetByIDResponse, error) { + req, err := client.getByIDCreateRequest(ctx, alertID, options) + if err != nil { + return AlertsGetByIDResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return AlertsGetByIDResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return AlertsGetByIDResponse{}, client.getByIDHandleError(resp) + } + return client.getByIDHandleResponse(resp) +} + +// getByIDCreateRequest creates the GetByID request. +func (client *AlertsClient) getByIDCreateRequest(ctx context.Context, alertID string, options *AlertsGetByIDOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/alerts/{alertId}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if alertID == "" { + return nil, errors.New("parameter alertID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{alertId}", url.PathEscape(alertID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-05-05-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getByIDHandleResponse handles the GetByID response. +func (client *AlertsClient) getByIDHandleResponse(resp *http.Response) (AlertsGetByIDResponse, error) { + result := AlertsGetByIDResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.Alert); err != nil { + return AlertsGetByIDResponse{}, err + } + return result, nil +} + +// getByIDHandleError handles the GetByID error response. +func (client *AlertsClient) getByIDHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseAutoGenerated{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// GetHistory - Get the history of an alert, which captures any monitor condition changes (Fired/Resolved) and alert state changes (New/Acknowledged/Closed). +// If the operation fails it returns the *ErrorResponseAutoGenerated error type. +func (client *AlertsClient) GetHistory(ctx context.Context, alertID string, options *AlertsGetHistoryOptions) (AlertsGetHistoryResponse, error) { + req, err := client.getHistoryCreateRequest(ctx, alertID, options) + if err != nil { + return AlertsGetHistoryResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return AlertsGetHistoryResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return AlertsGetHistoryResponse{}, client.getHistoryHandleError(resp) + } + return client.getHistoryHandleResponse(resp) +} + +// getHistoryCreateRequest creates the GetHistory request. +func (client *AlertsClient) getHistoryCreateRequest(ctx context.Context, alertID string, options *AlertsGetHistoryOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/alerts/{alertId}/history" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if alertID == "" { + return nil, errors.New("parameter alertID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{alertId}", url.PathEscape(alertID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-05-05-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHistoryHandleResponse handles the GetHistory response. +func (client *AlertsClient) getHistoryHandleResponse(resp *http.Response) (AlertsGetHistoryResponse, error) { + result := AlertsGetHistoryResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.AlertModification); err != nil { + return AlertsGetHistoryResponse{}, err + } + return result, nil +} + +// getHistoryHandleError handles the GetHistory error response. +func (client *AlertsClient) getHistoryHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseAutoGenerated{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// GetSummary - Get a summarized count of your alerts grouped by various parameters (e.g. grouping by 'Severity' returns the count of alerts for each severity). +// If the operation fails it returns the *ErrorResponseAutoGenerated error type. +func (client *AlertsClient) GetSummary(ctx context.Context, groupby AlertsSummaryGroupByFields, options *AlertsGetSummaryOptions) (AlertsGetSummaryResponse, error) { + req, err := client.getSummaryCreateRequest(ctx, groupby, options) + if err != nil { + return AlertsGetSummaryResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return AlertsGetSummaryResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return AlertsGetSummaryResponse{}, client.getSummaryHandleError(resp) + } + return client.getSummaryHandleResponse(resp) +} + +// getSummaryCreateRequest creates the GetSummary request. +func (client *AlertsClient) getSummaryCreateRequest(ctx context.Context, groupby AlertsSummaryGroupByFields, options *AlertsGetSummaryOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/alertsSummary" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("groupby", string(groupby)) + if options != nil && options.IncludeSmartGroupsCount != nil { + reqQP.Set("includeSmartGroupsCount", strconv.FormatBool(*options.IncludeSmartGroupsCount)) + } + if options != nil && options.TargetResource != nil { + reqQP.Set("targetResource", *options.TargetResource) + } + if options != nil && options.TargetResourceType != nil { + reqQP.Set("targetResourceType", *options.TargetResourceType) + } + if options != nil && options.TargetResourceGroup != nil { + reqQP.Set("targetResourceGroup", *options.TargetResourceGroup) + } + if options != nil && options.MonitorService != nil { + reqQP.Set("monitorService", string(*options.MonitorService)) + } + if options != nil && options.MonitorCondition != nil { + reqQP.Set("monitorCondition", string(*options.MonitorCondition)) + } + if options != nil && options.Severity != nil { + reqQP.Set("severity", string(*options.Severity)) + } + if options != nil && options.AlertState != nil { + reqQP.Set("alertState", string(*options.AlertState)) + } + if options != nil && options.AlertRule != nil { + reqQP.Set("alertRule", *options.AlertRule) + } + if options != nil && options.TimeRange != nil { + reqQP.Set("timeRange", string(*options.TimeRange)) + } + if options != nil && options.CustomTimeRange != nil { + reqQP.Set("customTimeRange", *options.CustomTimeRange) + } + reqQP.Set("api-version", "2019-05-05-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getSummaryHandleResponse handles the GetSummary response. +func (client *AlertsClient) getSummaryHandleResponse(resp *http.Response) (AlertsGetSummaryResponse, error) { + result := AlertsGetSummaryResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.AlertsSummary); err != nil { + return AlertsGetSummaryResponse{}, err + } + return result, nil +} + +// getSummaryHandleError handles the GetSummary error response. +func (client *AlertsClient) getSummaryHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseAutoGenerated{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// MetaData - List alerts meta data information based on value of identifier parameter. +// If the operation fails it returns a generic error. +func (client *AlertsClient) MetaData(ctx context.Context, identifier Identifier, options *AlertsMetaDataOptions) (AlertsMetaDataResponse, error) { + req, err := client.metaDataCreateRequest(ctx, identifier, options) + if err != nil { + return AlertsMetaDataResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return AlertsMetaDataResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return AlertsMetaDataResponse{}, client.metaDataHandleError(resp) + } + return client.metaDataHandleResponse(resp) +} + +// metaDataCreateRequest creates the MetaData request. +func (client *AlertsClient) metaDataCreateRequest(ctx context.Context, identifier Identifier, options *AlertsMetaDataOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.AlertsManagement/alertsMetaData" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-05-05-preview") + reqQP.Set("identifier", string(identifier)) + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// metaDataHandleResponse handles the MetaData response. +func (client *AlertsClient) metaDataHandleResponse(resp *http.Response) (AlertsMetaDataResponse, error) { + result := AlertsMetaDataResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.AlertsMetaData); err != nil { + return AlertsMetaDataResponse{}, err + } + return result, nil +} + +// metaDataHandleError handles the MetaData error response. +func (client *AlertsClient) metaDataHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + if len(body) == 0 { + return runtime.NewResponseError(errors.New(resp.Status), resp) + } + return runtime.NewResponseError(errors.New(string(body)), resp) +} diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_constants.go b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_constants.go new file mode 100644 index 000000000000..7d4059b4565c --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_constants.go @@ -0,0 +1,543 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armalertsmanagement + +const ( + module = "armalertsmanagement" + version = "v0.1.0" +) + +// ActionRuleStatus - Indicates if the given action rule is enabled or disabled +type ActionRuleStatus string + +const ( + ActionRuleStatusDisabled ActionRuleStatus = "Disabled" + ActionRuleStatusEnabled ActionRuleStatus = "Enabled" +) + +// PossibleActionRuleStatusValues returns the possible values for the ActionRuleStatus const type. +func PossibleActionRuleStatusValues() []ActionRuleStatus { + return []ActionRuleStatus{ + ActionRuleStatusDisabled, + ActionRuleStatusEnabled, + } +} + +// ToPtr returns a *ActionRuleStatus pointing to the current value. +func (c ActionRuleStatus) ToPtr() *ActionRuleStatus { + return &c +} + +// ActionRuleType - Indicates type of action rule +type ActionRuleType string + +const ( + ActionRuleTypeActionGroup ActionRuleType = "ActionGroup" + ActionRuleTypeDiagnostics ActionRuleType = "Diagnostics" + ActionRuleTypeSuppression ActionRuleType = "Suppression" +) + +// PossibleActionRuleTypeValues returns the possible values for the ActionRuleType const type. +func PossibleActionRuleTypeValues() []ActionRuleType { + return []ActionRuleType{ + ActionRuleTypeActionGroup, + ActionRuleTypeDiagnostics, + ActionRuleTypeSuppression, + } +} + +// ToPtr returns a *ActionRuleType pointing to the current value. +func (c ActionRuleType) ToPtr() *ActionRuleType { + return &c +} + +// AlertModificationEvent - Reason for the modification +type AlertModificationEvent string + +const ( + AlertModificationEventAlertCreated AlertModificationEvent = "AlertCreated" + AlertModificationEventStateChange AlertModificationEvent = "StateChange" + AlertModificationEventMonitorConditionChange AlertModificationEvent = "MonitorConditionChange" + AlertModificationEventSeverityChange AlertModificationEvent = "SeverityChange" + AlertModificationEventActionRuleTriggered AlertModificationEvent = "ActionRuleTriggered" + AlertModificationEventActionRuleSuppressed AlertModificationEvent = "ActionRuleSuppressed" + AlertModificationEventActionsTriggered AlertModificationEvent = "ActionsTriggered" + AlertModificationEventActionsSuppressed AlertModificationEvent = "ActionsSuppressed" + AlertModificationEventActionsFailed AlertModificationEvent = "ActionsFailed" +) + +// PossibleAlertModificationEventValues returns the possible values for the AlertModificationEvent const type. +func PossibleAlertModificationEventValues() []AlertModificationEvent { + return []AlertModificationEvent{ + AlertModificationEventAlertCreated, + AlertModificationEventStateChange, + AlertModificationEventMonitorConditionChange, + AlertModificationEventSeverityChange, + AlertModificationEventActionRuleTriggered, + AlertModificationEventActionRuleSuppressed, + AlertModificationEventActionsTriggered, + AlertModificationEventActionsSuppressed, + AlertModificationEventActionsFailed, + } +} + +// ToPtr returns a *AlertModificationEvent pointing to the current value. +func (c AlertModificationEvent) ToPtr() *AlertModificationEvent { + return &c +} + +// AlertRuleState - The alert rule state. +type AlertRuleState string + +const ( + AlertRuleStateDisabled AlertRuleState = "Disabled" + AlertRuleStateEnabled AlertRuleState = "Enabled" +) + +// PossibleAlertRuleStateValues returns the possible values for the AlertRuleState const type. +func PossibleAlertRuleStateValues() []AlertRuleState { + return []AlertRuleState{ + AlertRuleStateDisabled, + AlertRuleStateEnabled, + } +} + +// ToPtr returns a *AlertRuleState pointing to the current value. +func (c AlertRuleState) ToPtr() *AlertRuleState { + return &c +} + +type AlertState string + +const ( + AlertStateAcknowledged AlertState = "Acknowledged" + AlertStateClosed AlertState = "Closed" + AlertStateNew AlertState = "New" +) + +// PossibleAlertStateValues returns the possible values for the AlertState const type. +func PossibleAlertStateValues() []AlertState { + return []AlertState{ + AlertStateAcknowledged, + AlertStateClosed, + AlertStateNew, + } +} + +// ToPtr returns a *AlertState pointing to the current value. +func (c AlertState) ToPtr() *AlertState { + return &c +} + +type AlertsSortByFields string + +const ( + AlertsSortByFieldsAlertState AlertsSortByFields = "alertState" + AlertsSortByFieldsLastModifiedDateTime AlertsSortByFields = "lastModifiedDateTime" + AlertsSortByFieldsMonitorCondition AlertsSortByFields = "monitorCondition" + AlertsSortByFieldsName AlertsSortByFields = "name" + AlertsSortByFieldsSeverity AlertsSortByFields = "severity" + AlertsSortByFieldsStartDateTime AlertsSortByFields = "startDateTime" + AlertsSortByFieldsTargetResource AlertsSortByFields = "targetResource" + AlertsSortByFieldsTargetResourceGroup AlertsSortByFields = "targetResourceGroup" + AlertsSortByFieldsTargetResourceName AlertsSortByFields = "targetResourceName" + AlertsSortByFieldsTargetResourceType AlertsSortByFields = "targetResourceType" +) + +// PossibleAlertsSortByFieldsValues returns the possible values for the AlertsSortByFields const type. +func PossibleAlertsSortByFieldsValues() []AlertsSortByFields { + return []AlertsSortByFields{ + AlertsSortByFieldsAlertState, + AlertsSortByFieldsLastModifiedDateTime, + AlertsSortByFieldsMonitorCondition, + AlertsSortByFieldsName, + AlertsSortByFieldsSeverity, + AlertsSortByFieldsStartDateTime, + AlertsSortByFieldsTargetResource, + AlertsSortByFieldsTargetResourceGroup, + AlertsSortByFieldsTargetResourceName, + AlertsSortByFieldsTargetResourceType, + } +} + +// ToPtr returns a *AlertsSortByFields pointing to the current value. +func (c AlertsSortByFields) ToPtr() *AlertsSortByFields { + return &c +} + +type AlertsSummaryGroupByFields string + +const ( + AlertsSummaryGroupByFieldsAlertRule AlertsSummaryGroupByFields = "alertRule" + AlertsSummaryGroupByFieldsAlertState AlertsSummaryGroupByFields = "alertState" + AlertsSummaryGroupByFieldsMonitorCondition AlertsSummaryGroupByFields = "monitorCondition" + AlertsSummaryGroupByFieldsMonitorService AlertsSummaryGroupByFields = "monitorService" + AlertsSummaryGroupByFieldsSeverity AlertsSummaryGroupByFields = "severity" + AlertsSummaryGroupByFieldsSignalType AlertsSummaryGroupByFields = "signalType" +) + +// PossibleAlertsSummaryGroupByFieldsValues returns the possible values for the AlertsSummaryGroupByFields const type. +func PossibleAlertsSummaryGroupByFieldsValues() []AlertsSummaryGroupByFields { + return []AlertsSummaryGroupByFields{ + AlertsSummaryGroupByFieldsAlertRule, + AlertsSummaryGroupByFieldsAlertState, + AlertsSummaryGroupByFieldsMonitorCondition, + AlertsSummaryGroupByFieldsMonitorService, + AlertsSummaryGroupByFieldsSeverity, + AlertsSummaryGroupByFieldsSignalType, + } +} + +// ToPtr returns a *AlertsSummaryGroupByFields pointing to the current value. +func (c AlertsSummaryGroupByFields) ToPtr() *AlertsSummaryGroupByFields { + return &c +} + +type Enum11 string + +const ( + Enum11Asc Enum11 = "asc" + Enum11Desc Enum11 = "desc" +) + +// PossibleEnum11Values returns the possible values for the Enum11 const type. +func PossibleEnum11Values() []Enum11 { + return []Enum11{ + Enum11Asc, + Enum11Desc, + } +} + +// ToPtr returns a *Enum11 pointing to the current value. +func (c Enum11) ToPtr() *Enum11 { + return &c +} + +type Identifier string + +const ( + IdentifierMonitorServiceList Identifier = "MonitorServiceList" +) + +// PossibleIdentifierValues returns the possible values for the Identifier const type. +func PossibleIdentifierValues() []Identifier { + return []Identifier{ + IdentifierMonitorServiceList, + } +} + +// ToPtr returns a *Identifier pointing to the current value. +func (c Identifier) ToPtr() *Identifier { + return &c +} + +// MetadataIdentifier - Identification of the information to be retrieved by API call +type MetadataIdentifier string + +const ( + MetadataIdentifierMonitorServiceList MetadataIdentifier = "MonitorServiceList" +) + +// PossibleMetadataIdentifierValues returns the possible values for the MetadataIdentifier const type. +func PossibleMetadataIdentifierValues() []MetadataIdentifier { + return []MetadataIdentifier{ + MetadataIdentifierMonitorServiceList, + } +} + +// ToPtr returns a *MetadataIdentifier pointing to the current value. +func (c MetadataIdentifier) ToPtr() *MetadataIdentifier { + return &c +} + +type MonitorCondition string + +const ( + MonitorConditionFired MonitorCondition = "Fired" + MonitorConditionResolved MonitorCondition = "Resolved" +) + +// PossibleMonitorConditionValues returns the possible values for the MonitorCondition const type. +func PossibleMonitorConditionValues() []MonitorCondition { + return []MonitorCondition{ + MonitorConditionFired, + MonitorConditionResolved, + } +} + +// ToPtr returns a *MonitorCondition pointing to the current value. +func (c MonitorCondition) ToPtr() *MonitorCondition { + return &c +} + +type MonitorService string + +const ( + MonitorServiceActivityLogAdministrative MonitorService = "ActivityLog Administrative" + MonitorServiceActivityLogAutoscale MonitorService = "ActivityLog Autoscale" + MonitorServiceActivityLogPolicy MonitorService = "ActivityLog Policy" + MonitorServiceActivityLogRecommendation MonitorService = "ActivityLog Recommendation" + MonitorServiceActivityLogSecurity MonitorService = "ActivityLog Security" + MonitorServiceApplicationInsights MonitorService = "Application Insights" + MonitorServiceLogAnalytics MonitorService = "Log Analytics" + MonitorServiceNagios MonitorService = "Nagios" + MonitorServicePlatform MonitorService = "Platform" + MonitorServiceSCOM MonitorService = "SCOM" + MonitorServiceServiceHealth MonitorService = "ServiceHealth" + MonitorServiceSmartDetector MonitorService = "SmartDetector" + MonitorServiceVMInsights MonitorService = "VM Insights" + MonitorServiceZabbix MonitorService = "Zabbix" +) + +// PossibleMonitorServiceValues returns the possible values for the MonitorService const type. +func PossibleMonitorServiceValues() []MonitorService { + return []MonitorService{ + MonitorServiceActivityLogAdministrative, + MonitorServiceActivityLogAutoscale, + MonitorServiceActivityLogPolicy, + MonitorServiceActivityLogRecommendation, + MonitorServiceActivityLogSecurity, + MonitorServiceApplicationInsights, + MonitorServiceLogAnalytics, + MonitorServiceNagios, + MonitorServicePlatform, + MonitorServiceSCOM, + MonitorServiceServiceHealth, + MonitorServiceSmartDetector, + MonitorServiceVMInsights, + MonitorServiceZabbix, + } +} + +// ToPtr returns a *MonitorService pointing to the current value. +func (c MonitorService) ToPtr() *MonitorService { + return &c +} + +// Operator - operator for a given condition +type Operator string + +const ( + OperatorContains Operator = "Contains" + OperatorDoesNotContain Operator = "DoesNotContain" + OperatorEquals Operator = "Equals" + OperatorNotEquals Operator = "NotEquals" +) + +// PossibleOperatorValues returns the possible values for the Operator const type. +func PossibleOperatorValues() []Operator { + return []Operator{ + OperatorContains, + OperatorDoesNotContain, + OperatorEquals, + OperatorNotEquals, + } +} + +// ToPtr returns a *Operator pointing to the current value. +func (c Operator) ToPtr() *Operator { + return &c +} + +// ScopeType - type of target scope +type ScopeType string + +const ( + ScopeTypeResource ScopeType = "Resource" + ScopeTypeResourceGroup ScopeType = "ResourceGroup" + ScopeTypeSubscription ScopeType = "Subscription" +) + +// PossibleScopeTypeValues returns the possible values for the ScopeType const type. +func PossibleScopeTypeValues() []ScopeType { + return []ScopeType{ + ScopeTypeResource, + ScopeTypeResourceGroup, + ScopeTypeSubscription, + } +} + +// ToPtr returns a *ScopeType pointing to the current value. +func (c ScopeType) ToPtr() *ScopeType { + return &c +} + +type Severity string + +const ( + SeveritySev0 Severity = "Sev0" + SeveritySev1 Severity = "Sev1" + SeveritySev2 Severity = "Sev2" + SeveritySev3 Severity = "Sev3" + SeveritySev4 Severity = "Sev4" +) + +// PossibleSeverityValues returns the possible values for the Severity const type. +func PossibleSeverityValues() []Severity { + return []Severity{ + SeveritySev0, + SeveritySev1, + SeveritySev2, + SeveritySev3, + SeveritySev4, + } +} + +// ToPtr returns a *Severity pointing to the current value. +func (c Severity) ToPtr() *Severity { + return &c +} + +// SignalType - The type of signal the alert is based on, which could be metrics, logs or activity logs. +type SignalType string + +const ( + SignalTypeLog SignalType = "Log" + SignalTypeMetric SignalType = "Metric" + SignalTypeUnknown SignalType = "Unknown" +) + +// PossibleSignalTypeValues returns the possible values for the SignalType const type. +func PossibleSignalTypeValues() []SignalType { + return []SignalType{ + SignalTypeLog, + SignalTypeMetric, + SignalTypeUnknown, + } +} + +// ToPtr returns a *SignalType pointing to the current value. +func (c SignalType) ToPtr() *SignalType { + return &c +} + +// SmartGroupModificationEvent - Reason for the modification +type SmartGroupModificationEvent string + +const ( + SmartGroupModificationEventSmartGroupCreated SmartGroupModificationEvent = "SmartGroupCreated" + SmartGroupModificationEventStateChange SmartGroupModificationEvent = "StateChange" + SmartGroupModificationEventAlertAdded SmartGroupModificationEvent = "AlertAdded" + SmartGroupModificationEventAlertRemoved SmartGroupModificationEvent = "AlertRemoved" +) + +// PossibleSmartGroupModificationEventValues returns the possible values for the SmartGroupModificationEvent const type. +func PossibleSmartGroupModificationEventValues() []SmartGroupModificationEvent { + return []SmartGroupModificationEvent{ + SmartGroupModificationEventSmartGroupCreated, + SmartGroupModificationEventStateChange, + SmartGroupModificationEventAlertAdded, + SmartGroupModificationEventAlertRemoved, + } +} + +// ToPtr returns a *SmartGroupModificationEvent pointing to the current value. +func (c SmartGroupModificationEvent) ToPtr() *SmartGroupModificationEvent { + return &c +} + +type SmartGroupsSortByFields string + +const ( + SmartGroupsSortByFieldsAlertsCount SmartGroupsSortByFields = "alertsCount" + SmartGroupsSortByFieldsLastModifiedDateTime SmartGroupsSortByFields = "lastModifiedDateTime" + SmartGroupsSortByFieldsSeverity SmartGroupsSortByFields = "severity" + SmartGroupsSortByFieldsStartDateTime SmartGroupsSortByFields = "startDateTime" + SmartGroupsSortByFieldsState SmartGroupsSortByFields = "state" +) + +// PossibleSmartGroupsSortByFieldsValues returns the possible values for the SmartGroupsSortByFields const type. +func PossibleSmartGroupsSortByFieldsValues() []SmartGroupsSortByFields { + return []SmartGroupsSortByFields{ + SmartGroupsSortByFieldsAlertsCount, + SmartGroupsSortByFieldsLastModifiedDateTime, + SmartGroupsSortByFieldsSeverity, + SmartGroupsSortByFieldsStartDateTime, + SmartGroupsSortByFieldsState, + } +} + +// ToPtr returns a *SmartGroupsSortByFields pointing to the current value. +func (c SmartGroupsSortByFields) ToPtr() *SmartGroupsSortByFields { + return &c +} + +// State - Smart group state +type State string + +const ( + StateAcknowledged State = "Acknowledged" + StateClosed State = "Closed" + StateNew State = "New" +) + +// PossibleStateValues returns the possible values for the State const type. +func PossibleStateValues() []State { + return []State{ + StateAcknowledged, + StateClosed, + StateNew, + } +} + +// ToPtr returns a *State pointing to the current value. +func (c State) ToPtr() *State { + return &c +} + +// SuppressionType - Specifies when the suppression should be applied +type SuppressionType string + +const ( + SuppressionTypeAlways SuppressionType = "Always" + SuppressionTypeDaily SuppressionType = "Daily" + SuppressionTypeMonthly SuppressionType = "Monthly" + SuppressionTypeOnce SuppressionType = "Once" + SuppressionTypeWeekly SuppressionType = "Weekly" +) + +// PossibleSuppressionTypeValues returns the possible values for the SuppressionType const type. +func PossibleSuppressionTypeValues() []SuppressionType { + return []SuppressionType{ + SuppressionTypeAlways, + SuppressionTypeDaily, + SuppressionTypeMonthly, + SuppressionTypeOnce, + SuppressionTypeWeekly, + } +} + +// ToPtr returns a *SuppressionType pointing to the current value. +func (c SuppressionType) ToPtr() *SuppressionType { + return &c +} + +type TimeRange string + +const ( + TimeRangeOneD TimeRange = "1d" + TimeRangeOneH TimeRange = "1h" + TimeRangeSevenD TimeRange = "7d" + TimeRangeThirtyD TimeRange = "30d" +) + +// PossibleTimeRangeValues returns the possible values for the TimeRange const type. +func PossibleTimeRangeValues() []TimeRange { + return []TimeRange{ + TimeRangeOneD, + TimeRangeOneH, + TimeRangeSevenD, + TimeRangeThirtyD, + } +} + +// ToPtr returns a *TimeRange pointing to the current value. +func (c TimeRange) ToPtr() *TimeRange { + return &c +} diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_models.go b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_models.go new file mode 100644 index 000000000000..11479ad259db --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_models.go @@ -0,0 +1,1928 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armalertsmanagement + +import ( + "encoding/json" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "time" +) + +// ActionGroup - Action rule with action group configuration +type ActionGroup struct { + ActionRuleProperties + // REQUIRED; Action group to trigger if action rule matches + ActionGroupID *string `json:"actionGroupId,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ActionGroup. +func (a ActionGroup) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + a.ActionRuleProperties.marshalInternal(objectMap, ActionRuleTypeActionGroup) + populate(objectMap, "actionGroupId", a.ActionGroupID) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ActionGroup. +func (a *ActionGroup) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "actionGroupId": + err = unpopulate(val, &a.ActionGroupID) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + if err := a.ActionRuleProperties.unmarshalInternal(rawMsg); err != nil { + return err + } + return nil +} + +// ActionGroupsInformation - The Action Groups information, used by the alert rule. +type ActionGroupsInformation struct { + // REQUIRED; The Action Group resource IDs. + GroupIDs []*string `json:"groupIds,omitempty"` + + // An optional custom email subject to use in email notifications. + CustomEmailSubject *string `json:"customEmailSubject,omitempty"` + + // An optional custom web-hook payload to use in web-hook notifications. + CustomWebhookPayload *string `json:"customWebhookPayload,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ActionGroupsInformation. +func (a ActionGroupsInformation) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "customEmailSubject", a.CustomEmailSubject) + populate(objectMap, "customWebhookPayload", a.CustomWebhookPayload) + populate(objectMap, "groupIds", a.GroupIDs) + return json.Marshal(objectMap) +} + +// ActionRule - Action rule object containing target scope, conditions and suppression logic +type ActionRule struct { + ManagedResource + // action rule properties + Properties ActionRulePropertiesClassification `json:"properties,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ActionRule. +func (a ActionRule) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + a.ManagedResource.marshalInternal(objectMap) + populate(objectMap, "properties", a.Properties) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ActionRule. +func (a *ActionRule) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "properties": + a.Properties, err = unmarshalActionRulePropertiesClassification(val) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + if err := a.ManagedResource.unmarshalInternal(rawMsg); err != nil { + return err + } + return nil +} + +// ActionRulePropertiesClassification provides polymorphic access to related types. +// Call the interface's GetActionRuleProperties() method to access the common type. +// Use a type switch to determine the concrete type. The possible types are: +// - *ActionGroup, *ActionRuleProperties, *Diagnostics, *Suppression +type ActionRulePropertiesClassification interface { + // GetActionRuleProperties returns the ActionRuleProperties content of the underlying type. + GetActionRuleProperties() *ActionRuleProperties +} + +// ActionRuleProperties - Action rule properties defining scope, conditions, suppression logic for action rule +type ActionRuleProperties struct { + // REQUIRED; Indicates type of action rule + Type *ActionRuleType `json:"type,omitempty"` + + // conditions on which alerts will be filtered + Conditions *Conditions `json:"conditions,omitempty"` + + // Description of action rule + Description *string `json:"description,omitempty"` + + // scope on which action rule will apply + Scope *Scope `json:"scope,omitempty"` + + // Indicates if the given action rule is enabled or disabled + Status *ActionRuleStatus `json:"status,omitempty"` + + // READ-ONLY; Creation time of action rule. Date-Time in ISO-8601 format. + CreatedAt *time.Time `json:"createdAt,omitempty" azure:"ro"` + + // READ-ONLY; Created by user name. + CreatedBy *string `json:"createdBy,omitempty" azure:"ro"` + + // READ-ONLY; Last updated time of action rule. Date-Time in ISO-8601 format. + LastModifiedAt *time.Time `json:"lastModifiedAt,omitempty" azure:"ro"` + + // READ-ONLY; Last modified by user name. + LastModifiedBy *string `json:"lastModifiedBy,omitempty" azure:"ro"` +} + +// GetActionRuleProperties implements the ActionRulePropertiesClassification interface for type ActionRuleProperties. +func (a *ActionRuleProperties) GetActionRuleProperties() *ActionRuleProperties { return a } + +// UnmarshalJSON implements the json.Unmarshaller interface for type ActionRuleProperties. +func (a *ActionRuleProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + return a.unmarshalInternal(rawMsg) +} + +func (a ActionRuleProperties) marshalInternal(objectMap map[string]interface{}, discValue ActionRuleType) { + populate(objectMap, "conditions", a.Conditions) + populate(objectMap, "createdAt", (*timeRFC3339)(a.CreatedAt)) + populate(objectMap, "createdBy", a.CreatedBy) + populate(objectMap, "description", a.Description) + populate(objectMap, "lastModifiedAt", (*timeRFC3339)(a.LastModifiedAt)) + populate(objectMap, "lastModifiedBy", a.LastModifiedBy) + populate(objectMap, "scope", a.Scope) + populate(objectMap, "status", a.Status) + a.Type = &discValue + objectMap["type"] = a.Type +} + +func (a *ActionRuleProperties) unmarshalInternal(rawMsg map[string]json.RawMessage) error { + for key, val := range rawMsg { + var err error + switch key { + case "conditions": + err = unpopulate(val, &a.Conditions) + delete(rawMsg, key) + case "createdAt": + var aux timeRFC3339 + err = unpopulate(val, &aux) + a.CreatedAt = (*time.Time)(&aux) + delete(rawMsg, key) + case "createdBy": + err = unpopulate(val, &a.CreatedBy) + delete(rawMsg, key) + case "description": + err = unpopulate(val, &a.Description) + delete(rawMsg, key) + case "lastModifiedAt": + var aux timeRFC3339 + err = unpopulate(val, &aux) + a.LastModifiedAt = (*time.Time)(&aux) + delete(rawMsg, key) + case "lastModifiedBy": + err = unpopulate(val, &a.LastModifiedBy) + delete(rawMsg, key) + case "scope": + err = unpopulate(val, &a.Scope) + delete(rawMsg, key) + case "status": + err = unpopulate(val, &a.Status) + delete(rawMsg, key) + case "type": + err = unpopulate(val, &a.Type) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// ActionRulesCreateUpdateOptions contains the optional parameters for the ActionRules.CreateUpdate method. +type ActionRulesCreateUpdateOptions struct { + // placeholder for future optional parameters +} + +// ActionRulesDeleteOptions contains the optional parameters for the ActionRules.Delete method. +type ActionRulesDeleteOptions struct { + // placeholder for future optional parameters +} + +// ActionRulesGetByNameOptions contains the optional parameters for the ActionRules.GetByName method. +type ActionRulesGetByNameOptions struct { + // placeholder for future optional parameters +} + +// ActionRulesList - List of action rules +type ActionRulesList struct { + // URL to fetch the next set of action rules + NextLink *string `json:"nextLink,omitempty"` + + // List of action rules + Value []*ActionRule `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ActionRulesList. +func (a ActionRulesList) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", a.NextLink) + populate(objectMap, "value", a.Value) + return json.Marshal(objectMap) +} + +// ActionRulesListByResourceGroupOptions contains the optional parameters for the ActionRules.ListByResourceGroup method. +type ActionRulesListByResourceGroupOptions struct { + // filter by action group configured as part of action rule + ActionGroup *string + // filter by alert rule id + AlertRuleID *string + // filter by alert rule description + Description *string + // filter by impacted/target scope (provide comma separated list for multiple scopes). The value should be an well constructed ARM id of the scope. + ImpactedScope *string + // Filter by monitor service which generates the alert instance. Default value is select all. + MonitorService *MonitorService + // filter by action rule name + Name *string + // Filter by severity. Default value is select all. + Severity *Severity + // Filter by target resource( which is full ARM ID) Default value is select all. + TargetResource *string + // Filter by target resource group name. Default value is select all. + TargetResourceGroup *string + // Filter by target resource type. Default value is select all. + TargetResourceType *string +} + +// ActionRulesListBySubscriptionOptions contains the optional parameters for the ActionRules.ListBySubscription method. +type ActionRulesListBySubscriptionOptions struct { + // filter by action group configured as part of action rule + ActionGroup *string + // filter by alert rule id + AlertRuleID *string + // filter by alert rule description + Description *string + // filter by impacted/target scope (provide comma separated list for multiple scopes). The value should be an well constructed ARM id of the scope. + ImpactedScope *string + // Filter by monitor service which generates the alert instance. Default value is select all. + MonitorService *MonitorService + // filter by action rule name + Name *string + // Filter by severity. Default value is select all. + Severity *Severity + // Filter by target resource( which is full ARM ID) Default value is select all. + TargetResource *string + // Filter by target resource group name. Default value is select all. + TargetResourceGroup *string + // Filter by target resource type. Default value is select all. + TargetResourceType *string +} + +// ActionRulesUpdateOptions contains the optional parameters for the ActionRules.Update method. +type ActionRulesUpdateOptions struct { + // placeholder for future optional parameters +} + +// Alert - An alert created in alert management service. +type Alert struct { + Resource + // Alert property bag + Properties *AlertProperties `json:"properties,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type Alert. +func (a Alert) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + a.Resource.marshalInternal(objectMap) + populate(objectMap, "properties", a.Properties) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Alert. +func (a *Alert) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "properties": + err = unpopulate(val, &a.Properties) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + if err := a.Resource.unmarshalInternal(rawMsg); err != nil { + return err + } + return nil +} + +// AlertModification - Alert Modification details +type AlertModification struct { + Resource + // Properties of the alert modification item. + Properties *AlertModificationProperties `json:"properties,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type AlertModification. +func (a AlertModification) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + a.Resource.marshalInternal(objectMap) + populate(objectMap, "properties", a.Properties) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type AlertModification. +func (a *AlertModification) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "properties": + err = unpopulate(val, &a.Properties) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + if err := a.Resource.unmarshalInternal(rawMsg); err != nil { + return err + } + return nil +} + +// AlertModificationItem - Alert modification item. +type AlertModificationItem struct { + // Modification comments + Comments *string `json:"comments,omitempty"` + + // Description of the modification + Description *string `json:"description,omitempty"` + + // Reason for the modification + ModificationEvent *AlertModificationEvent `json:"modificationEvent,omitempty"` + + // Modified date and time + ModifiedAt *string `json:"modifiedAt,omitempty"` + + // Modified user details (Principal client name) + ModifiedBy *string `json:"modifiedBy,omitempty"` + + // New value + NewValue *string `json:"newValue,omitempty"` + + // Old value + OldValue *string `json:"oldValue,omitempty"` +} + +// AlertModificationProperties - Properties of the alert modification item. +type AlertModificationProperties struct { + // Modification details + Modifications []*AlertModificationItem `json:"modifications,omitempty"` + + // READ-ONLY; Unique Id of the alert for which the history is being retrieved + AlertID *string `json:"alertId,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type AlertModificationProperties. +func (a AlertModificationProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "alertId", a.AlertID) + populate(objectMap, "modifications", a.Modifications) + return json.Marshal(objectMap) +} + +// AlertProperties - Alert property bag +type AlertProperties struct { + // This object contains consistent fields across different monitor services. + Essentials *Essentials `json:"essentials,omitempty"` + + // READ-ONLY; Any object + Context map[string]interface{} `json:"context,omitempty" azure:"ro"` + + // READ-ONLY; Any object + EgressConfig map[string]interface{} `json:"egressConfig,omitempty" azure:"ro"` +} + +// AlertRule - The alert rule information +type AlertRule struct { + AzureResource + // The properties of the alert rule. + Properties *AlertRuleProperties `json:"properties,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type AlertRule. +func (a AlertRule) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + a.AzureResource.marshalInternal(objectMap) + populate(objectMap, "properties", a.Properties) + return json.Marshal(objectMap) +} + +// AlertRulePatchObject - The alert rule patch information +type AlertRulePatchObject struct { + // The properties of the alert rule. + Properties *AlertRulePatchProperties `json:"properties,omitempty"` + + // The resource tags. + Tags map[string]*string `json:"tags,omitempty"` + + // READ-ONLY; The resource ID. + ID *string `json:"id,omitempty" azure:"ro"` + + // READ-ONLY; The resource name. + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; The resource type. + Type *string `json:"type,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type AlertRulePatchObject. +func (a AlertRulePatchObject) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "id", a.ID) + populate(objectMap, "name", a.Name) + populate(objectMap, "properties", a.Properties) + populate(objectMap, "tags", a.Tags) + populate(objectMap, "type", a.Type) + return json.Marshal(objectMap) +} + +// AlertRulePatchProperties - The alert rule properties. +type AlertRulePatchProperties struct { + // The alert rule actions. + ActionGroups *ActionGroupsInformation `json:"actionGroups,omitempty"` + + // The alert rule description. + Description *string `json:"description,omitempty"` + + // The alert rule frequency in ISO8601 format. The time granularity must be in minutes and minimum value is 5 minutes. + Frequency *string `json:"frequency,omitempty"` + + // The alert rule severity. + Severity *Severity `json:"severity,omitempty"` + + // The alert rule state. + State *AlertRuleState `json:"state,omitempty"` + + // The alert rule throttling information. + Throttling *ThrottlingInformation `json:"throttling,omitempty"` +} + +// AlertRuleProperties - The alert rule properties. +type AlertRuleProperties struct { + // REQUIRED; The alert rule actions. + ActionGroups *ActionGroupsInformation `json:"actionGroups,omitempty"` + + // REQUIRED; The alert rule's detector. + Detector *Detector `json:"detector,omitempty"` + + // REQUIRED; The alert rule frequency in ISO8601 format. The time granularity must be in minutes and minimum value is 5 minutes. + Frequency *string `json:"frequency,omitempty"` + + // REQUIRED; The alert rule resources scope. + Scope []*string `json:"scope,omitempty"` + + // REQUIRED; The alert rule severity. + Severity *Severity `json:"severity,omitempty"` + + // REQUIRED; The alert rule state. + State *AlertRuleState `json:"state,omitempty"` + + // The alert rule description. + Description *string `json:"description,omitempty"` + + // The alert rule throttling information. + Throttling *ThrottlingInformation `json:"throttling,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type AlertRuleProperties. +func (a AlertRuleProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "actionGroups", a.ActionGroups) + populate(objectMap, "description", a.Description) + populate(objectMap, "detector", a.Detector) + populate(objectMap, "frequency", a.Frequency) + populate(objectMap, "scope", a.Scope) + populate(objectMap, "severity", a.Severity) + populate(objectMap, "state", a.State) + populate(objectMap, "throttling", a.Throttling) + return json.Marshal(objectMap) +} + +// AlertRulesList - List of Smart Detector alert rules. +type AlertRulesList struct { + // The URL to get the next set of results. + NextLink *string `json:"nextLink,omitempty"` + + // List of Smart Detector alert rules. + Value []*AlertRule `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type AlertRulesList. +func (a AlertRulesList) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", a.NextLink) + populate(objectMap, "value", a.Value) + return json.Marshal(objectMap) +} + +// AlertsChangeStateOptions contains the optional parameters for the Alerts.ChangeState method. +type AlertsChangeStateOptions struct { + // placeholder for future optional parameters +} + +// AlertsGetAllOptions contains the optional parameters for the Alerts.GetAll method. +type AlertsGetAllOptions struct { + // Filter by specific alert rule. Default value is to select all. + AlertRule *string + // Filter by state of the alert instance. Default value is to select all. + AlertState *AlertState + // Filter by custom time range in the format / where time is in (ISO-8601 format)'. Permissible values is within 30 days from query + // time. Either timeRange or customTimeRange could be used but not both. Default is none. + CustomTimeRange *string + // Include context which has contextual data specific to the monitor service. Default value is false' + IncludeContext *bool + // Include egress config which would be used for displaying the content in portal. Default value is 'false'. + IncludeEgressConfig *bool + // Filter by monitor condition which is either 'Fired' or 'Resolved'. Default value is to select all. + MonitorCondition *MonitorCondition + // Filter by monitor service which generates the alert instance. Default value is select all. + MonitorService *MonitorService + // Determines number of alerts returned per page in response. Permissible value is between 1 to 250. When the "includeContent" filter is selected, maximum + // value allowed is 25. Default value is 25. + PageCount *int32 + // This filter allows to selection of the fields(comma separated) which would be part of the essential section. This would allow to project only the required + // fields rather than getting entire content. Default is to fetch all the fields in the essentials section. + Select *string + // Filter by severity. Default value is select all. + Severity *Severity + // Filter the alerts list by the Smart Group Id. Default value is none. + SmartGroupID *string + // Sort the query results by input field, Default value is 'lastModifiedDateTime'. + SortBy *AlertsSortByFields + // Sort the query results order in either ascending or descending. Default value is 'desc' for time fields and 'asc' for others. + SortOrder *Enum11 + // Filter by target resource( which is full ARM ID) Default value is select all. + TargetResource *string + // Filter by target resource group name. Default value is select all. + TargetResourceGroup *string + // Filter by target resource type. Default value is select all. + TargetResourceType *string + // Filter by time range by below listed values. Default value is 1 day. + TimeRange *TimeRange +} + +// AlertsGetByIDOptions contains the optional parameters for the Alerts.GetByID method. +type AlertsGetByIDOptions struct { + // placeholder for future optional parameters +} + +// AlertsGetHistoryOptions contains the optional parameters for the Alerts.GetHistory method. +type AlertsGetHistoryOptions struct { + // placeholder for future optional parameters +} + +// AlertsGetSummaryOptions contains the optional parameters for the Alerts.GetSummary method. +type AlertsGetSummaryOptions struct { + // Filter by specific alert rule. Default value is to select all. + AlertRule *string + // Filter by state of the alert instance. Default value is to select all. + AlertState *AlertState + // Filter by custom time range in the format / where time is in (ISO-8601 format)'. Permissible values is within 30 days from query + // time. Either timeRange or customTimeRange could be used but not both. Default is none. + CustomTimeRange *string + // Include count of the SmartGroups as part of the summary. Default value is 'false'. + IncludeSmartGroupsCount *bool + // Filter by monitor condition which is either 'Fired' or 'Resolved'. Default value is to select all. + MonitorCondition *MonitorCondition + // Filter by monitor service which generates the alert instance. Default value is select all. + MonitorService *MonitorService + // Filter by severity. Default value is select all. + Severity *Severity + // Filter by target resource( which is full ARM ID) Default value is select all. + TargetResource *string + // Filter by target resource group name. Default value is select all. + TargetResourceGroup *string + // Filter by target resource type. Default value is select all. + TargetResourceType *string + // Filter by time range by below listed values. Default value is 1 day. + TimeRange *TimeRange +} + +// AlertsList - List the alerts. +type AlertsList struct { + // URL to fetch the next set of alerts. + NextLink *string `json:"nextLink,omitempty"` + + // List of alerts + Value []*Alert `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type AlertsList. +func (a AlertsList) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", a.NextLink) + populate(objectMap, "value", a.Value) + return json.Marshal(objectMap) +} + +// AlertsMetaData - alert meta data information. +type AlertsMetaData struct { + // alert meta data property bag + Properties AlertsMetaDataPropertiesClassification `json:"properties,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type AlertsMetaData. +func (a AlertsMetaData) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "properties", a.Properties) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type AlertsMetaData. +func (a *AlertsMetaData) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "properties": + a.Properties, err = unmarshalAlertsMetaDataPropertiesClassification(val) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// AlertsMetaDataOptions contains the optional parameters for the Alerts.MetaData method. +type AlertsMetaDataOptions struct { + // placeholder for future optional parameters +} + +// AlertsMetaDataPropertiesClassification provides polymorphic access to related types. +// Call the interface's GetAlertsMetaDataProperties() method to access the common type. +// Use a type switch to determine the concrete type. The possible types are: +// - *AlertsMetaDataProperties, *MonitorServiceList +type AlertsMetaDataPropertiesClassification interface { + // GetAlertsMetaDataProperties returns the AlertsMetaDataProperties content of the underlying type. + GetAlertsMetaDataProperties() *AlertsMetaDataProperties +} + +// AlertsMetaDataProperties - alert meta data property bag +type AlertsMetaDataProperties struct { + // REQUIRED; Identification of the information to be retrieved by API call + MetadataIdentifier *MetadataIdentifier `json:"metadataIdentifier,omitempty"` +} + +// GetAlertsMetaDataProperties implements the AlertsMetaDataPropertiesClassification interface for type AlertsMetaDataProperties. +func (a *AlertsMetaDataProperties) GetAlertsMetaDataProperties() *AlertsMetaDataProperties { return a } + +// UnmarshalJSON implements the json.Unmarshaller interface for type AlertsMetaDataProperties. +func (a *AlertsMetaDataProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + return a.unmarshalInternal(rawMsg) +} + +func (a AlertsMetaDataProperties) marshalInternal(objectMap map[string]interface{}, discValue MetadataIdentifier) { + a.MetadataIdentifier = &discValue + objectMap["metadataIdentifier"] = a.MetadataIdentifier +} + +func (a *AlertsMetaDataProperties) unmarshalInternal(rawMsg map[string]json.RawMessage) error { + for key, val := range rawMsg { + var err error + switch key { + case "metadataIdentifier": + err = unpopulate(val, &a.MetadataIdentifier) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// AlertsSummary - Summary of alerts based on the input filters and 'groupby' parameters. +type AlertsSummary struct { + Resource + // Group the result set. + Properties *AlertsSummaryGroup `json:"properties,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type AlertsSummary. +func (a AlertsSummary) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + a.Resource.marshalInternal(objectMap) + populate(objectMap, "properties", a.Properties) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type AlertsSummary. +func (a *AlertsSummary) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "properties": + err = unpopulate(val, &a.Properties) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + if err := a.Resource.unmarshalInternal(rawMsg); err != nil { + return err + } + return nil +} + +// AlertsSummaryGroup - Group the result set. +type AlertsSummaryGroup struct { + // Name of the field aggregated + Groupedby *string `json:"groupedby,omitempty"` + + // Total count of the smart groups. + SmartGroupsCount *int32 `json:"smartGroupsCount,omitempty"` + + // Total count of the result set. + Total *int32 `json:"total,omitempty"` + + // List of the items + Values []*AlertsSummaryGroupItem `json:"values,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type AlertsSummaryGroup. +func (a AlertsSummaryGroup) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "groupedby", a.Groupedby) + populate(objectMap, "smartGroupsCount", a.SmartGroupsCount) + populate(objectMap, "total", a.Total) + populate(objectMap, "values", a.Values) + return json.Marshal(objectMap) +} + +// AlertsSummaryGroupItem - Alerts summary group item +type AlertsSummaryGroupItem struct { + // Count of the aggregated field + Count *int32 `json:"count,omitempty"` + + // Name of the field aggregated + Groupedby *string `json:"groupedby,omitempty"` + + // Value of the aggregated field + Name *string `json:"name,omitempty"` + + // List of the items + Values []*AlertsSummaryGroupItem `json:"values,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type AlertsSummaryGroupItem. +func (a AlertsSummaryGroupItem) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "count", a.Count) + populate(objectMap, "groupedby", a.Groupedby) + populate(objectMap, "name", a.Name) + populate(objectMap, "values", a.Values) + return json.Marshal(objectMap) +} + +// AzureResource - An Azure resource object +type AzureResource struct { + // The resource location. + Location *string `json:"location,omitempty"` + + // The resource tags. + Tags map[string]*string `json:"tags,omitempty"` + + // READ-ONLY; The resource ID. + ID *string `json:"id,omitempty" azure:"ro"` + + // READ-ONLY; The resource name. + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; The resource type. + Type *string `json:"type,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type AzureResource. +func (a AzureResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + a.marshalInternal(objectMap) + return json.Marshal(objectMap) +} + +func (a AzureResource) marshalInternal(objectMap map[string]interface{}) { + populate(objectMap, "id", a.ID) + populate(objectMap, "location", a.Location) + populate(objectMap, "name", a.Name) + populate(objectMap, "tags", a.Tags) + populate(objectMap, "type", a.Type) +} + +// Condition - condition to trigger an action rule +type Condition struct { + // operator for a given condition + Operator *Operator `json:"operator,omitempty"` + + // list of values to match for a given condition. + Values []*string `json:"values,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type Condition. +func (c Condition) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "operator", c.Operator) + populate(objectMap, "values", c.Values) + return json.Marshal(objectMap) +} + +// Conditions in alert instance to be matched for a given action rule. Default value is all. Multiple values could be provided with comma separation. +type Conditions struct { + // filter alerts by alert context (payload) + AlertContext *Condition `json:"alertContext,omitempty"` + + // filter alerts by alert rule id + AlertRuleID *Condition `json:"alertRuleId,omitempty"` + + // filter alerts by alert rule description + Description *Condition `json:"description,omitempty"` + + // filter alerts by monitor condition + MonitorCondition *Condition `json:"monitorCondition,omitempty"` + + // filter alerts by monitor service + MonitorService *Condition `json:"monitorService,omitempty"` + + // filter alerts by severity + Severity *Condition `json:"severity,omitempty"` + + // filter alerts by target resource type + TargetResourceType *Condition `json:"targetResourceType,omitempty"` +} + +// Detector - The detector information. By default this is not populated, unless it's specified in expandDetector +type Detector struct { + // REQUIRED; The detector id. + ID *string `json:"id,omitempty"` + + // The Smart Detector description. By default this is not populated, unless it's specified in expandDetector + Description *string `json:"description,omitempty"` + + // The Smart Detector image path. By default this is not populated, unless it's specified in expandDetector + ImagePaths []*string `json:"imagePaths,omitempty"` + + // The Smart Detector name. By default this is not populated, unless it's specified in expandDetector + Name *string `json:"name,omitempty"` + + // The detector's parameters.' + Parameters map[string]map[string]interface{} `json:"parameters,omitempty"` + + // The Smart Detector supported resource types. By default this is not populated, unless it's specified in expandDetector + SupportedResourceTypes []*string `json:"supportedResourceTypes,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type Detector. +func (d Detector) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "description", d.Description) + populate(objectMap, "id", d.ID) + populate(objectMap, "imagePaths", d.ImagePaths) + populate(objectMap, "name", d.Name) + populate(objectMap, "parameters", d.Parameters) + populate(objectMap, "supportedResourceTypes", d.SupportedResourceTypes) + return json.Marshal(objectMap) +} + +// Diagnostics - Action rule with diagnostics configuration +type Diagnostics struct { + ActionRuleProperties +} + +// MarshalJSON implements the json.Marshaller interface for type Diagnostics. +func (d Diagnostics) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + d.ActionRuleProperties.marshalInternal(objectMap, ActionRuleTypeDiagnostics) + return json.Marshal(objectMap) +} + +// ErrorResponse - An error response from the service. +// Implements the error and azcore.HTTPResponse interfaces. +type ErrorResponse struct { + raw string + // Details of error response. + InnerError *ErrorResponseBody `json:"error,omitempty"` +} + +// Error implements the error interface for type ErrorResponse. +// The contents of the error text are not contractual and subject to change. +func (e ErrorResponse) Error() string { + return e.raw +} + +// ErrorResponseAutoGenerated - An error response from the service. +// Implements the error and azcore.HTTPResponse interfaces. +type ErrorResponseAutoGenerated struct { + raw string + // Details of error response. + InnerError *ErrorResponseBodyAutoGenerated `json:"error,omitempty"` +} + +// Error implements the error interface for type ErrorResponseAutoGenerated. +// The contents of the error text are not contractual and subject to change. +func (e ErrorResponseAutoGenerated) Error() string { + return e.raw +} + +// ErrorResponseAutoGenerated2 - An error response from the service. +// Implements the error and azcore.HTTPResponse interfaces. +type ErrorResponseAutoGenerated2 struct { + raw string + // Details of error response. + InnerError *ErrorResponseBodyAutoGenerated2 `json:"error,omitempty"` +} + +// Error implements the error interface for type ErrorResponseAutoGenerated2. +// The contents of the error text are not contractual and subject to change. +func (e ErrorResponseAutoGenerated2) Error() string { + return e.raw +} + +// ErrorResponseBody - Details of error response. +type ErrorResponseBody struct { + // Error code, intended to be consumed programmatically. + Code *string `json:"code,omitempty"` + + // A list of additional details about the error. + Details []*ErrorResponseBody `json:"details,omitempty"` + + // Description of the error, intended for display in user interface. + Message *string `json:"message,omitempty"` + + // Target of the particular error, for example name of the property. + Target *string `json:"target,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ErrorResponseBody. +func (e ErrorResponseBody) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "code", e.Code) + populate(objectMap, "details", e.Details) + populate(objectMap, "message", e.Message) + populate(objectMap, "target", e.Target) + return json.Marshal(objectMap) +} + +// ErrorResponseBodyAutoGenerated - Details of error response. +type ErrorResponseBodyAutoGenerated struct { + // Error code, intended to be consumed programmatically. + Code *string `json:"code,omitempty"` + + // A list of additional details about the error. + Details []*ErrorResponseBodyAutoGenerated `json:"details,omitempty"` + + // Description of the error, intended for display in user interface. + Message *string `json:"message,omitempty"` + + // Target of the particular error, for example name of the property. + Target *string `json:"target,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ErrorResponseBodyAutoGenerated. +func (e ErrorResponseBodyAutoGenerated) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "code", e.Code) + populate(objectMap, "details", e.Details) + populate(objectMap, "message", e.Message) + populate(objectMap, "target", e.Target) + return json.Marshal(objectMap) +} + +// ErrorResponseBodyAutoGenerated2 - Details of error response. +type ErrorResponseBodyAutoGenerated2 struct { + // Error code, intended to be consumed programmatically. + Code *string `json:"code,omitempty"` + + // A list of additional details about the error. + Details []*ErrorResponseBodyAutoGenerated2 `json:"details,omitempty"` + + // Description of the error, intended for display in user interface. + Message *string `json:"message,omitempty"` + + // Target of the particular error, for example name of the property. + Target *string `json:"target,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ErrorResponseBodyAutoGenerated2. +func (e ErrorResponseBodyAutoGenerated2) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "code", e.Code) + populate(objectMap, "details", e.Details) + populate(objectMap, "message", e.Message) + populate(objectMap, "target", e.Target) + return json.Marshal(objectMap) +} + +// Essentials - This object contains consistent fields across different monitor services. +type Essentials struct { + // Target ARM resource, on which alert got created. + TargetResource *string `json:"targetResource,omitempty"` + + // Resource group of target ARM resource, on which alert got created. + TargetResourceGroup *string `json:"targetResourceGroup,omitempty"` + + // Name of the target ARM resource name, on which alert got created. + TargetResourceName *string `json:"targetResourceName,omitempty"` + + // Resource type of target ARM resource, on which alert got created. + TargetResourceType *string `json:"targetResourceType,omitempty"` + + // READ-ONLY; Rule(monitor) which fired alert instance. Depending on the monitor service, this would be ARM id or name of the rule. + AlertRule *string `json:"alertRule,omitempty" azure:"ro"` + + // READ-ONLY; Alert object state, which can be modified by the user. + AlertState *AlertState `json:"alertState,omitempty" azure:"ro"` + + // READ-ONLY; Last modification time(ISO-8601 format) of alert instance. + LastModifiedDateTime *time.Time `json:"lastModifiedDateTime,omitempty" azure:"ro"` + + // READ-ONLY; User who last modified the alert, in case of monitor service updates user would be 'system', otherwise name of the user. + LastModifiedUserName *string `json:"lastModifiedUserName,omitempty" azure:"ro"` + + // READ-ONLY; Condition of the rule at the monitor service. It represents whether the underlying conditions have crossed the defined alert rule thresholds. + MonitorCondition *MonitorCondition `json:"monitorCondition,omitempty" azure:"ro"` + + // READ-ONLY; Resolved time(ISO-8601 format) of alert instance. This will be updated when monitor service resolves the alert instance because the rule condition + // is no longer met. + MonitorConditionResolvedDateTime *time.Time `json:"monitorConditionResolvedDateTime,omitempty" azure:"ro"` + + // READ-ONLY; Monitor service on which the rule(monitor) is set. + MonitorService *MonitorService `json:"monitorService,omitempty" azure:"ro"` + + // READ-ONLY; Severity of alert Sev0 being highest and Sev4 being lowest. + Severity *Severity `json:"severity,omitempty" azure:"ro"` + + // READ-ONLY; The type of signal the alert is based on, which could be metrics, logs or activity logs. + SignalType *SignalType `json:"signalType,omitempty" azure:"ro"` + + // READ-ONLY; Unique Id of the smart group + SmartGroupID *string `json:"smartGroupId,omitempty" azure:"ro"` + + // READ-ONLY; Verbose reason describing the reason why this alert instance is added to a smart group + SmartGroupingReason *string `json:"smartGroupingReason,omitempty" azure:"ro"` + + // READ-ONLY; Unique Id created by monitor service for each alert instance. This could be used to track the issue at the monitor service, in case of Nagios, + // Zabbix, SCOM etc. + SourceCreatedID *string `json:"sourceCreatedId,omitempty" azure:"ro"` + + // READ-ONLY; Creation time(ISO-8601 format) of alert instance. + StartDateTime *time.Time `json:"startDateTime,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type Essentials. +func (e Essentials) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "alertRule", e.AlertRule) + populate(objectMap, "alertState", e.AlertState) + populate(objectMap, "lastModifiedDateTime", (*timeRFC3339)(e.LastModifiedDateTime)) + populate(objectMap, "lastModifiedUserName", e.LastModifiedUserName) + populate(objectMap, "monitorCondition", e.MonitorCondition) + populate(objectMap, "monitorConditionResolvedDateTime", (*timeRFC3339)(e.MonitorConditionResolvedDateTime)) + populate(objectMap, "monitorService", e.MonitorService) + populate(objectMap, "severity", e.Severity) + populate(objectMap, "signalType", e.SignalType) + populate(objectMap, "smartGroupId", e.SmartGroupID) + populate(objectMap, "smartGroupingReason", e.SmartGroupingReason) + populate(objectMap, "sourceCreatedId", e.SourceCreatedID) + populate(objectMap, "startDateTime", (*timeRFC3339)(e.StartDateTime)) + populate(objectMap, "targetResource", e.TargetResource) + populate(objectMap, "targetResourceGroup", e.TargetResourceGroup) + populate(objectMap, "targetResourceName", e.TargetResourceName) + populate(objectMap, "targetResourceType", e.TargetResourceType) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Essentials. +func (e *Essentials) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "alertRule": + err = unpopulate(val, &e.AlertRule) + delete(rawMsg, key) + case "alertState": + err = unpopulate(val, &e.AlertState) + delete(rawMsg, key) + case "lastModifiedDateTime": + var aux timeRFC3339 + err = unpopulate(val, &aux) + e.LastModifiedDateTime = (*time.Time)(&aux) + delete(rawMsg, key) + case "lastModifiedUserName": + err = unpopulate(val, &e.LastModifiedUserName) + delete(rawMsg, key) + case "monitorCondition": + err = unpopulate(val, &e.MonitorCondition) + delete(rawMsg, key) + case "monitorConditionResolvedDateTime": + var aux timeRFC3339 + err = unpopulate(val, &aux) + e.MonitorConditionResolvedDateTime = (*time.Time)(&aux) + delete(rawMsg, key) + case "monitorService": + err = unpopulate(val, &e.MonitorService) + delete(rawMsg, key) + case "severity": + err = unpopulate(val, &e.Severity) + delete(rawMsg, key) + case "signalType": + err = unpopulate(val, &e.SignalType) + delete(rawMsg, key) + case "smartGroupId": + err = unpopulate(val, &e.SmartGroupID) + delete(rawMsg, key) + case "smartGroupingReason": + err = unpopulate(val, &e.SmartGroupingReason) + delete(rawMsg, key) + case "sourceCreatedId": + err = unpopulate(val, &e.SourceCreatedID) + delete(rawMsg, key) + case "startDateTime": + var aux timeRFC3339 + err = unpopulate(val, &aux) + e.StartDateTime = (*time.Time)(&aux) + delete(rawMsg, key) + case "targetResource": + err = unpopulate(val, &e.TargetResource) + delete(rawMsg, key) + case "targetResourceGroup": + err = unpopulate(val, &e.TargetResourceGroup) + delete(rawMsg, key) + case "targetResourceName": + err = unpopulate(val, &e.TargetResourceName) + delete(rawMsg, key) + case "targetResourceType": + err = unpopulate(val, &e.TargetResourceType) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// ManagedResource - An azure managed resource object +type ManagedResource struct { + Resource + // REQUIRED; Resource location + Location *string `json:"location,omitempty"` + + // Resource tags + Tags map[string]*string `json:"tags,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ManagedResource. +func (m ManagedResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + m.marshalInternal(objectMap) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ManagedResource. +func (m *ManagedResource) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + return m.unmarshalInternal(rawMsg) +} + +func (m ManagedResource) marshalInternal(objectMap map[string]interface{}) { + m.Resource.marshalInternal(objectMap) + populate(objectMap, "location", m.Location) + populate(objectMap, "tags", m.Tags) +} + +func (m *ManagedResource) unmarshalInternal(rawMsg map[string]json.RawMessage) error { + for key, val := range rawMsg { + var err error + switch key { + case "location": + err = unpopulate(val, &m.Location) + delete(rawMsg, key) + case "tags": + err = unpopulate(val, &m.Tags) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + if err := m.Resource.unmarshalInternal(rawMsg); err != nil { + return err + } + return nil +} + +// MonitorServiceDetails - Details of a monitor service +type MonitorServiceDetails struct { + // Monitor service display name + DisplayName *string `json:"displayName,omitempty"` + + // Monitor service name + Name *string `json:"name,omitempty"` +} + +// MonitorServiceList - Monitor service details +type MonitorServiceList struct { + AlertsMetaDataProperties + // REQUIRED; Array of operations + Data []*MonitorServiceDetails `json:"data,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type MonitorServiceList. +func (m MonitorServiceList) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + m.AlertsMetaDataProperties.marshalInternal(objectMap, MetadataIdentifierMonitorServiceList) + populate(objectMap, "data", m.Data) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type MonitorServiceList. +func (m *MonitorServiceList) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "data": + err = unpopulate(val, &m.Data) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + if err := m.AlertsMetaDataProperties.unmarshalInternal(rawMsg); err != nil { + return err + } + return nil +} + +// Operation provided by provider +type Operation struct { + // Properties of the operation + Display *OperationDisplay `json:"display,omitempty"` + + // Name of the operation + Name *string `json:"name,omitempty"` +} + +// OperationDisplay - Properties of the operation +type OperationDisplay struct { + // Description of the operation + Description *string `json:"description,omitempty"` + + // Operation name + Operation *string `json:"operation,omitempty"` + + // Provider name + Provider *string `json:"provider,omitempty"` + + // Resource name + Resource *string `json:"resource,omitempty"` +} + +// OperationsList - Lists the operations available in the AlertsManagement RP. +type OperationsList struct { + // REQUIRED; Array of operations + Value []*Operation `json:"value,omitempty"` + + // URL to fetch the next set of alerts. + NextLink *string `json:"nextLink,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type OperationsList. +func (o OperationsList) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", o.NextLink) + populate(objectMap, "value", o.Value) + return json.Marshal(objectMap) +} + +// OperationsListOptions contains the optional parameters for the Operations.List method. +type OperationsListOptions struct { + // placeholder for future optional parameters +} + +// PatchObject - Data contract for patch +type PatchObject struct { + // properties supported by patch operation + Properties *PatchProperties `json:"properties,omitempty"` + + // tags to be updated + Tags map[string]interface{} `json:"tags,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type PatchObject. +func (p PatchObject) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "properties", p.Properties) + populate(objectMap, "tags", p.Tags) + return json.Marshal(objectMap) +} + +// PatchProperties - Action rule properties supported by patch +type PatchProperties struct { + // Indicates if the given action rule is enabled or disabled + Status *ActionRuleStatus `json:"status,omitempty"` +} + +// Resource - An azure resource object +type Resource struct { + // READ-ONLY; Azure resource Id + ID *string `json:"id,omitempty" azure:"ro"` + + // READ-ONLY; Azure resource name + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; Azure resource type + Type *string `json:"type,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type Resource. +func (r Resource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + r.marshalInternal(objectMap) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Resource. +func (r *Resource) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + return r.unmarshalInternal(rawMsg) +} + +func (r Resource) marshalInternal(objectMap map[string]interface{}) { + populate(objectMap, "id", r.ID) + populate(objectMap, "name", r.Name) + populate(objectMap, "type", r.Type) +} + +func (r *Resource) unmarshalInternal(rawMsg map[string]json.RawMessage) error { + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, &r.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, &r.Name) + delete(rawMsg, key) + case "type": + err = unpopulate(val, &r.Type) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// Scope - Target scope for a given action rule. By default scope will be the subscription. User can also provide list of resource groups or list of resources +// from the scope subscription as well. +type Scope struct { + // type of target scope + ScopeType *ScopeType `json:"scopeType,omitempty"` + + // list of ARM IDs of the given scope type which will be the target of the given action rule. + Values []*string `json:"values,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type Scope. +func (s Scope) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "scopeType", s.ScopeType) + populate(objectMap, "values", s.Values) + return json.Marshal(objectMap) +} + +// SmartDetectorAlertRulesCreateOrUpdateOptions contains the optional parameters for the SmartDetectorAlertRules.CreateOrUpdate method. +type SmartDetectorAlertRulesCreateOrUpdateOptions struct { + // placeholder for future optional parameters +} + +// SmartDetectorAlertRulesDeleteOptions contains the optional parameters for the SmartDetectorAlertRules.Delete method. +type SmartDetectorAlertRulesDeleteOptions struct { + // placeholder for future optional parameters +} + +// SmartDetectorAlertRulesGetOptions contains the optional parameters for the SmartDetectorAlertRules.Get method. +type SmartDetectorAlertRulesGetOptions struct { + // Indicates if Smart Detector should be expanded. + ExpandDetector *bool +} + +// SmartDetectorAlertRulesListByResourceGroupOptions contains the optional parameters for the SmartDetectorAlertRules.ListByResourceGroup method. +type SmartDetectorAlertRulesListByResourceGroupOptions struct { + // Indicates if Smart Detector should be expanded. + ExpandDetector *bool +} + +// SmartDetectorAlertRulesListOptions contains the optional parameters for the SmartDetectorAlertRules.List method. +type SmartDetectorAlertRulesListOptions struct { + // Indicates if Smart Detector should be expanded. + ExpandDetector *bool +} + +// SmartDetectorAlertRulesPatchOptions contains the optional parameters for the SmartDetectorAlertRules.Patch method. +type SmartDetectorAlertRulesPatchOptions struct { + // placeholder for future optional parameters +} + +// SmartDetectorErrorResponse - Describe the format of an Error response. +// Implements the error and azcore.HTTPResponse interfaces. +type SmartDetectorErrorResponse struct { + raw string + // Error code + Code *string `json:"code,omitempty"` + + // Error message indicating why the operation failed. + Message *string `json:"message,omitempty"` +} + +// Error implements the error interface for type SmartDetectorErrorResponse. +// The contents of the error text are not contractual and subject to change. +func (e SmartDetectorErrorResponse) Error() string { + return e.raw +} + +// SmartGroup - Set of related alerts grouped together smartly by AMS. +type SmartGroup struct { + Resource + // Properties of smart group. + Properties *SmartGroupProperties `json:"properties,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type SmartGroup. +func (s SmartGroup) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + s.Resource.marshalInternal(objectMap) + populate(objectMap, "properties", s.Properties) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SmartGroup. +func (s *SmartGroup) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "properties": + err = unpopulate(val, &s.Properties) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + if err := s.Resource.unmarshalInternal(rawMsg); err != nil { + return err + } + return nil +} + +// SmartGroupAggregatedProperty - Aggregated property of each type +type SmartGroupAggregatedProperty struct { + // Total number of items of type. + Count *int32 `json:"count,omitempty"` + + // Name of the type. + Name *string `json:"name,omitempty"` +} + +// SmartGroupModification - Alert Modification details +type SmartGroupModification struct { + Resource + // Properties of the smartGroup modification item. + Properties *SmartGroupModificationProperties `json:"properties,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type SmartGroupModification. +func (s SmartGroupModification) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + s.Resource.marshalInternal(objectMap) + populate(objectMap, "properties", s.Properties) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SmartGroupModification. +func (s *SmartGroupModification) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "properties": + err = unpopulate(val, &s.Properties) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + if err := s.Resource.unmarshalInternal(rawMsg); err != nil { + return err + } + return nil +} + +// SmartGroupModificationItem - smartGroup modification item. +type SmartGroupModificationItem struct { + // Modification comments + Comments *string `json:"comments,omitempty"` + + // Description of the modification + Description *string `json:"description,omitempty"` + + // Reason for the modification + ModificationEvent *SmartGroupModificationEvent `json:"modificationEvent,omitempty"` + + // Modified date and time + ModifiedAt *string `json:"modifiedAt,omitempty"` + + // Modified user details (Principal client name) + ModifiedBy *string `json:"modifiedBy,omitempty"` + + // New value + NewValue *string `json:"newValue,omitempty"` + + // Old value + OldValue *string `json:"oldValue,omitempty"` +} + +// SmartGroupModificationProperties - Properties of the smartGroup modification item. +type SmartGroupModificationProperties struct { + // Modification details + Modifications []*SmartGroupModificationItem `json:"modifications,omitempty"` + + // URL to fetch the next set of results. + NextLink *string `json:"nextLink,omitempty"` + + // READ-ONLY; Unique Id of the smartGroup for which the history is being retrieved + SmartGroupID *string `json:"smartGroupId,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type SmartGroupModificationProperties. +func (s SmartGroupModificationProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "modifications", s.Modifications) + populate(objectMap, "nextLink", s.NextLink) + populate(objectMap, "smartGroupId", s.SmartGroupID) + return json.Marshal(objectMap) +} + +// SmartGroupProperties - Properties of smart group. +type SmartGroupProperties struct { + // Summary of alertSeverities in the smart group + AlertSeverities []*SmartGroupAggregatedProperty `json:"alertSeverities,omitempty"` + + // Summary of alertStates in the smart group + AlertStates []*SmartGroupAggregatedProperty `json:"alertStates,omitempty"` + + // Total number of alerts in smart group + AlertsCount *int32 `json:"alertsCount,omitempty"` + + // Summary of monitorConditions in the smart group + MonitorConditions []*SmartGroupAggregatedProperty `json:"monitorConditions,omitempty"` + + // Summary of monitorServices in the smart group + MonitorServices []*SmartGroupAggregatedProperty `json:"monitorServices,omitempty"` + + // The URI to fetch the next page of alerts. Call ListNext() with this URI to fetch the next page alerts. + NextLink *string `json:"nextLink,omitempty"` + + // Summary of target resource groups in the smart group + ResourceGroups []*SmartGroupAggregatedProperty `json:"resourceGroups,omitempty"` + + // Summary of target resource types in the smart group + ResourceTypes []*SmartGroupAggregatedProperty `json:"resourceTypes,omitempty"` + + // Summary of target resources in the smart group + Resources []*SmartGroupAggregatedProperty `json:"resources,omitempty"` + + // READ-ONLY; Last updated time of smart group. Date-Time in ISO-8601 format. + LastModifiedDateTime *time.Time `json:"lastModifiedDateTime,omitempty" azure:"ro"` + + // READ-ONLY; Last modified by user name. + LastModifiedUserName *string `json:"lastModifiedUserName,omitempty" azure:"ro"` + + // READ-ONLY; Severity of smart group is the highest(Sev0 >… > Sev4) severity of all the alerts in the group. + Severity *Severity `json:"severity,omitempty" azure:"ro"` + + // READ-ONLY; Smart group state + SmartGroupState *State `json:"smartGroupState,omitempty" azure:"ro"` + + // READ-ONLY; Creation time of smart group. Date-Time in ISO-8601 format. + StartDateTime *time.Time `json:"startDateTime,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type SmartGroupProperties. +func (s SmartGroupProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "alertSeverities", s.AlertSeverities) + populate(objectMap, "alertStates", s.AlertStates) + populate(objectMap, "alertsCount", s.AlertsCount) + populate(objectMap, "lastModifiedDateTime", (*timeRFC3339)(s.LastModifiedDateTime)) + populate(objectMap, "lastModifiedUserName", s.LastModifiedUserName) + populate(objectMap, "monitorConditions", s.MonitorConditions) + populate(objectMap, "monitorServices", s.MonitorServices) + populate(objectMap, "nextLink", s.NextLink) + populate(objectMap, "resourceGroups", s.ResourceGroups) + populate(objectMap, "resourceTypes", s.ResourceTypes) + populate(objectMap, "resources", s.Resources) + populate(objectMap, "severity", s.Severity) + populate(objectMap, "smartGroupState", s.SmartGroupState) + populate(objectMap, "startDateTime", (*timeRFC3339)(s.StartDateTime)) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SmartGroupProperties. +func (s *SmartGroupProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "alertSeverities": + err = unpopulate(val, &s.AlertSeverities) + delete(rawMsg, key) + case "alertStates": + err = unpopulate(val, &s.AlertStates) + delete(rawMsg, key) + case "alertsCount": + err = unpopulate(val, &s.AlertsCount) + delete(rawMsg, key) + case "lastModifiedDateTime": + var aux timeRFC3339 + err = unpopulate(val, &aux) + s.LastModifiedDateTime = (*time.Time)(&aux) + delete(rawMsg, key) + case "lastModifiedUserName": + err = unpopulate(val, &s.LastModifiedUserName) + delete(rawMsg, key) + case "monitorConditions": + err = unpopulate(val, &s.MonitorConditions) + delete(rawMsg, key) + case "monitorServices": + err = unpopulate(val, &s.MonitorServices) + delete(rawMsg, key) + case "nextLink": + err = unpopulate(val, &s.NextLink) + delete(rawMsg, key) + case "resourceGroups": + err = unpopulate(val, &s.ResourceGroups) + delete(rawMsg, key) + case "resourceTypes": + err = unpopulate(val, &s.ResourceTypes) + delete(rawMsg, key) + case "resources": + err = unpopulate(val, &s.Resources) + delete(rawMsg, key) + case "severity": + err = unpopulate(val, &s.Severity) + delete(rawMsg, key) + case "smartGroupState": + err = unpopulate(val, &s.SmartGroupState) + delete(rawMsg, key) + case "startDateTime": + var aux timeRFC3339 + err = unpopulate(val, &aux) + s.StartDateTime = (*time.Time)(&aux) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// SmartGroupsChangeStateOptions contains the optional parameters for the SmartGroups.ChangeState method. +type SmartGroupsChangeStateOptions struct { + // placeholder for future optional parameters +} + +// SmartGroupsGetAllOptions contains the optional parameters for the SmartGroups.GetAll method. +type SmartGroupsGetAllOptions struct { + // Filter by monitor condition which is either 'Fired' or 'Resolved'. Default value is to select all. + MonitorCondition *MonitorCondition + // Filter by monitor service which generates the alert instance. Default value is select all. + MonitorService *MonitorService + // Determines number of alerts returned per page in response. Permissible value is between 1 to 250. When the "includeContent" filter is selected, maximum + // value allowed is 25. Default value is 25. + PageCount *int32 + // Filter by severity. Default value is select all. + Severity *Severity + // Filter by state of the smart group. Default value is to select all. + SmartGroupState *AlertState + // Sort the query results by input field. Default value is sort by 'lastModifiedDateTime'. + SortBy *SmartGroupsSortByFields + // Sort the query results order in either ascending or descending. Default value is 'desc' for time fields and 'asc' for others. + SortOrder *Enum11 + // Filter by target resource( which is full ARM ID) Default value is select all. + TargetResource *string + // Filter by target resource group name. Default value is select all. + TargetResourceGroup *string + // Filter by target resource type. Default value is select all. + TargetResourceType *string + // Filter by time range by below listed values. Default value is 1 day. + TimeRange *TimeRange +} + +// SmartGroupsGetByIDOptions contains the optional parameters for the SmartGroups.GetByID method. +type SmartGroupsGetByIDOptions struct { + // placeholder for future optional parameters +} + +// SmartGroupsGetHistoryOptions contains the optional parameters for the SmartGroups.GetHistory method. +type SmartGroupsGetHistoryOptions struct { + // placeholder for future optional parameters +} + +// SmartGroupsList - List the alerts. +type SmartGroupsList struct { + // URL to fetch the next set of alerts. + NextLink *string `json:"nextLink,omitempty"` + + // List of alerts + Value []*SmartGroup `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type SmartGroupsList. +func (s SmartGroupsList) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", s.NextLink) + populate(objectMap, "value", s.Value) + return json.Marshal(objectMap) +} + +// Suppression - Action rule with suppression configuration +type Suppression struct { + ActionRuleProperties + // REQUIRED; suppression configuration for the action rule + SuppressionConfig *SuppressionConfig `json:"suppressionConfig,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type Suppression. +func (s Suppression) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + s.ActionRuleProperties.marshalInternal(objectMap, ActionRuleTypeSuppression) + populate(objectMap, "suppressionConfig", s.SuppressionConfig) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Suppression. +func (s *Suppression) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "suppressionConfig": + err = unpopulate(val, &s.SuppressionConfig) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + if err := s.ActionRuleProperties.unmarshalInternal(rawMsg); err != nil { + return err + } + return nil +} + +// SuppressionConfig - Suppression logic for a given action rule +type SuppressionConfig struct { + // REQUIRED; Specifies when the suppression should be applied + RecurrenceType *SuppressionType `json:"recurrenceType,omitempty"` + + // suppression schedule configuration + Schedule *SuppressionSchedule `json:"schedule,omitempty"` +} + +// SuppressionSchedule - Schedule for a given suppression configuration. +type SuppressionSchedule struct { + // End date for suppression + EndDate *string `json:"endDate,omitempty"` + + // End date for suppression + EndTime *string `json:"endTime,omitempty"` + + // Specifies the values for recurrence pattern + RecurrenceValues []*int32 `json:"recurrenceValues,omitempty"` + + // Start date for suppression + StartDate *string `json:"startDate,omitempty"` + + // Start time for suppression + StartTime *string `json:"startTime,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type SuppressionSchedule. +func (s SuppressionSchedule) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "endDate", s.EndDate) + populate(objectMap, "endTime", s.EndTime) + populate(objectMap, "recurrenceValues", s.RecurrenceValues) + populate(objectMap, "startDate", s.StartDate) + populate(objectMap, "startTime", s.StartTime) + return json.Marshal(objectMap) +} + +// ThrottlingInformation - Optional throttling information for the alert rule. +type ThrottlingInformation struct { + // The required duration (in ISO8601 format) to wait before notifying on the alert rule again. The time granularity must be in minutes and minimum value + // is 0 minutes + Duration *string `json:"duration,omitempty"` +} + +func populate(m map[string]interface{}, k string, v interface{}) { + if v == nil { + return + } else if azcore.IsNullValue(v) { + m[k] = nil + } else if !reflect.ValueOf(v).IsNil() { + m[k] = v + } +} + +func unpopulate(data json.RawMessage, v interface{}) error { + if data == nil { + return nil + } + return json.Unmarshal(data, v) +} diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_operations_client.go b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_operations_client.go new file mode 100644 index 000000000000..b174c6953544 --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_operations_client.go @@ -0,0 +1,79 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armalertsmanagement + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" +) + +// OperationsClient contains the methods for the Operations group. +// Don't use this type directly, use NewOperationsClient() instead. +type OperationsClient struct { + ep string + pl runtime.Pipeline +} + +// NewOperationsClient creates a new instance of OperationsClient with the specified values. +func NewOperationsClient(con *arm.Connection) *OperationsClient { + return &OperationsClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version)} +} + +// List - List all operations available through Azure Alerts Management Resource Provider. +// If the operation fails it returns a generic error. +func (client *OperationsClient) List(options *OperationsListOptions) *OperationsListPager { + return &OperationsListPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listCreateRequest(ctx, options) + }, + advancer: func(ctx context.Context, resp OperationsListResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.OperationsList.NextLink) + }, + } +} + +// listCreateRequest creates the List request. +func (client *OperationsClient) listCreateRequest(ctx context.Context, options *OperationsListOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.AlertsManagement/operations" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-05-05-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listHandleResponse handles the List response. +func (client *OperationsClient) listHandleResponse(resp *http.Response) (OperationsListResponse, error) { + result := OperationsListResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.OperationsList); err != nil { + return OperationsListResponse{}, err + } + return result, nil +} + +// listHandleError handles the List error response. +func (client *OperationsClient) listHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + if len(body) == 0 { + return runtime.NewResponseError(errors.New(resp.Status), resp) + } + return runtime.NewResponseError(errors.New(string(body)), resp) +} diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_pagers.go b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_pagers.go new file mode 100644 index 000000000000..6309e2717af4 --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_pagers.go @@ -0,0 +1,395 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armalertsmanagement + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "reflect" +) + +// ActionRulesListByResourceGroupPager provides operations for iterating over paged responses. +type ActionRulesListByResourceGroupPager struct { + client *ActionRulesClient + current ActionRulesListByResourceGroupResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, ActionRulesListByResourceGroupResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *ActionRulesListByResourceGroupPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *ActionRulesListByResourceGroupPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ActionRulesList.NextLink == nil || len(*p.current.ActionRulesList.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listByResourceGroupHandleError(resp) + return false + } + result, err := p.client.listByResourceGroupHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current ActionRulesListByResourceGroupResponse page. +func (p *ActionRulesListByResourceGroupPager) PageResponse() ActionRulesListByResourceGroupResponse { + return p.current +} + +// ActionRulesListBySubscriptionPager provides operations for iterating over paged responses. +type ActionRulesListBySubscriptionPager struct { + client *ActionRulesClient + current ActionRulesListBySubscriptionResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, ActionRulesListBySubscriptionResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *ActionRulesListBySubscriptionPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *ActionRulesListBySubscriptionPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ActionRulesList.NextLink == nil || len(*p.current.ActionRulesList.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listBySubscriptionHandleError(resp) + return false + } + result, err := p.client.listBySubscriptionHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current ActionRulesListBySubscriptionResponse page. +func (p *ActionRulesListBySubscriptionPager) PageResponse() ActionRulesListBySubscriptionResponse { + return p.current +} + +// AlertsGetAllPager provides operations for iterating over paged responses. +type AlertsGetAllPager struct { + client *AlertsClient + current AlertsGetAllResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, AlertsGetAllResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *AlertsGetAllPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *AlertsGetAllPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.AlertsList.NextLink == nil || len(*p.current.AlertsList.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.getAllHandleError(resp) + return false + } + result, err := p.client.getAllHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current AlertsGetAllResponse page. +func (p *AlertsGetAllPager) PageResponse() AlertsGetAllResponse { + return p.current +} + +// OperationsListPager provides operations for iterating over paged responses. +type OperationsListPager struct { + client *OperationsClient + current OperationsListResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, OperationsListResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *OperationsListPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *OperationsListPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.OperationsList.NextLink == nil || len(*p.current.OperationsList.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listHandleError(resp) + return false + } + result, err := p.client.listHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current OperationsListResponse page. +func (p *OperationsListPager) PageResponse() OperationsListResponse { + return p.current +} + +// SmartDetectorAlertRulesListByResourceGroupPager provides operations for iterating over paged responses. +type SmartDetectorAlertRulesListByResourceGroupPager struct { + client *SmartDetectorAlertRulesClient + current SmartDetectorAlertRulesListByResourceGroupResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, SmartDetectorAlertRulesListByResourceGroupResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *SmartDetectorAlertRulesListByResourceGroupPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *SmartDetectorAlertRulesListByResourceGroupPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.AlertRulesList.NextLink == nil || len(*p.current.AlertRulesList.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listByResourceGroupHandleError(resp) + return false + } + result, err := p.client.listByResourceGroupHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current SmartDetectorAlertRulesListByResourceGroupResponse page. +func (p *SmartDetectorAlertRulesListByResourceGroupPager) PageResponse() SmartDetectorAlertRulesListByResourceGroupResponse { + return p.current +} + +// SmartDetectorAlertRulesListPager provides operations for iterating over paged responses. +type SmartDetectorAlertRulesListPager struct { + client *SmartDetectorAlertRulesClient + current SmartDetectorAlertRulesListResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, SmartDetectorAlertRulesListResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *SmartDetectorAlertRulesListPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *SmartDetectorAlertRulesListPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.AlertRulesList.NextLink == nil || len(*p.current.AlertRulesList.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listHandleError(resp) + return false + } + result, err := p.client.listHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current SmartDetectorAlertRulesListResponse page. +func (p *SmartDetectorAlertRulesListPager) PageResponse() SmartDetectorAlertRulesListResponse { + return p.current +} + +// SmartGroupsGetAllPager provides operations for iterating over paged responses. +type SmartGroupsGetAllPager struct { + client *SmartGroupsClient + current SmartGroupsGetAllResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, SmartGroupsGetAllResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *SmartGroupsGetAllPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *SmartGroupsGetAllPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.SmartGroupsList.NextLink == nil || len(*p.current.SmartGroupsList.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.getAllHandleError(resp) + return false + } + result, err := p.client.getAllHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current SmartGroupsGetAllResponse page. +func (p *SmartGroupsGetAllPager) PageResponse() SmartGroupsGetAllResponse { + return p.current +} diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_polymorphic_helpers.go b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_polymorphic_helpers.go new file mode 100644 index 000000000000..81bb2bb70b28 --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_polymorphic_helpers.go @@ -0,0 +1,89 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armalertsmanagement + +import "encoding/json" + +func unmarshalActionRulePropertiesClassification(rawMsg json.RawMessage) (ActionRulePropertiesClassification, error) { + if rawMsg == nil { + return nil, nil + } + var m map[string]interface{} + if err := json.Unmarshal(rawMsg, &m); err != nil { + return nil, err + } + var b ActionRulePropertiesClassification + switch m["type"] { + case string(ActionRuleTypeActionGroup): + b = &ActionGroup{} + case string(ActionRuleTypeDiagnostics): + b = &Diagnostics{} + case string(ActionRuleTypeSuppression): + b = &Suppression{} + default: + b = &ActionRuleProperties{} + } + return b, json.Unmarshal(rawMsg, b) +} + +func unmarshalActionRulePropertiesClassificationArray(rawMsg json.RawMessage) ([]ActionRulePropertiesClassification, error) { + if rawMsg == nil { + return nil, nil + } + var rawMessages []json.RawMessage + if err := json.Unmarshal(rawMsg, &rawMessages); err != nil { + return nil, err + } + fArray := make([]ActionRulePropertiesClassification, len(rawMessages)) + for index, rawMessage := range rawMessages { + f, err := unmarshalActionRulePropertiesClassification(rawMessage) + if err != nil { + return nil, err + } + fArray[index] = f + } + return fArray, nil +} + +func unmarshalAlertsMetaDataPropertiesClassification(rawMsg json.RawMessage) (AlertsMetaDataPropertiesClassification, error) { + if rawMsg == nil { + return nil, nil + } + var m map[string]interface{} + if err := json.Unmarshal(rawMsg, &m); err != nil { + return nil, err + } + var b AlertsMetaDataPropertiesClassification + switch m["metadataIdentifier"] { + case string(MetadataIdentifierMonitorServiceList): + b = &MonitorServiceList{} + default: + b = &AlertsMetaDataProperties{} + } + return b, json.Unmarshal(rawMsg, b) +} + +func unmarshalAlertsMetaDataPropertiesClassificationArray(rawMsg json.RawMessage) ([]AlertsMetaDataPropertiesClassification, error) { + if rawMsg == nil { + return nil, nil + } + var rawMessages []json.RawMessage + if err := json.Unmarshal(rawMsg, &rawMessages); err != nil { + return nil, err + } + fArray := make([]AlertsMetaDataPropertiesClassification, len(rawMessages)) + for index, rawMessage := range rawMessages { + f, err := unmarshalAlertsMetaDataPropertiesClassification(rawMessage) + if err != nil { + return nil, err + } + fArray[index] = f + } + return fArray, nil +} diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_response_types.go b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_response_types.go new file mode 100644 index 000000000000..4d7003de37e1 --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_response_types.go @@ -0,0 +1,298 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armalertsmanagement + +import "net/http" + +// ActionRulesCreateUpdateResponse contains the response from method ActionRules.CreateUpdate. +type ActionRulesCreateUpdateResponse struct { + ActionRulesCreateUpdateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ActionRulesCreateUpdateResult contains the result from method ActionRules.CreateUpdate. +type ActionRulesCreateUpdateResult struct { + ActionRule + // XMSRequestID contains the information returned from the x-ms-request-id header response. + XMSRequestID *string +} + +// ActionRulesDeleteResponse contains the response from method ActionRules.Delete. +type ActionRulesDeleteResponse struct { + ActionRulesDeleteResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ActionRulesDeleteResult contains the result from method ActionRules.Delete. +type ActionRulesDeleteResult struct { + Value *bool + + // XMSRequestID contains the information returned from the x-ms-request-id header response. + XMSRequestID *string +} + +// ActionRulesGetByNameResponse contains the response from method ActionRules.GetByName. +type ActionRulesGetByNameResponse struct { + ActionRulesGetByNameResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ActionRulesGetByNameResult contains the result from method ActionRules.GetByName. +type ActionRulesGetByNameResult struct { + ActionRule + // XMSRequestID contains the information returned from the x-ms-request-id header response. + XMSRequestID *string +} + +// ActionRulesListByResourceGroupResponse contains the response from method ActionRules.ListByResourceGroup. +type ActionRulesListByResourceGroupResponse struct { + ActionRulesListByResourceGroupResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ActionRulesListByResourceGroupResult contains the result from method ActionRules.ListByResourceGroup. +type ActionRulesListByResourceGroupResult struct { + ActionRulesList + // XMSRequestID contains the information returned from the x-ms-request-id header response. + XMSRequestID *string +} + +// ActionRulesListBySubscriptionResponse contains the response from method ActionRules.ListBySubscription. +type ActionRulesListBySubscriptionResponse struct { + ActionRulesListBySubscriptionResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ActionRulesListBySubscriptionResult contains the result from method ActionRules.ListBySubscription. +type ActionRulesListBySubscriptionResult struct { + ActionRulesList + // XMSRequestID contains the information returned from the x-ms-request-id header response. + XMSRequestID *string +} + +// ActionRulesUpdateResponse contains the response from method ActionRules.Update. +type ActionRulesUpdateResponse struct { + ActionRulesUpdateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ActionRulesUpdateResult contains the result from method ActionRules.Update. +type ActionRulesUpdateResult struct { + ActionRule + // XMSRequestID contains the information returned from the x-ms-request-id header response. + XMSRequestID *string +} + +// AlertsChangeStateResponse contains the response from method Alerts.ChangeState. +type AlertsChangeStateResponse struct { + AlertsChangeStateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// AlertsChangeStateResult contains the result from method Alerts.ChangeState. +type AlertsChangeStateResult struct { + Alert +} + +// AlertsGetAllResponse contains the response from method Alerts.GetAll. +type AlertsGetAllResponse struct { + AlertsGetAllResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// AlertsGetAllResult contains the result from method Alerts.GetAll. +type AlertsGetAllResult struct { + AlertsList +} + +// AlertsGetByIDResponse contains the response from method Alerts.GetByID. +type AlertsGetByIDResponse struct { + AlertsGetByIDResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// AlertsGetByIDResult contains the result from method Alerts.GetByID. +type AlertsGetByIDResult struct { + Alert +} + +// AlertsGetHistoryResponse contains the response from method Alerts.GetHistory. +type AlertsGetHistoryResponse struct { + AlertsGetHistoryResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// AlertsGetHistoryResult contains the result from method Alerts.GetHistory. +type AlertsGetHistoryResult struct { + AlertModification +} + +// AlertsGetSummaryResponse contains the response from method Alerts.GetSummary. +type AlertsGetSummaryResponse struct { + AlertsGetSummaryResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// AlertsGetSummaryResult contains the result from method Alerts.GetSummary. +type AlertsGetSummaryResult struct { + AlertsSummary +} + +// AlertsMetaDataResponse contains the response from method Alerts.MetaData. +type AlertsMetaDataResponse struct { + AlertsMetaDataResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// AlertsMetaDataResult contains the result from method Alerts.MetaData. +type AlertsMetaDataResult struct { + AlertsMetaData +} + +// OperationsListResponse contains the response from method Operations.List. +type OperationsListResponse struct { + OperationsListResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// OperationsListResult contains the result from method Operations.List. +type OperationsListResult struct { + OperationsList +} + +// SmartDetectorAlertRulesCreateOrUpdateResponse contains the response from method SmartDetectorAlertRules.CreateOrUpdate. +type SmartDetectorAlertRulesCreateOrUpdateResponse struct { + SmartDetectorAlertRulesCreateOrUpdateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SmartDetectorAlertRulesCreateOrUpdateResult contains the result from method SmartDetectorAlertRules.CreateOrUpdate. +type SmartDetectorAlertRulesCreateOrUpdateResult struct { + AlertRule +} + +// SmartDetectorAlertRulesDeleteResponse contains the response from method SmartDetectorAlertRules.Delete. +type SmartDetectorAlertRulesDeleteResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SmartDetectorAlertRulesGetResponse contains the response from method SmartDetectorAlertRules.Get. +type SmartDetectorAlertRulesGetResponse struct { + SmartDetectorAlertRulesGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SmartDetectorAlertRulesGetResult contains the result from method SmartDetectorAlertRules.Get. +type SmartDetectorAlertRulesGetResult struct { + AlertRule +} + +// SmartDetectorAlertRulesListByResourceGroupResponse contains the response from method SmartDetectorAlertRules.ListByResourceGroup. +type SmartDetectorAlertRulesListByResourceGroupResponse struct { + SmartDetectorAlertRulesListByResourceGroupResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SmartDetectorAlertRulesListByResourceGroupResult contains the result from method SmartDetectorAlertRules.ListByResourceGroup. +type SmartDetectorAlertRulesListByResourceGroupResult struct { + AlertRulesList +} + +// SmartDetectorAlertRulesListResponse contains the response from method SmartDetectorAlertRules.List. +type SmartDetectorAlertRulesListResponse struct { + SmartDetectorAlertRulesListResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SmartDetectorAlertRulesListResult contains the result from method SmartDetectorAlertRules.List. +type SmartDetectorAlertRulesListResult struct { + AlertRulesList +} + +// SmartDetectorAlertRulesPatchResponse contains the response from method SmartDetectorAlertRules.Patch. +type SmartDetectorAlertRulesPatchResponse struct { + SmartDetectorAlertRulesPatchResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SmartDetectorAlertRulesPatchResult contains the result from method SmartDetectorAlertRules.Patch. +type SmartDetectorAlertRulesPatchResult struct { + AlertRule +} + +// SmartGroupsChangeStateResponse contains the response from method SmartGroups.ChangeState. +type SmartGroupsChangeStateResponse struct { + SmartGroupsChangeStateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SmartGroupsChangeStateResult contains the result from method SmartGroups.ChangeState. +type SmartGroupsChangeStateResult struct { + SmartGroup + // XMSRequestID contains the information returned from the x-ms-request-id header response. + XMSRequestID *string +} + +// SmartGroupsGetAllResponse contains the response from method SmartGroups.GetAll. +type SmartGroupsGetAllResponse struct { + SmartGroupsGetAllResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SmartGroupsGetAllResult contains the result from method SmartGroups.GetAll. +type SmartGroupsGetAllResult struct { + SmartGroupsList +} + +// SmartGroupsGetByIDResponse contains the response from method SmartGroups.GetByID. +type SmartGroupsGetByIDResponse struct { + SmartGroupsGetByIDResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SmartGroupsGetByIDResult contains the result from method SmartGroups.GetByID. +type SmartGroupsGetByIDResult struct { + SmartGroup + // XMSRequestID contains the information returned from the x-ms-request-id header response. + XMSRequestID *string +} + +// SmartGroupsGetHistoryResponse contains the response from method SmartGroups.GetHistory. +type SmartGroupsGetHistoryResponse struct { + SmartGroupsGetHistoryResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SmartGroupsGetHistoryResult contains the result from method SmartGroups.GetHistory. +type SmartGroupsGetHistoryResult struct { + SmartGroupModification +} diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_smartdetectoralertrules_client.go b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_smartdetectoralertrules_client.go new file mode 100644 index 000000000000..80adf65b2601 --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_smartdetectoralertrules_client.go @@ -0,0 +1,407 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armalertsmanagement + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strconv" + "strings" +) + +// SmartDetectorAlertRulesClient contains the methods for the SmartDetectorAlertRules group. +// Don't use this type directly, use NewSmartDetectorAlertRulesClient() instead. +type SmartDetectorAlertRulesClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewSmartDetectorAlertRulesClient creates a new instance of SmartDetectorAlertRulesClient with the specified values. +func NewSmartDetectorAlertRulesClient(con *arm.Connection, subscriptionID string) *SmartDetectorAlertRulesClient { + return &SmartDetectorAlertRulesClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version), subscriptionID: subscriptionID} +} + +// CreateOrUpdate - Create or update a Smart Detector alert rule. +// If the operation fails it returns the *SmartDetectorErrorResponse error type. +func (client *SmartDetectorAlertRulesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, alertRuleName string, parameters AlertRule, options *SmartDetectorAlertRulesCreateOrUpdateOptions) (SmartDetectorAlertRulesCreateOrUpdateResponse, error) { + req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, alertRuleName, parameters, options) + if err != nil { + return SmartDetectorAlertRulesCreateOrUpdateResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return SmartDetectorAlertRulesCreateOrUpdateResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { + return SmartDetectorAlertRulesCreateOrUpdateResponse{}, client.createOrUpdateHandleError(resp) + } + return client.createOrUpdateHandleResponse(resp) +} + +// createOrUpdateCreateRequest creates the CreateOrUpdate request. +func (client *SmartDetectorAlertRulesClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, alertRuleName string, parameters AlertRule, options *SmartDetectorAlertRulesCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.alertsManagement/smartDetectorAlertRules/{alertRuleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if alertRuleName == "" { + return nil, errors.New("parameter alertRuleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{alertRuleName}", url.PathEscape(alertRuleName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-06-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// createOrUpdateHandleResponse handles the CreateOrUpdate response. +func (client *SmartDetectorAlertRulesClient) createOrUpdateHandleResponse(resp *http.Response) (SmartDetectorAlertRulesCreateOrUpdateResponse, error) { + result := SmartDetectorAlertRulesCreateOrUpdateResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.AlertRule); err != nil { + return SmartDetectorAlertRulesCreateOrUpdateResponse{}, err + } + return result, nil +} + +// createOrUpdateHandleError handles the CreateOrUpdate error response. +func (client *SmartDetectorAlertRulesClient) createOrUpdateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := SmartDetectorErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Delete - Delete an existing Smart Detector alert rule. +// If the operation fails it returns the *SmartDetectorErrorResponse error type. +func (client *SmartDetectorAlertRulesClient) Delete(ctx context.Context, resourceGroupName string, alertRuleName string, options *SmartDetectorAlertRulesDeleteOptions) (SmartDetectorAlertRulesDeleteResponse, error) { + req, err := client.deleteCreateRequest(ctx, resourceGroupName, alertRuleName, options) + if err != nil { + return SmartDetectorAlertRulesDeleteResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return SmartDetectorAlertRulesDeleteResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { + return SmartDetectorAlertRulesDeleteResponse{}, client.deleteHandleError(resp) + } + return SmartDetectorAlertRulesDeleteResponse{RawResponse: resp}, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *SmartDetectorAlertRulesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, alertRuleName string, options *SmartDetectorAlertRulesDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.alertsManagement/smartDetectorAlertRules/{alertRuleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if alertRuleName == "" { + return nil, errors.New("parameter alertRuleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{alertRuleName}", url.PathEscape(alertRuleName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-06-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// deleteHandleError handles the Delete error response. +func (client *SmartDetectorAlertRulesClient) deleteHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := SmartDetectorErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Get - Get a specific Smart Detector alert rule. +// If the operation fails it returns the *SmartDetectorErrorResponse error type. +func (client *SmartDetectorAlertRulesClient) Get(ctx context.Context, resourceGroupName string, alertRuleName string, options *SmartDetectorAlertRulesGetOptions) (SmartDetectorAlertRulesGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, alertRuleName, options) + if err != nil { + return SmartDetectorAlertRulesGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return SmartDetectorAlertRulesGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return SmartDetectorAlertRulesGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *SmartDetectorAlertRulesClient) getCreateRequest(ctx context.Context, resourceGroupName string, alertRuleName string, options *SmartDetectorAlertRulesGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.alertsManagement/smartDetectorAlertRules/{alertRuleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if alertRuleName == "" { + return nil, errors.New("parameter alertRuleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{alertRuleName}", url.PathEscape(alertRuleName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-06-01") + if options != nil && options.ExpandDetector != nil { + reqQP.Set("expandDetector", strconv.FormatBool(*options.ExpandDetector)) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *SmartDetectorAlertRulesClient) getHandleResponse(resp *http.Response) (SmartDetectorAlertRulesGetResponse, error) { + result := SmartDetectorAlertRulesGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.AlertRule); err != nil { + return SmartDetectorAlertRulesGetResponse{}, err + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *SmartDetectorAlertRulesClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := SmartDetectorErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// List - List all the existing Smart Detector alert rules within the subscription. +// If the operation fails it returns the *SmartDetectorErrorResponse error type. +func (client *SmartDetectorAlertRulesClient) List(options *SmartDetectorAlertRulesListOptions) *SmartDetectorAlertRulesListPager { + return &SmartDetectorAlertRulesListPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listCreateRequest(ctx, options) + }, + advancer: func(ctx context.Context, resp SmartDetectorAlertRulesListResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.AlertRulesList.NextLink) + }, + } +} + +// listCreateRequest creates the List request. +func (client *SmartDetectorAlertRulesClient) listCreateRequest(ctx context.Context, options *SmartDetectorAlertRulesListOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/microsoft.alertsManagement/smartDetectorAlertRules" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-06-01") + if options != nil && options.ExpandDetector != nil { + reqQP.Set("expandDetector", strconv.FormatBool(*options.ExpandDetector)) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listHandleResponse handles the List response. +func (client *SmartDetectorAlertRulesClient) listHandleResponse(resp *http.Response) (SmartDetectorAlertRulesListResponse, error) { + result := SmartDetectorAlertRulesListResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.AlertRulesList); err != nil { + return SmartDetectorAlertRulesListResponse{}, err + } + return result, nil +} + +// listHandleError handles the List error response. +func (client *SmartDetectorAlertRulesClient) listHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := SmartDetectorErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// ListByResourceGroup - List all the existing Smart Detector alert rules within the subscription and resource group. +// If the operation fails it returns the *SmartDetectorErrorResponse error type. +func (client *SmartDetectorAlertRulesClient) ListByResourceGroup(resourceGroupName string, options *SmartDetectorAlertRulesListByResourceGroupOptions) *SmartDetectorAlertRulesListByResourceGroupPager { + return &SmartDetectorAlertRulesListByResourceGroupPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) + }, + advancer: func(ctx context.Context, resp SmartDetectorAlertRulesListByResourceGroupResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.AlertRulesList.NextLink) + }, + } +} + +// listByResourceGroupCreateRequest creates the ListByResourceGroup request. +func (client *SmartDetectorAlertRulesClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, options *SmartDetectorAlertRulesListByResourceGroupOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.alertsManagement/smartDetectorAlertRules" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-06-01") + if options != nil && options.ExpandDetector != nil { + reqQP.Set("expandDetector", strconv.FormatBool(*options.ExpandDetector)) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listByResourceGroupHandleResponse handles the ListByResourceGroup response. +func (client *SmartDetectorAlertRulesClient) listByResourceGroupHandleResponse(resp *http.Response) (SmartDetectorAlertRulesListByResourceGroupResponse, error) { + result := SmartDetectorAlertRulesListByResourceGroupResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.AlertRulesList); err != nil { + return SmartDetectorAlertRulesListByResourceGroupResponse{}, err + } + return result, nil +} + +// listByResourceGroupHandleError handles the ListByResourceGroup error response. +func (client *SmartDetectorAlertRulesClient) listByResourceGroupHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := SmartDetectorErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Patch - Patch a specific Smart Detector alert rule. +// If the operation fails it returns the *SmartDetectorErrorResponse error type. +func (client *SmartDetectorAlertRulesClient) Patch(ctx context.Context, resourceGroupName string, alertRuleName string, parameters AlertRulePatchObject, options *SmartDetectorAlertRulesPatchOptions) (SmartDetectorAlertRulesPatchResponse, error) { + req, err := client.patchCreateRequest(ctx, resourceGroupName, alertRuleName, parameters, options) + if err != nil { + return SmartDetectorAlertRulesPatchResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return SmartDetectorAlertRulesPatchResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return SmartDetectorAlertRulesPatchResponse{}, client.patchHandleError(resp) + } + return client.patchHandleResponse(resp) +} + +// patchCreateRequest creates the Patch request. +func (client *SmartDetectorAlertRulesClient) patchCreateRequest(ctx context.Context, resourceGroupName string, alertRuleName string, parameters AlertRulePatchObject, options *SmartDetectorAlertRulesPatchOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.alertsManagement/smartDetectorAlertRules/{alertRuleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if alertRuleName == "" { + return nil, errors.New("parameter alertRuleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{alertRuleName}", url.PathEscape(alertRuleName)) + req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-06-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// patchHandleResponse handles the Patch response. +func (client *SmartDetectorAlertRulesClient) patchHandleResponse(resp *http.Response) (SmartDetectorAlertRulesPatchResponse, error) { + result := SmartDetectorAlertRulesPatchResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.AlertRule); err != nil { + return SmartDetectorAlertRulesPatchResponse{}, err + } + return result, nil +} + +// patchHandleError handles the Patch error response. +func (client *SmartDetectorAlertRulesClient) patchHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := SmartDetectorErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_smartgroups_client.go b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_smartgroups_client.go new file mode 100644 index 000000000000..7aaab19c07dd --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_smartgroups_client.go @@ -0,0 +1,312 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armalertsmanagement + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strconv" + "strings" +) + +// SmartGroupsClient contains the methods for the SmartGroups group. +// Don't use this type directly, use NewSmartGroupsClient() instead. +type SmartGroupsClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewSmartGroupsClient creates a new instance of SmartGroupsClient with the specified values. +func NewSmartGroupsClient(con *arm.Connection, subscriptionID string) *SmartGroupsClient { + return &SmartGroupsClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version), subscriptionID: subscriptionID} +} + +// ChangeState - Change the state of a Smart Group. +// If the operation fails it returns the *ErrorResponseAutoGenerated2 error type. +func (client *SmartGroupsClient) ChangeState(ctx context.Context, smartGroupID string, newState AlertState, options *SmartGroupsChangeStateOptions) (SmartGroupsChangeStateResponse, error) { + req, err := client.changeStateCreateRequest(ctx, smartGroupID, newState, options) + if err != nil { + return SmartGroupsChangeStateResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return SmartGroupsChangeStateResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return SmartGroupsChangeStateResponse{}, client.changeStateHandleError(resp) + } + return client.changeStateHandleResponse(resp) +} + +// changeStateCreateRequest creates the ChangeState request. +func (client *SmartGroupsClient) changeStateCreateRequest(ctx context.Context, smartGroupID string, newState AlertState, options *SmartGroupsChangeStateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/smartGroups/{smartGroupId}/changeState" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if smartGroupID == "" { + return nil, errors.New("parameter smartGroupID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{smartGroupId}", url.PathEscape(smartGroupID)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-05-05-preview") + reqQP.Set("newState", string(newState)) + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// changeStateHandleResponse handles the ChangeState response. +func (client *SmartGroupsClient) changeStateHandleResponse(resp *http.Response) (SmartGroupsChangeStateResponse, error) { + result := SmartGroupsChangeStateResponse{RawResponse: resp} + if val := resp.Header.Get("x-ms-request-id"); val != "" { + result.XMSRequestID = &val + } + if err := runtime.UnmarshalAsJSON(resp, &result.SmartGroup); err != nil { + return SmartGroupsChangeStateResponse{}, err + } + return result, nil +} + +// changeStateHandleError handles the ChangeState error response. +func (client *SmartGroupsClient) changeStateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseAutoGenerated2{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// GetAll - List all the Smart Groups within a specified subscription. +// If the operation fails it returns the *ErrorResponseAutoGenerated2 error type. +func (client *SmartGroupsClient) GetAll(options *SmartGroupsGetAllOptions) *SmartGroupsGetAllPager { + return &SmartGroupsGetAllPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.getAllCreateRequest(ctx, options) + }, + advancer: func(ctx context.Context, resp SmartGroupsGetAllResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.SmartGroupsList.NextLink) + }, + } +} + +// getAllCreateRequest creates the GetAll request. +func (client *SmartGroupsClient) getAllCreateRequest(ctx context.Context, options *SmartGroupsGetAllOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/smartGroups" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + if options != nil && options.TargetResource != nil { + reqQP.Set("targetResource", *options.TargetResource) + } + if options != nil && options.TargetResourceGroup != nil { + reqQP.Set("targetResourceGroup", *options.TargetResourceGroup) + } + if options != nil && options.TargetResourceType != nil { + reqQP.Set("targetResourceType", *options.TargetResourceType) + } + if options != nil && options.MonitorService != nil { + reqQP.Set("monitorService", string(*options.MonitorService)) + } + if options != nil && options.MonitorCondition != nil { + reqQP.Set("monitorCondition", string(*options.MonitorCondition)) + } + if options != nil && options.Severity != nil { + reqQP.Set("severity", string(*options.Severity)) + } + if options != nil && options.SmartGroupState != nil { + reqQP.Set("smartGroupState", string(*options.SmartGroupState)) + } + if options != nil && options.TimeRange != nil { + reqQP.Set("timeRange", string(*options.TimeRange)) + } + if options != nil && options.PageCount != nil { + reqQP.Set("pageCount", strconv.FormatInt(int64(*options.PageCount), 10)) + } + if options != nil && options.SortBy != nil { + reqQP.Set("sortBy", string(*options.SortBy)) + } + if options != nil && options.SortOrder != nil { + reqQP.Set("sortOrder", string(*options.SortOrder)) + } + reqQP.Set("api-version", "2019-05-05-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getAllHandleResponse handles the GetAll response. +func (client *SmartGroupsClient) getAllHandleResponse(resp *http.Response) (SmartGroupsGetAllResponse, error) { + result := SmartGroupsGetAllResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.SmartGroupsList); err != nil { + return SmartGroupsGetAllResponse{}, err + } + return result, nil +} + +// getAllHandleError handles the GetAll error response. +func (client *SmartGroupsClient) getAllHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseAutoGenerated2{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// GetByID - Get information related to a specific Smart Group. +// If the operation fails it returns the *ErrorResponseAutoGenerated2 error type. +func (client *SmartGroupsClient) GetByID(ctx context.Context, smartGroupID string, options *SmartGroupsGetByIDOptions) (SmartGroupsGetByIDResponse, error) { + req, err := client.getByIDCreateRequest(ctx, smartGroupID, options) + if err != nil { + return SmartGroupsGetByIDResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return SmartGroupsGetByIDResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return SmartGroupsGetByIDResponse{}, client.getByIDHandleError(resp) + } + return client.getByIDHandleResponse(resp) +} + +// getByIDCreateRequest creates the GetByID request. +func (client *SmartGroupsClient) getByIDCreateRequest(ctx context.Context, smartGroupID string, options *SmartGroupsGetByIDOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/smartGroups/{smartGroupId}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if smartGroupID == "" { + return nil, errors.New("parameter smartGroupID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{smartGroupId}", url.PathEscape(smartGroupID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-05-05-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getByIDHandleResponse handles the GetByID response. +func (client *SmartGroupsClient) getByIDHandleResponse(resp *http.Response) (SmartGroupsGetByIDResponse, error) { + result := SmartGroupsGetByIDResponse{RawResponse: resp} + if val := resp.Header.Get("x-ms-request-id"); val != "" { + result.XMSRequestID = &val + } + if err := runtime.UnmarshalAsJSON(resp, &result.SmartGroup); err != nil { + return SmartGroupsGetByIDResponse{}, err + } + return result, nil +} + +// getByIDHandleError handles the GetByID error response. +func (client *SmartGroupsClient) getByIDHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseAutoGenerated2{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// GetHistory - Get the history a smart group, which captures any Smart Group state changes (New/Acknowledged/Closed) . +// If the operation fails it returns the *ErrorResponseAutoGenerated2 error type. +func (client *SmartGroupsClient) GetHistory(ctx context.Context, smartGroupID string, options *SmartGroupsGetHistoryOptions) (SmartGroupsGetHistoryResponse, error) { + req, err := client.getHistoryCreateRequest(ctx, smartGroupID, options) + if err != nil { + return SmartGroupsGetHistoryResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return SmartGroupsGetHistoryResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return SmartGroupsGetHistoryResponse{}, client.getHistoryHandleError(resp) + } + return client.getHistoryHandleResponse(resp) +} + +// getHistoryCreateRequest creates the GetHistory request. +func (client *SmartGroupsClient) getHistoryCreateRequest(ctx context.Context, smartGroupID string, options *SmartGroupsGetHistoryOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/smartGroups/{smartGroupId}/history" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if smartGroupID == "" { + return nil, errors.New("parameter smartGroupID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{smartGroupId}", url.PathEscape(smartGroupID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2019-05-05-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHistoryHandleResponse handles the GetHistory response. +func (client *SmartGroupsClient) getHistoryHandleResponse(resp *http.Response) (SmartGroupsGetHistoryResponse, error) { + result := SmartGroupsGetHistoryResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.SmartGroupModification); err != nil { + return SmartGroupsGetHistoryResponse{}, err + } + return result, nil +} + +// getHistoryHandleError handles the GetHistory error response. +func (client *SmartGroupsClient) getHistoryHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseAutoGenerated2{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_time_rfc3339.go b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_time_rfc3339.go new file mode 100644 index 000000000000..d14c88c6147b --- /dev/null +++ b/sdk/resourcemanager/alertsmanagement/armalertsmanagement/zz_generated_time_rfc3339.go @@ -0,0 +1,58 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armalertsmanagement + +import ( + "regexp" + "strings" + "time" +) + +const ( + utcLayoutJSON = `"2006-01-02T15:04:05.999999999"` + utcLayout = "2006-01-02T15:04:05.999999999" + rfc3339JSON = `"` + time.RFC3339Nano + `"` +) + +// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. +var tzOffsetRegex = regexp.MustCompile(`(Z|z|\+|-)(\d+:\d+)*"*$`) + +type timeRFC3339 time.Time + +func (t timeRFC3339) MarshalJSON() (json []byte, err error) { + tt := time.Time(t) + return tt.MarshalJSON() +} + +func (t timeRFC3339) MarshalText() (text []byte, err error) { + tt := time.Time(t) + return tt.MarshalText() +} + +func (t *timeRFC3339) UnmarshalJSON(data []byte) error { + layout := utcLayoutJSON + if tzOffsetRegex.Match(data) { + layout = rfc3339JSON + } + return t.Parse(layout, string(data)) +} + +func (t *timeRFC3339) UnmarshalText(data []byte) (err error) { + layout := utcLayout + if tzOffsetRegex.Match(data) { + layout = time.RFC3339Nano + } + return t.Parse(layout, string(data)) +} + +func (t *timeRFC3339) Parse(layout, value string) error { + p, err := time.Parse(layout, strings.ToUpper(value)) + *t = timeRFC3339(p) + return err +}