Skip to content

Commit 9c94953

Browse files
authored
Merge pull request #345 from Azure/gucalder
Activity Log Alert cmdlets
2 parents a1f3e08 + 8b4a3ba commit 9c94953

File tree

67 files changed

+4179
-498
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4179
-498
lines changed

ChangeLog.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@
4040
- Remove-AzureRmContainerGroup
4141
- Get-AzureRmContainerInstanceLog
4242
* Insights
43+
* New cmdlet Disable-AzureRmActivityLogAlert
44+
- A new cmdlet to disable an existing activity log alert.
45+
- Optionally the Tags are settable with this cmdlet too.
46+
* New cmdlet Enable-AzureRmActivityLogAlert
47+
- A new cmdlet to enable an existing activity log alert.
48+
- Optionally the Tags are settable with this cmdlet too.
49+
* New cmdlet Get-AzureRmActivityLogAlert
50+
- A new cmdlet to retrieve one or more activity log alerts.
51+
- The alerts can be retrieved by name, resource group, or subscription.
52+
* New cmdlet New-AzureRmActionGroup
53+
- A new cmdlet to create an ActionGroup object in memory (no request involved.)
54+
* New cmdlet New-AzureRmActivityLogAlertCondition
55+
- A new cmdlet to create an activity log alert leaf condition object in memory (no request involved.)
56+
* New cmdlet Set-AzureRmActivityLogAlert
57+
- A new cmdlet to create or update an activity log alert.
58+
* New cmdlet Remove-AzureRmActivityLogAlert
59+
- A new cmdlet to remove one activity log alert.
4360
* New cmdlet Set-AzureRmActionGroup
4461
- A new cmdlet to create a new or update an existing action group.
4562
* New cmdlet Get-AzureRmActionGroup

src/ResourceManager/Insights/AzureRM.Insights.psd1

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ CmdletsToExport = 'Get-AzureRmUsage', 'Get-AzureRmMetricDefinition',
8383
'Add-AzureRmMetricAlertRule', 'Add-AzureRmLogAlertRule',
8484
'Add-AzureRmWebtestAlertRule', 'Get-AzureRmAlertHistory',
8585
'Get-AzureRmAlertRule', 'New-AzureRmAlertRuleEmail',
86-
'New-AzureRmAlertRuleWebhook', 'Remove-AzureRmAlertRule',
86+
'New-AzureRmAlertRuleWebhook', 'Remove-AzureRmAlertRule',
87+
'Set-AzureRmActivityLogAlert', 'Get-AzureRmActivityLogAlert',
88+
'New-AzureRmActionGroup', 'New-AzureRmActivityLogAlertCondition',
89+
'Enable-AzureRmActivityLogAlert', 'Disable-AzureRmActivityLogAlert',
90+
'Remove-AzureRmActivityLogAlert',
8791
'New-AzureRmActionGroupReceiver', 'Set-AzureRmActionGroup',
8892
'Get-AzureRmActionGroup', 'Remove-AzureRmActionGroup'
8993

