Skip to content

[PS] migrate ActivityLogAlert module to autorest v4 #28024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Monitor/ActivityLogAlert.Autorest/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the ""License"");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an ""AS IS"" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
// is regenerated.

using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: System.Reflection.AssemblyCompanyAttribute("Microsoft")]
[assembly: System.Reflection.AssemblyCopyrightAttribute("Copyright © Microsoft")]
[assembly: System.Reflection.AssemblyProductAttribute("Microsoft Azure PowerShell")]
[assembly: System.Reflection.AssemblyTitleAttribute("Microsoft Azure PowerShell - ActivityLogAlert")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("6.0.2")]
[assembly: System.Reflection.AssemblyVersionAttribute("6.0.2")]
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]
[assembly: System.CLSCompliantAttribute(false)]


16 changes: 3 additions & 13 deletions src/Monitor/ActivityLogAlert.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ title: ActivityLogAlert
module-version: 0.1.0
subject-prefix: ActivityLogAlert
namespace: Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert
resourcegroup-append: true
nested-object-to-string: true

# If there are post APIs for some kinds of actions in the RP, you may need to
# uncomment following line to support viaIdentity for these post APIs
# identity-correction-for-post: true

# For new modules, please avoid setting 3.x using the use-extension method and instead, use 4.x as the default option
use-extension:
"@autorest/powershell": "3.x"

directive:
# Following is two common directive which are normally required in all the RPs
Expand Down Expand Up @@ -85,7 +75,7 @@ directive:
subject-prefix: ""

- model-cmdlet:
- AlertRuleAnyOfOrLeafCondition
- AlertRuleLeafCondition
- ActionGroup
- model-name: AlertRuleAnyOfOrLeafCondition
- model-name: AlertRuleLeafCondition
- model-name: ActionGroup
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ Create a new Activity Log Alert rule or update an existing one.
.Description
Create a new Activity Log Alert rule or update an existing one.
.Example
{{ Add code here }}
.Example
{{ Add code here }}
$scope = "/subscriptions/"+(Get-AzContext).Subscription.ID
$actiongroup=New-AzActivityLogAlertActionGroupObject -Id $ActionGroupResourceId -WebhookProperty @{"sampleWebhookProperty"="SamplePropertyValue"}
$condition1=New-AzActivityLogAlertAlertRuleAnyOfOrLeafConditionObject -Equal Administrative -Field category
$condition2=New-AzActivityLogAlertAlertRuleAnyOfOrLeafConditionObject -Equal Error -Field level
$any1=New-AzActivityLogAlertAlertRuleLeafConditionObject -Field properties.incidentType -Equal Maintenance
$any2=New-AzActivityLogAlertAlertRuleLeafConditionObject -Field properties.incidentType -Equal Incident
$condition3=New-AzActivityLogAlertAlertRuleAnyOfOrLeafConditionObject -AnyOf $any1,$any2
New-AzActivityLogAlert -Name $AlertName -ResourceGroupName $ResourceGroupName -Action $actiongroup -Condition @($condition1,$condition2,$condition3) -Location global -Scope $scope

.Outputs
Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.IActivityLogAlertResource
Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.IActivityLogAlertResource
.Notes
COMPLEX PARAMETER PROPERTIES

Expand All @@ -37,18 +42,18 @@ ACTIONGROUP <IActionGroup[]>: The list of the Action Groups.
[(Any) <String>]: This indicates any property can be added to this object.

CONDITIONALLOF <IAlertRuleAnyOfOrLeafCondition[]>: The list of Activity Log Alert rule conditions.
[ContainsAny <String[]>]: The value of the event's field will be compared to the values in this array (case-insensitive) to determine if the condition is met.
[ContainsAny <List<String>>]: The value of the event's field will be compared to the values in this array (case-insensitive) to determine if the condition is met.
[Equal <String>]: The value of the event's field will be compared to this value (case-insensitive) to determine if the condition is met.
[Field <String>]: The name of the Activity Log event's field that this condition will examine. The possible values for this field are (case-insensitive): 'resourceId', 'category', 'caller', 'level', 'operationName', 'resourceGroup', 'resourceProvider', 'status', 'subStatus', 'resourceType', or anything beginning with 'properties'.
[AnyOf <IAlertRuleLeafCondition[]>]: An Activity Log Alert rule condition that is met when at least one of its member leaf conditions are met.
[ContainsAny <String[]>]: The value of the event's field will be compared to the values in this array (case-insensitive) to determine if the condition is met.
[AnyOf <List<IAlertRuleLeafCondition>>]: An Activity Log Alert rule condition that is met when at least one of its member leaf conditions are met.
[ContainsAny <List<String>>]: The value of the event's field will be compared to the values in this array (case-insensitive) to determine if the condition is met.
[Equal <String>]: The value of the event's field will be compared to this value (case-insensitive) to determine if the condition is met.
[Field <String>]: The name of the Activity Log event's field that this condition will examine. The possible values for this field are (case-insensitive): 'resourceId', 'category', 'caller', 'level', 'operationName', 'resourceGroup', 'resourceProvider', 'status', 'subStatus', 'resourceType', or anything beginning with 'properties'.
.Link
https://learn.microsoft.com/powershell/module/az.monitor/new-azactivitylogalert
#>
function New-AzActivityLogAlert {
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.IActivityLogAlertResource])]
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.IActivityLogAlertResource])]
[CmdletBinding(DefaultParameterSetName='CreateExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')]
param(
[Parameter(Mandatory)]
Expand All @@ -72,43 +77,43 @@ function New-AzActivityLogAlert {
# The ID of the target subscription.
${SubscriptionId},

[Parameter(Mandatory)]
[Parameter(ParameterSetName='CreateExpanded', Mandatory)]
[AllowEmptyCollection()]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.IActionGroup[]]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.IActionGroup[]]
# The list of the Action Groups.
# To construct, see NOTES section for ACTIONGROUP properties and create a hash table.
${Action},

