Skip to content

Commit 6b84dbb

Browse files
committed
[Insights] Removing Tag from the Activity Log Alert Enable and Disable cmdlets, fixing the arguments attributes for Set-AzureRmActivityLogAlerts, updating the help files accordingly.
1 parent c3d3675 commit 6b84dbb

File tree

8 files changed

+76
-146
lines changed

8 files changed

+76
-146
lines changed

src/ResourceManager/Insights/Commands.Insights.Test/ActivityLogAlerts/DisableAzureRmActivityLogAlertTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,14 @@ public void DisableActivityLogAlertCommandParametersProcessing()
8080
{
8181
cmdlet.ResourceGroupName = Utilities.ResourceGroup;
8282
cmdlet.Name = "alert1";
83-
cmdlet.Tag = new Dictionary<string, string> { { "key2", "value2" } };
8483
cmdlet.ExecuteCmdlet();
8584

8685
Assert.Equal(Utilities.ResourceGroup, this.resourceGroup);
8786
Assert.Equal("alert1", this.name);
8887
Assert.NotNull(this.body);
8988
Assert.False(this.body.Enabled);
90-
Assert.NotNull(this.body.Tags);
89+
Assert.Null(this.body.Tags);
9190

92-
cmdlet.Tag = null;
9391
cmdlet.ExecuteCmdlet();
9492

9593
Assert.NotNull(this.body);

src/ResourceManager/Insights/Commands.Insights.Test/ActivityLogAlerts/EnableAzureRmActivityLogAlertTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,14 @@ public void EnableActivityLogAlertCommandParametersProcessing()
8080
{
8181
cmdlet.ResourceGroupName = Utilities.ResourceGroup;
8282
cmdlet.Name = "alert1";
83-
cmdlet.Tag = new Dictionary<string, string>{ { "key2", "value2" } };
8483
cmdlet.ExecuteCmdlet();
8584

8685
Assert.Equal(Utilities.ResourceGroup, this.resourceGroup);
8786
Assert.Equal("alert1", this.name);
8887
Assert.NotNull(this.body);
8988
Assert.True(this.body.Enabled);
90-
Assert.NotNull(this.body.Tags);
89+
Assert.Null(this.body.Tags);
9190

92-
cmdlet.Tag = null;
9391
cmdlet.ExecuteCmdlet();
9492

9593
Assert.NotNull(this.body);

src/ResourceManager/Insights/Commands.Insights/ActivityLogAlert/DisableAzureRmActivityLogAlertCommand.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,6 @@ public class DisableAzureRmActivityLogAlertCommand : ManagementCmdletBase
4646
[ValidateNotNullOrEmpty]
4747
public string ResourceGroupName { get; set; }
4848

49-
/// <summary>
50-
/// Gets or sets the Tags of the activity log alert resource
51-
/// </summary>
52-
[Parameter(ParameterSetName = DisableActivityLogAlertDeafultParamGroup, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The tags of the activity log alert resource")]
53-
[Parameter(ParameterSetName = DisableActivityLogAlertFromPipeParamGroup, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The tags of the activity log alert resource")]
54-
[Parameter(ParameterSetName = DisableActivityLogAlertFromResourceIdParamGroup, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The tags of the activity log alert resource")]
55-
[ValidateNotNullOrEmpty]
56-
public Dictionary<string, string> Tag { get; set; }
57-
5849
/// <summary>
5950
/// Gets or sets the InputObject parameter of the cmdlet
6051
/// </summary>
@@ -82,7 +73,7 @@ protected override void ProcessRecordInternal()
8273
{
8374
string resourceGroupName = this.ResourceGroupName;
8475
string activityLogAlertName = this.Name;
85-
IDictionary<string, string> tags = this.Tag;
76+
IDictionary<string, string> tags = null;
8677

8778
// Using value from the pipe
8879
if (this.MyInvocation.BoundParameters.ContainsKey("InputObject") || this.InputObject != null)
@@ -92,7 +83,7 @@ protected override void ProcessRecordInternal()
9283
resourceGroupName: out resourceGroupName,
9384
activityLogAlertName: out activityLogAlertName);
9485

95-
tags = this.MyInvocation.BoundParameters.ContainsKey("Tag") || this.Tag != null ? this.Tag : this.InputObject.Tags;
86+
tags = this.InputObject.Tags;
9687
}
9788
else if (this.MyInvocation.BoundParameters.ContainsKey("ResourceId") || !string.IsNullOrWhiteSpace(this.ResourceId))
9889
{

src/ResourceManager/Insights/Commands.Insights/ActivityLogAlert/EnableAzureRmActivityLogAlertCommand.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,6 @@ public class EnableAzureRmActivityLogAlertCommand : ManagementCmdletBase
4646
[ValidateNotNullOrEmpty]
4747
public string ResourceGroupName { get; set; }
4848

49-
/// <summary>
50-
/// Gets or sets the Tags of the activity log alert resource
51-
/// </summary>
52-
[Parameter(ParameterSetName = EnableActivityLogAlertDeafultParamGroup, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The tags of the activity log alert resource")]
53-
[Parameter(ParameterSetName = EnableActivityLogAlertFromPipeParamGroup, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The tags of the activity log alert resource")]
54-
[Parameter(ParameterSetName = EnableActivityLogAlertFromResourceIdParamGroup, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The tags of the activity log alert resource")]
55-
[ValidateNotNullOrEmpty]
56-
public Dictionary<string, string> Tag { get; set; }
57-
5849
/// <summary>
5950
/// Gets or sets the InputObject parameter of the cmdlet
6051
/// </summary>
@@ -82,7 +73,7 @@ protected override void ProcessRecordInternal()
8273
{
8374
string resourceGroupName = this.ResourceGroupName;
8475
string activityLogAlertName = this.Name;
85-
IDictionary<string, string> tags = this.Tag;
76+
IDictionary<string, string> tags = null;
8677

8778
// Using value from the pipe
8879
if (this.MyInvocation.BoundParameters.ContainsKey("InputObject") || this.InputObject != null)
@@ -92,7 +83,7 @@ protected override void ProcessRecordInternal()
9283
resourceGroupName: out resourceGroupName,
9384
activityLogAlertName: out activityLogAlertName);
9485

95-
tags = this.MyInvocation.BoundParameters.ContainsKey("Tag") || this.Tag != null ? this.Tag : this.InputObject.Tags;
86+
tags = this.InputObject.Tags;
9687
}
9788
else if (this.MyInvocation.BoundParameters.ContainsKey("ResourceId") || !string.IsNullOrWhiteSpace(this.ResourceId))
9889
{

src/ResourceManager/Insights/Commands.Insights/ActivityLogAlert/SetAzureRmActivityLogAlertCommand.cs

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -35,45 +35,48 @@ public class SetAzureRmActivityLogAlertCommand : ManagementCmdletBase
3535
/// <summary>
3636
/// Gets or sets the Location parameter of the cmdlet
3737
/// </summary>
38-
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = true, ValueFromPipeline = true, HelpMessage = "The location of the activity log rule resource")]
38+
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The location of the activity log rule resource")]
3939
[Parameter(ParameterSetName = SetActivityLogAlertFromResourceIdParamGroup, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The location of the activity log rule resource")]
4040
[ValidateNotNullOrEmpty]
4141
public string Location { get; set; }
4242

4343
/// <summary>
4444
/// Gets or sets the alert name parameter of the cmdlet
4545
/// </summary>
46-
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = true, ValueFromPipeline = true, HelpMessage = "The activity log rule name")]
46+
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The activity log rule name")]
4747
[ValidateNotNullOrEmpty]
4848
public string Name { get; set; }
4949

5050
/// <summary>
5151
/// Gets or set the resource group name
5252
/// </summary>
53-
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = true, ValueFromPipeline = true, HelpMessage = "The resource group name of the activity log rule resource")]
53+
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name of the activity log rule resource")]
5454
[ValidateNotNullOrEmpty]
5555
public string ResourceGroupName { get; set; }
5656

5757
/// <summary>
5858
/// Gets or sets the scopes of the activity log alert
5959
/// </summary>
60-
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = true, ValueFromPipeline = true, HelpMessage = "The list scopes")]
60+
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The list scopes")]
61+
[Parameter(ParameterSetName = SetActivityLogAlertFromPipeParamGroup, Mandatory = false, HelpMessage = "The list scopes")]
6162
[Parameter(ParameterSetName = SetActivityLogAlertFromResourceIdParamGroup, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The list scopes")]
6263
[ValidateNotNullOrEmpty]
6364
public List<string> Scope { get; set; }
6465

6566
/// <summary>
6667
/// Gets or sets the conditions of the activity log alert
6768
/// </summary>
68-
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = true, ValueFromPipeline = true, HelpMessage = "The list of leaf conditions of the activity log alert")]
69+
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The list of leaf conditions of the activity log alert")]
70+
[Parameter(ParameterSetName = SetActivityLogAlertFromPipeParamGroup, Mandatory = false, HelpMessage = "The list of leaf conditions of the activity log alert")]
6971
[Parameter(ParameterSetName = SetActivityLogAlertFromResourceIdParamGroup, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The list of leaf conditions of the activity log alert")]
7072
[ValidateNotNullOrEmpty]
7173
public List<ActivityLogAlertLeafCondition> Condition { get; set; }
7274

7375
/// <summary>
7476
/// Gets or sets the actions of the activity log alert
7577
/// </summary>
76-
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = true, ValueFromPipeline = true, HelpMessage = "The list actions of the activity log alert")]
78+
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The list actions of the activity log alert")]
79+
[Parameter(ParameterSetName = SetActivityLogAlertFromPipeParamGroup, Mandatory = false, HelpMessage = "The list actions of the activity log alert")]
7780
[Parameter(ParameterSetName = SetActivityLogAlertFromResourceIdParamGroup, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The list actions of the activity log alert")]
7881
[ValidateNotNullOrEmpty]
7982
public List<ActivityLogAlertActionGroup> Action { get; set; }
@@ -89,17 +92,17 @@ public class SetAzureRmActivityLogAlertCommand : ManagementCmdletBase
8992
/// <summary>
9093
/// Gets or set the alert description
9194
/// </summary>
92-
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = false, ValueFromPipeline = true, HelpMessage = "The description of the activity log rule resource")]
93-
[Parameter(ParameterSetName = SetActivityLogAlertFromPipeParamGroup, Mandatory = false, ValueFromPipeline = true, HelpMessage = "The description of the activity log rule resource")]
95+
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The description of the activity log rule resource")]
96+
[Parameter(ParameterSetName = SetActivityLogAlertFromPipeParamGroup, Mandatory = false, HelpMessage = "The description of the activity log rule resource")]
9497
[Parameter(ParameterSetName = SetActivityLogAlertFromResourceIdParamGroup, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The description of the activity log rule resource")]
9598
[ValidateNotNullOrEmpty]
9699
public string Description { get; set; }
97100

98101
/// <summary>
99102
/// Gets or sets the Tags of the activity log alert resource
100103
/// </summary>
101-
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = false, ValueFromPipeline = true, HelpMessage = "The tags of the activity log alert resource")]
102-
[Parameter(ParameterSetName = SetActivityLogAlertFromPipeParamGroup, Mandatory = false, ValueFromPipeline = true, HelpMessage = "The tags of the activity log alert resource")]
104+
[Parameter(ParameterSetName = SetActivityLogAlertDefaultParamGroup, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The tags of the activity log alert resource")]
105+
[Parameter(ParameterSetName = SetActivityLogAlertFromPipeParamGroup, Mandatory = false, HelpMessage = "The tags of the activity log alert resource")]
103106
[Parameter(ParameterSetName = SetActivityLogAlertFromResourceIdParamGroup, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The tags of the activity log alert resource")]
104107
[ValidateNotNullOrEmpty]
105108
public Dictionary<string, string> Tag { get; set; }
@@ -143,11 +146,7 @@ protected override void ProcessRecordInternal()
143146
resourceGroupName: out resourceGroupName,
144147
activityLogAlertName: out activityLogAlertName);
145148

146-
requestBody = this.InputObject;
147-
if (this.MyInvocation.BoundParameters.ContainsKey("Tag") || this.Tag != null)
148-
{
149-
requestBody.Tags = this.Tag;
150-
}
149+
requestBody = this.UpdateActivityLogAlertResource(this.InputObject);
151150
}
152151
else if (this.MyInvocation.BoundParameters.ContainsKey("ResourceId") || !string.IsNullOrWhiteSpace(this.ResourceId))
153152
{
@@ -182,34 +181,7 @@ protected override void ProcessRecordInternal()
182181
{
183182
WriteVerboseWithTimestamp("ResourceId detected: given activity log alert found, modifying its values with the parameters.");
184183

185-
// There was an ActivityLogAlert already there, just modify what can be modifed
186-
// NOTE: Location remains unchanged, the value of the Location parameter is ignored
187-
if (this.MyInvocation.BoundParameters.ContainsKey("Scope") || this.Scope != null)
188-
{
189-
requestBody.Scopes = this.Scope;
190-
}
191-
192-
if (this.MyInvocation.BoundParameters.ContainsKey("Condition") || this.Condition != null)
193-
{
194-
requestBody.Condition = new ActivityLogAlertAllOfCondition(this.Condition);
195-
}
196-
197-
if (this.MyInvocation.BoundParameters.ContainsKey("Action") || this.Action != null)
198-
{
199-
requestBody.Actions = new ActivityLogAlertActionList(this.Action);
200-
}
201-
202-
requestBody.Enabled = !this.DisableAlert.IsPresent;
203-
204-
if (this.MyInvocation.BoundParameters.ContainsKey("Description") || this.Description != null)
205-
{
206-
requestBody.Description = this.Description;
207-
}
208-
209-
if (this.MyInvocation.BoundParameters.ContainsKey("Tag") || this.Tag != null)
210-
{
211-
requestBody.Tags = this.Tag;
212-
}
184+
requestBody = this.UpdateActivityLogAlertResource(requestBody);
213185
}
214186
}
215187
else
@@ -229,6 +201,43 @@ protected override void ProcessRecordInternal()
229201
}
230202
}
231203

204+
private ActivityLogAlertResource UpdateActivityLogAlertResource(ActivityLogAlertResource requestBody)
205+
{
206+
// There was an ActivityLogAlert already there, just modify what can be modifed
207+
// NOTE: Location remains unchanged, the value of the Location parameter is ignored
208+
if (this.MyInvocation.BoundParameters.ContainsKey("Scope") || this.Scope != null)
209+
{
210+
requestBody.Scopes = this.Scope;
211+
}
212+
213+
if (this.MyInvocation.BoundParameters.ContainsKey("Condition") || this.Condition != null)
214+
{
215+
requestBody.Condition = new ActivityLogAlertAllOfCondition(this.Condition);
216+
}
217+
218+
if (this.MyInvocation.BoundParameters.ContainsKey("Action") || this.Action != null)
219+
{
220+
requestBody.Actions = new ActivityLogAlertActionList(this.Action);
221+
}
222+
223+
if (this.DisableAlert.IsPresent)
224+
{
225+
requestBody.Enabled = false;
226+
}
227+
228+
if (this.MyInvocation.BoundParameters.ContainsKey("Description") || this.Description != null)
229+
{
230+
requestBody.Description = this.Description;
231+
}
232+
233+
if (this.MyInvocation.BoundParameters.ContainsKey("Tag") || this.Tag != null)
234+
{
235+
requestBody.Tags = this.Tag;
236+
}
237+
238+
return requestBody;
239+
}
240+
232241
private ActivityLogAlertResource CreateActivityLogAlertResource(string name, string location)
233242
{
234243
ActivityLogAlertResource newAlert = new ActivityLogAlertResource(

src/ResourceManager/Insights/Commands.Insights/help/Disable-AzureRmActivityLogAlert.md

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Disables an activity log alert and sets its tags.
1313
## SYNTAX
1414

1515
```
16-
Disable-AzureRmActivityLogAlert [-InputObject <PSActivityLogAlertResource>] [-ResourceId <String>] [-Name <String> -ResourceGroupName <String>
17-
[-Tag <System.Collections.Generic.Dictionary`1[<string>, <string>]>]] [<CommonParameters>]
16+
Disable-AzureRmActivityLogAlert [-InputObject <PSActivityLogAlertResource>] [-ResourceId <String>] [-Name <String> -ResourceGroupName <String>] [<CommonParameters>]
1817
```
1918

2019
## DESCRIPTION
@@ -30,30 +29,18 @@ PS C:\>Disable-AzureRmActivityLogAlert -Name "alert1" -ResourceGroupName "Defaul
3029

3130
This command disables the activity log alert called alert1 in the resource group Default-ActivityLogsAlerts.
3231

33-
### Example 2: Change the tags for an activity log alert
34-
```
35-
36-
PS C:\>$dict = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]"
37-
PS C:\>$dict.Add('key1', 'value1')
38-
39-
PS C:\>Disable-AzureRmActivityLogAlert -Name "alert1" -ResourceGroupName "Default-ActivityLogsAlerts" -Tag $dict
40-
```
41-
4232
This command changes the tags property of the activity log alert called alert1 and disables it.
4333

44-
### Example 3: Change the tags and state of an activity log alert using a PSActivityLogAlertResource object as input
34+
### Example 2: Disable an activity log alert using a PSActivityLogAlertResource object as input
4535
```
4636
4737
PS C:\>$obj = Get-AzureRmActivityLogAlert -ResourceGroup "Default-activityLogAlerts" -Name "alert1"
48-
PS C:\>$dict = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]"
49-
PS C:\>$dict.Add('key1', 'value1')
50-
PS C:\>$obj.Tags = $dict
5138
PS C:\>Disable-AzureRmActivityLogAlert -InputObject $obj
5239
```
5340

54-
This command changes the tags property of the activity log alert called alert1. For this it uses a PSActivityLogAlertResource object as input argument.
41+
This command disables an activity log alert called alert1. For this it uses a PSActivityLogAlertResource object as input argument.
5542

56-
### Example 4: Disable the ActivityLogAlert using the ResourceId parameter
43+
### Example 3: Disable the ActivityLogAlert using the ResourceId parameter
5744
```
5845
5946
PS C:\>Find-AzureRmResource -ResourceGroupEquals "myResourceGroup" -ResourceNameEquals "myLogAlert" | Disable-AzureRmActivityLogAlert
@@ -95,21 +82,6 @@ Accept pipeline input: True (ByPropertyName)
9582
Accept wildcard characters: False
9683
```
9784
98-
### -Tag
99-
Sets the tags property of the activity log alert resource.
100-
101-
```yaml
102-
Type: System.Collections.Generic.Dictionary`1[<string>, <string>]
103-
Parameter Sets: DisableActivityLogAlertDeafultParamGroup
104-
Aliases:
105-
106-
Required: False
107-
Position: Named
108-
Default value: None
109-
Accept pipeline input: True (ByPropertyName)
110-
Accept wildcard characters: False
111-
```
112-
11385
### -InputObject
11486
Sets the InputObject tags property of the call to extract the required name, resource group name, and the optional tag properties.
11587

0 commit comments

Comments
 (0)