@@ -120,7 +124,24 @@ PrivateData = @{
120124
# IconUri = ''
121125

122126
# ReleaseNotes of this module
123-
ReleaseNotes = ' * New cmdlet Set-AzureRmActionGroup
127+
ReleaseNotes = ' * New cmdlet Disable-AzureRmActivityLogAlert
128+
- A new cmdlet to disable an existing activity log alert.
129+
- Optionally the Tags are settable with this cmdlet too.
130+
* New cmdlet Enable-AzureRmActivityLogAlert
131+
- A new cmdlet to enable an existing activity log alert.
132+
- Optionally the Tags are settable with this cmdlet too.
133+
* New cmdlet Get-AzureRmActivityLogAlert
134+
- A new cmdlet to retrieve one or more activity log alerts.
135+
- The alerts can be retrieved by name, resource group, or subscription.
136+
* New cmdlet New-AzureRmActionGroup
137+
- A new cmdlet to create an ActionGroup object in memory (no request involved.)
138+
* New cmdlet New-AzureRmActivityLogAlertCondition
139+
- A new cmdlet to create an activity log alert leaf condition object in memory (no request involved.)
140+
* New cmdlet Set-AzureRmActivityLogAlert
141+
- A new cmdlet to create or update an activity log alert.
142+
* New cmdlet Remove-AzureRmActivityLogAlert
143+
- A new cmdlet to remove one activity log alert.
144+
* New cmdlet Set-AzureRmActionGroup
124145
- A new cmdlet to create a new or update an existing action group.
125146
* New cmdlet Get-AzureRmActionGroup
126147
- A new cmdlet to retrieve one or more action groups.

src/ResourceManager/Insights/ChangeLog.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@
2020
## Current Release
2121

2222
## Version 3.4.0
23+
* New cmdlet Disable-AzureRmActivityLogAlert
24+
- A new cmdlet to disable an existing activity log alert.
25+
- Optionally the Tags are settable with this cmdlet too.
26+
* New cmdlet Enable-AzureRmActivityLogAlert
27+
- A new cmdlet to enable an existing activity log alert.
28+
- Optionally the Tags are settable with this cmdlet too.
29+
* New cmdlet Get-AzureRmActivityLogAlert
30+
- A new cmdlet to retrieve one or more activity log alerts.
31+
- The alerts can be retrieved by name, resource group, or subscription.
32+
* New cmdlet New-AzureRmActionGroup
33+
- A new cmdlet to create an ActionGroup object in memory (no request involved.)
34+
* New cmdlet New-AzureRmActivityLogAlertCondition
35+
- A new cmdlet to create an activity log alert leaf condition object in memory (no request involved.)
36+
* New cmdlet Set-AzureRmActivityLogAlert
37+
- A new cmdlet to create or update an activity log alert.
38+
* New cmdlet Remove-AzureRmActivityLogAlert
39+
- A new cmdlet to remove one activity log alert.
2340
* New cmdlet Set-AzureRmActionGroup
2441
- A new cmdlet to create a new or update an existing action group.
2542
* New cmdlet Get-AzureRmActionGroup
@@ -29,7 +46,7 @@
2946
- A new cmdlet to remove one action group.
3047
* New cmdlet New-AzureRmActionGroupReceiver
3148
- A new cmdlet to create an new action group receiver in memory.
32-
49+
3350
## Version 3.3.1
3451

3552
## Version 3.3.0
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Collections.Generic;
16+
using Microsoft.Azure.Management.Monitor.Management.Models;
17+
18+
namespace Microsoft.Azure.Commands.Insights.Test.ActivityLogAlerts
19+
{
20+
public static class ActivityLogAlertsUtilities
21+
{
22+
public static ActivityLogAlertActionGroup CreateActionGroup(string id, Dictionary<string, string> webhooks)
23+
{
24+
return new ActivityLogAlertActionGroup
25+
{
26+
ActionGroupId = id,
27+
WebhookProperties = webhooks
28+
};
29+
}
30+
31+
public static ActivityLogAlertLeafCondition CreateLeafCondition(string field, string equals)
32+
{
33+
return new ActivityLogAlertLeafCondition
34+
{
35+
Field = field,
36+
Equals = equals
37+
};
38+
}
39+
40+
public static ActivityLogAlertResource CreateActivityLogAlertResource(string location, string name)
41+
{
42+
return new ActivityLogAlertResource(
43+
location: location,
44+
name: name,
45+
condition: new ActivityLogAlertAllOfCondition(
46+
new List<ActivityLogAlertLeafCondition>
47+
{
48+
CreateLeafCondition("field", "equals")
49+
}),
50+
scopes: new List<string> { "scope1" },
51+
actions: new ActivityLogAlertActionList(
52+
new List<ActivityLogAlertActionGroup>
53+
{
54+
CreateActionGroup(
55+
id: "actionGrp1",
56+
webhooks: new Dictionary<string, string>())
57+
}));
58+
}
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Collections.Generic;
16+
using Microsoft.Rest.Azure;
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Moq;
19+
using System.Management.Automation;
20+
using System.Threading;
21+
using System.Threading.Tasks;
22+
using Xunit;
23+
using Microsoft.Azure.Commands.ScenarioTest;
24+
using Microsoft.Azure.Commands.Insights.ActivityLogAlert;
25+
using Microsoft.Azure.Management.Monitor.Management;
26+
using Microsoft.Azure.Management.Monitor.Management.Models;
27+
28+
namespace Microsoft.Azure.Commands.Insights.Test.ActivityLogAlerts
29+
{
30+
public class DisableAzureRmActivityLogAlertTests
31+
{
32+
private readonly DisableAzureRmActivityLogAlertCommand cmdlet;
33+
private readonly Mock<MonitorManagementClient> monitorClientMock;
34+
private readonly Mock<IActivityLogAlertsOperations> insightsOperationsMock;
35+
private Mock<ICommandRuntime> commandRuntimeMock;
36+
private AzureOperationResponse<ActivityLogAlertResource> response;
37+
private string resourceGroup;
38+
private string name;
39+
private ActivityLogAlertPatchBody body;
40+
41+
public DisableAzureRmActivityLogAlertTests(Xunit.Abstractions.ITestOutputHelper output)
42+
{
43+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
44+
TestExecutionHelpers.SetUpSessionAndProfile();
45+
insightsOperationsMock = new Mock<IActivityLogAlertsOperations>();
46+
monitorClientMock = new Mock<MonitorManagementClient>();
47+
commandRuntimeMock = new Mock<ICommandRuntime>();
48+
cmdlet = new DisableAzureRmActivityLogAlertCommand()
49+
{
50+
CommandRuntime = commandRuntimeMock.Object,
51+
MonitorManagementClient = monitorClientMock.Object
52+
};
53+
54+
response = new AzureOperationResponse<ActivityLogAlertResource>()
55+
{
56+
Body = ActivityLogAlertsUtilities.CreateActivityLogAlertResource(location: "westus", name: "alert1")
57+
};
58+
59+
insightsOperationsMock.Setup(f => f.UpdateWithHttpMessagesAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<ActivityLogAlertPatchBody>(), It.IsAny<Dictionary<string, List<string>>>(), It.IsAny<CancellationToken>()))
60+
.Returns(Task.FromResult<AzureOperationResponse<ActivityLogAlertResource>>(response))
61+
.Callback((string r, string n, ActivityLogAlertPatchBody b, Dictionary<string, List<string>> headers, CancellationToken t) =>
62+
{
63+
this.resourceGroup = r;
64+
this.name = n;
65+
this.body = b;
66+
});
67+
68+
monitorClientMock.SetupGet(f => f.ActivityLogAlerts).Returns(this.insightsOperationsMock.Object);
69+
70+
// Setup Confirmation
71+
commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>())).Returns(true);
72+
commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
73+
commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(true);
74+
commandRuntimeMock.Setup(f => f.ShouldContinue(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
75+
}
76+
77+
[Fact]
78+
[Trait(Category.AcceptanceType, Category.CheckIn)]
79+
public void DisableActivityLogAlertCommandParametersProcessing()
80+
{
81+
cmdlet.ResourceGroupName = Utilities.ResourceGroup;
82+
cmdlet.Name = "alert1";
83+
cmdlet.ExecuteCmdlet();
84+
85+
Assert.Equal(Utilities.ResourceGroup, this.resourceGroup);
86+
Assert.Equal("alert1", this.name);
87+
Assert.NotNull(this.body);
88+
Assert.False(this.body.Enabled);
89+
Assert.Null(this.body.Tags);
90+
91+
cmdlet.ExecuteCmdlet();
92+
93+
Assert.NotNull(this.body);
94+
Assert.False(this.body.Enabled);
95+
Assert.Null(this.body.Tags);
96+
97+
ActivityLogAlertResource resource = new ActivityLogAlertResource(location: "Global", scopes: null, condition: null, name: "andy0307rule", actions: null, id: "//subscriptions/07c0b09d-9f69-4e6e-8d05-f59f67299cb2/resourceGroups/Default-ActivityLogAlerts/providers/microsoft.insights/activityLogAlerts/andy0307rule")
98+
{
99+
Enabled = true
100+
};
101+
102+
cmdlet.InputObject = new OutputClasses.PSActivityLogAlertResource(resource);
103+
cmdlet.ExecuteCmdlet();
104+
105+
Assert.NotNull(this.body);
106+
Assert.Equal("Default-ActivityLogAlerts", this.resourceGroup);
107+
Assert.Equal("andy0307rule", this.name);
108+
Assert.False(this.body.Enabled);
109+
Assert.Null(this.body.Tags);
110+
111+
cmdlet.InputObject = null;
112+
cmdlet.ResourceId = "/subscriptions/07c0b09d-9f69-4e6e-8d05-f59f67299cb2/resourceGroups/Default-ActivityLogAlerts/providers/microsoft.insights/activityLogAlerts/andy0307rule";
113+
cmdlet.ExecuteCmdlet();
114+
Assert.NotNull(this.body);
115+
Assert.Equal("Default-ActivityLogAlerts", this.resourceGroup);
116+
Assert.Equal("andy0307rule", this.name);
117+
Assert.False(this.body.Enabled);
118+
Assert.Null(this.body.Tags);
119+
}
120+
}
121+
}

0 commit comments

Comments
 (0)