[Parameter(Mandatory)]
[Parameter(ParameterSetName='CreateExpanded', Mandatory)]
[AllowEmptyCollection()]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.IAlertRuleAnyOfOrLeafCondition[]]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.IAlertRuleAnyOfOrLeafCondition[]]
# The list of Activity Log Alert rule conditions.
# To construct, see NOTES section for CONDITIONALLOF properties and create a hash table.
${Condition},

[Parameter()]
[Parameter(ParameterSetName='CreateExpanded')]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Body')]
[System.String]
# A description of this Activity Log Alert rule.
${Description},

[Parameter()]
[Parameter(ParameterSetName='CreateExpanded')]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Body')]
[System.Boolean]
# Indicates whether this Activity Log Alert rule is enabled.
# If an Activity Log Alert rule is not enabled, then none of its actions will be activated.
${Enabled},

[Parameter(Mandatory)]
[Parameter(ParameterSetName='CreateExpanded', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Body')]
[System.String]
# The location of the resource.
# Since Azure Activity Log Alerts is a global service, the location of the rules should always be 'global'.
${Location},

[Parameter(Mandatory)]
[Parameter(ParameterSetName='CreateExpanded', Mandatory)]
[AllowEmptyCollection()]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Body')]
[System.String[]]
Expand All @@ -117,19 +122,32 @@ function New-AzActivityLogAlert {
# This list must include at least one item.
${Scope},

[Parameter()]
[Parameter(ParameterSetName='CreateExpanded')]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Runtime.Info(PossibleTypes=([Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.IAzureResourceTags]))]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Runtime.Info(PossibleTypes=([Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.IAzureResourceTags]))]
[System.Collections.Hashtable]
# The tags of the resource.
${Tag},

[Parameter(ParameterSetName='CreateViaJsonFilePath', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Body')]
[System.String]
# Path of Json file supplied to the Create operation
${JsonFilePath},

[Parameter(ParameterSetName='CreateViaJsonString', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Body')]
[System.String]
# Json string supplied to the Create operation
${JsonString},

[Parameter()]
[Alias('AzureRMContext', 'AzureCredential')]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Azure')]
[System.Management.Automation.PSObject]
# The credentials, account, tenant, and subscription used for communication with Azure.
# The DefaultProfile parameter is not functional.
# Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
${DefaultProfile},

[Parameter(DontShow)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ Updates 'tags' and 'enabled' fields in an existing Alert rule.
This method is used to update the Alert rule tags, and to enable or disable the Alert rule.
To update other fields use CreateOrUpdate operation.
.Example
{{ Add code here }}
.Example
{{ Add code here }}
Update-AzActivityLogAlert -ResourceGroupName $ResourceGroupName -Name $AlertName -Tag @{"key"="val"} -Enabled $false

.Inputs
Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.IActivityLogAlertIdentity
.Outputs
Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.IActivityLogAlertResource
Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.IActivityLogAlertResource
.Notes
COMPLEX PARAMETER PROPERTIES

Expand All @@ -46,24 +44,30 @@ INPUTOBJECT <IMonitorIdentity>: Identity Parameter
https://learn.microsoft.com/powershell/module/az.monitor/update-azactivitylogalert
#>
function Update-AzActivityLogAlert {
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.IActivityLogAlertResource])]
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.IActivityLogAlertResource])]
[CmdletBinding(DefaultParameterSetName='UpdateExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')]
param(
[Parameter(ParameterSetName='UpdateExpanded', Mandatory)]
[Parameter(ParameterSetName='UpdateViaJsonFilePath', Mandatory)]
[Parameter(ParameterSetName='UpdateViaJsonString', Mandatory)]
[Alias('ActivityLogAlertName')]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Path')]
[System.String]
# The name of the Activity Log Alert rule.
${Name},

[Parameter(ParameterSetName='UpdateExpanded', Mandatory)]
[Parameter(ParameterSetName='UpdateViaJsonFilePath', Mandatory)]
[Parameter(ParameterSetName='UpdateViaJsonString', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Path')]
[System.String]
# The name of the resource group.
# The name is case insensitive.
${ResourceGroupName},

[Parameter(ParameterSetName='UpdateExpanded')]
[Parameter(ParameterSetName='UpdateViaJsonFilePath')]
[Parameter(ParameterSetName='UpdateViaJsonString')]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')]
[System.String]
Expand All @@ -77,26 +81,41 @@ function Update-AzActivityLogAlert {
# To construct, see NOTES section for INPUTOBJECT properties and create a hash table.
${InputObject},

[Parameter()]
[Parameter(ParameterSetName='UpdateExpanded')]
[Parameter(ParameterSetName='UpdateViaIdentityExpanded')]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Body')]
[System.Boolean]
# Indicates whether this Activity Log Alert rule is enabled.
# If an Activity Log Alert rule is not enabled, then none of its actions will be activated.
${Enabled},

[Parameter()]
[Parameter(ParameterSetName='UpdateExpanded')]
[Parameter(ParameterSetName='UpdateViaIdentityExpanded')]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Runtime.Info(PossibleTypes=([Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.IAlertRulePatchObjectTags]))]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Runtime.Info(PossibleTypes=([Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.IAlertRulePatchObjectTags]))]
[System.Collections.Hashtable]
# The resource tags
${Tag},

[Parameter(ParameterSetName='UpdateViaJsonFilePath', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Body')]
[System.String]
# Path of Json file supplied to the Update operation
${JsonFilePath},

[Parameter(ParameterSetName='UpdateViaJsonString', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Body')]
[System.String]
# Json string supplied to the Update operation
${JsonString},

[Parameter()]
[Alias('AzureRMContext', 'AzureCredential')]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Category('Azure')]
[System.Management.Automation.PSObject]
# The credentials, account, tenant, and subscription used for communication with Azure.
# The DefaultProfile parameter is not functional.
# Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
${DefaultProfile},

[Parameter(DontShow)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,26 @@ Create an in-memory object for ActionGroup.
Create an in-memory object for ActionGroup.

.Outputs
Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.ActionGroup
Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.ActionGroup
.Link
https://learn.microsoft.com/powershell/module/Az.Monitor/new-AzActivityLogAlertActionGroupObject
https://learn.microsoft.com/powershell/module/Az.Monitor/new-azactivitylogalertactiongroupobject
#>
function New-AzActivityLogAlertActionGroupObject {
[OutputType('Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.ActionGroup')]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.ModelCmdletAttribute()]
[OutputType('Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.ActionGroup')]
[CmdletBinding(PositionalBinding=$false)]
Param(

[Parameter(Mandatory, HelpMessage="The resource ID of the Action Group. This cannot be null or empty.")]
[string]
$Id,
[Parameter(HelpMessage="the dictionary of custom properties to include with the post operation. These data are appended to the webhook payload.")]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.IActionGroupWebhookProperties]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.IActionGroupWebhookProperties]
$WebhookProperty
)

process {
$Object = [Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.ActionGroup]::New()
$Object = [Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.ActionGroup]::New()

if ($PSBoundParameters.ContainsKey('Id')) {
$Object.Id = $Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ Create an in-memory object for AlertRuleAnyOfOrLeafCondition.
Create an in-memory object for AlertRuleAnyOfOrLeafCondition.

.Outputs
Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.AlertRuleAnyOfOrLeafCondition
Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.AlertRuleAnyOfOrLeafCondition
.Link
https://learn.microsoft.com/powershell/module/Az.Monitor/new-AzActivityLogAlertAlertRuleAnyOfOrLeafConditionObject
https://learn.microsoft.com/powershell/module/Az.Monitor/new-azactivitylogalertalertruleanyoforleafconditionobject
#>
function New-AzActivityLogAlertAlertRuleAnyOfOrLeafConditionObject {
[OutputType('Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.AlertRuleAnyOfOrLeafCondition')]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.ModelCmdletAttribute()]
[OutputType('Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.AlertRuleAnyOfOrLeafCondition')]
[CmdletBinding(PositionalBinding=$false)]
Param(

[Parameter(HelpMessage="An Activity Log Alert rule condition that is met when at least one of its member leaf conditions are met.")]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.IAlertRuleLeafCondition[]]
[Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.IAlertRuleLeafCondition[]]
$AnyOf,
[Parameter(HelpMessage="The value of the event's field will be compared to the values in this array (case-insensitive) to determine if the condition is met.")]
[string[]]
Expand All @@ -46,7 +47,7 @@ function New-AzActivityLogAlertAlertRuleAnyOfOrLeafConditionObject {
)

process {
$Object = [Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.AlertRuleAnyOfOrLeafCondition]::New()
$Object = [Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.AlertRuleAnyOfOrLeafCondition]::New()

if ($PSBoundParameters.ContainsKey('AnyOf')) {
$Object.AnyOf = $AnyOf
Expand Down
Loading