Skip to content

Commit cb0c1c4

Browse files
authored
Merge pull request Azure#9495 from mahakjain314/master
Powershell Cmdlets for Alerts Management
2 parents f0c250f + 5bdf31c commit cb0c1c4

File tree

64 files changed

+9381
-0
lines changed

Some content is hidden

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

64 files changed

+9381
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<PsModuleName>AlertsManagement</PsModuleName>
5+
</PropertyGroup>
6+
7+
<Import Project="$(MSBuildThisFileDirectory)..\..\Az.Test.props" />
8+
9+
<PropertyGroup>
10+
<RootNamespace>$(LegacyAssemblyPrefix)$(PsModuleName)$(AzTestAssemblySuffix).ScenarioTests</RootNamespace>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.Azure.Management.AlertsManagement" Version="0.9.1-preview" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<Folder Include="SessionRecords\" />
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.Reflection;
16+
using System.Runtime.InteropServices;
17+
using Xunit;
18+
19+
// General Information about an assembly is controlled through the following
20+
// set of attributes. Change these attribute values to modify the information
21+
// associated with an assembly.
22+
[assembly: AssemblyTitle("Microsoft.Azure.Commands.AlertsManagement.Test")]
23+
[assembly: AssemblyDescription("")]
24+
[assembly: AssemblyConfiguration("")]
25+
[assembly: AssemblyCompany("")]
26+
[assembly: AssemblyProduct("Microsoft.Azure.Commands.AlertsManagement.Test")]
27+
[assembly: AssemblyCopyright(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyCopyright)]
28+
[assembly: AssemblyTrademark("")]
29+
[assembly: AssemblyCulture("")]
30+
31+
// Setting ComVisible to false makes the types in this assembly not visible
32+
// to COM components. If you need to access a type in this assembly from
33+
// COM, set the ComVisible attribute to true on that type.
34+
[assembly: ComVisible(false)]
35+
36+
// The following GUID is for the ID of the typelib if this project is exposed to COM
37+
[assembly: Guid("822d5889-438f-4c18-9c06-f5db728d417d")]
38+
39+
// Version information for an assembly consists of the following four values:
40+
//
41+
// Major Version
42+
// Minor Version
43+
// Build Number
44+
// Revision
45+
//
46+
// You can specify all the values or you can default the Build and Revision Numbers
47+
// by using the '*' as shown below:
48+
[assembly: AssemblyVersion("4.0.0")]
49+
[assembly: AssemblyFileVersion("4.0.0")]
50+
[assembly: CollectionBehavior(DisableTestParallelization = true)]
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
18+
using Xunit;
19+
using Microsoft.Azure.ServiceManagement.Common.Models;
20+
using Xunit.Abstractions;
21+
22+
namespace Microsoft.Azure.Commands.AlertsManagement.Test.ScenarioTests
23+
{
24+
public class ActionRuleTests : RMTestBase
25+
{
26+
public XunitTracingInterceptor _logger;
27+
28+
public ActionRuleTests(Xunit.Abstractions.ITestOutputHelper output)
29+
{
30+
_logger = new XunitTracingInterceptor(output);
31+
XunitTracingInterceptor.AddToContext(_logger);
32+
}
33+
34+
[Fact]
35+
[Trait(Category.AcceptanceType, Category.CheckIn)]
36+
public void TestGetActionRulesFilteredByParameters()
37+
{
38+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetActionRulesFilteredByParameters");
39+
}
40+
41+
[Fact]
42+
[Trait(Category.AcceptanceType, Category.CheckIn)]
43+
public void TestCreateUpdateAndDeleteSuppressionRule()
44+
{
45+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateUpdateAndDeleteSuppressionRule");
46+
}
47+
48+
[Fact]
49+
[Trait(Category.AcceptanceType, Category.CheckIn)]
50+
public void TestCreateUpdateAndDeleteActionGroupRule()
51+
{
52+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateUpdateAndDeleteActionGroupRule");
53+
}
54+
55+
[Fact]
56+
[Trait(Category.AcceptanceType, Category.CheckIn)]
57+
public void TestCreateUpdateAndDeleteDiagnosticsRule()
58+
{
59+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateUpdateAndDeleteDiagnosticsRule");
60+
}
61+
}
62+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
<#
16+
.SYNOPSIS
17+
Test Action Rule Operations
18+
#>
19+
function Test-GetActionRulesFilteredByParameters
20+
{
21+
$severityFilter = "Sev3"
22+
$monitorService = "Platform"
23+
$actionRules = Get-AzActionRule -Severity $severityFilter -MonitorService $monitorService
24+
25+
Assert-NotNull $actionRules.Count
26+
}
27+
28+
function Test-CreateUpdateAndDeleteSuppressionRule
29+
{
30+
try
31+
{
32+
$resourceGroupName = Get-TestResourceGroupName "suppression"
33+
$location = Get-ProviderLocation ResourceManagement
34+
$actionRuleName = Get-TestActionRuleName "suppression"
35+
36+
#Create Resource Group
37+
New-AzResourceGroup -Name $resourceGroupName -Location $location -Force
38+
39+
$createdActionRule = Set-AzActionRule -ResourceGroupName $resourceGroupName -Name $actionRuleName -Scope "/subscriptions/dd91de05-d791-4ceb-b6dc-988682dc7d72/resourceGroups/alertslab","/subscriptions/dd91de05-d791-4ceb-b6dc-988682dc7d72/resourceGroups/Test-VMs" -SeverityCondition "Equals:Sev0,Sev1" -MonitorCondition "NotEquals:Resolved" -Description "Test description" -Status "Enabled" -ActionRuleType "Suppression" -ReccurenceType "Weekly" -SuppressionStartTime "06/26/2018 06:00:00" -SuppressionEndTime "07/27/2018 06:00:00" -ReccurentValue 1,4,6
40+
41+
Assert-NotNull $createdActionRule
42+
43+
# Update Status of Action Rule
44+
$updatedActionRule = Update-AzActionRule -ResourceGroupName $resourceGroupName -Name $actionRuleName -Status "Disabled"
45+
Assert-NotNull $updatedActionRule
46+
Assert-AreEqual "Disabled" $updatedActionRule.Status
47+
}
48+
finally
49+
{
50+
CleanUp $resourceGroupName $actionRuleName
51+
}
52+
}
53+
54+
function Test-CreateUpdateAndDeleteActionGroupRule
55+
{
56+
try
57+
{
58+
$resourceGroupName = Get-TestResourceGroupName "actiongroup"
59+
$location = Get-ProviderLocation ResourceManagement
60+
$actionRuleName = Get-TestActionRuleName "actiongroup"
61+
62+
#Create Resource Group
63+
New-AzResourceGroup -Name $resourceGroupName -Location $location -Force
64+
65+
$createdActionRule = Set-AzActionRule -ResourceGroupName $resourceGroupName -Name $actionRuleName -Scope "/subscriptions/dd91de05-d791-4ceb-b6dc-988682dc7d72/resourceGroups/alertslab","/subscriptions/dd91de05-d791-4ceb-b6dc-988682dc7d72/resourceGroups/Test-VMs" -SeverityCondition "Equals:Sev0,Sev1" -MonitorCondition "NotEquals:Resolved" -Description "Test description" -Status "Enabled" -ActionRuleType "ActionGroup" -ActionGroupId "/subscriptions/1e3ff1c0-771a-4119-a03b-be82a51e232d/resourceGroups/alertscorrelationrg/providers/Microsoft.insights/actiongroups/testAG"
66+
67+
Assert-NotNull $createdActionRule
68+
69+
# Update Status of Action Rule
70+
$updatedActionRule = Update-AzActionRule -ResourceGroupName $resourceGroupName -Name $actionRuleName -Status "Disabled"
71+
Assert-NotNull $updatedActionRule
72+
Assert-AreEqual "Disabled" $updatedActionRule.Status
73+
}
74+
finally
75+
{
76+
CleanUp $resourceGroupName $actionRuleName
77+
}
78+
}
79+
80+
function Test-CreateUpdateAndDeleteDiagnosticsRule
81+
{
82+
try
83+
{
84+
$resourceGroupName = Get-TestResourceGroupName "diag"
85+
$location = Get-ProviderLocation ResourceManagement
86+
$actionRuleName = Get-TestActionRuleName "diag"
87+
88+
#Create Resource Group
89+
New-AzResourceGroup -Name $resourceGroupName -Location $location -Force
90+
91+
$createdActionRule = Set-AzActionRule -ResourceGroupName $resourceGroupName -Name $actionRuleName -Scope "/subscriptions/dd91de05-d791-4ceb-b6dc-988682dc7d72/resourceGroups/alertslab","/subscriptions/dd91de05-d791-4ceb-b6dc-988682dc7d72/resourceGroups/Test-VMs" -SeverityCondition "Equals:Sev0,Sev1" -MonitorCondition "NotEquals:Resolved" -Description "Test description" -Status "Enabled" -ActionRuleType "Diagnostics"
92+
93+
Assert-NotNull $createdActionRule
94+
95+
# Update Status of Action Rule
96+
$updatedActionRule = Update-AzActionRule -ResourceGroupName $resourceGroupName -Name $actionRuleName -Status "Disabled"
97+
Assert-NotNull $updatedActionRule
98+
Assert-AreEqual "Disabled" $updatedActionRule.Status
99+
}
100+
finally
101+
{
102+
CleanUp $resourceGroupName $actionRuleName
103+
}
104+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
18+
using Xunit;
19+
using Microsoft.Azure.ServiceManagement.Common.Models;
20+
21+
namespace Microsoft.Azure.Commands.AlertsManagement.Test.ScenarioTests
22+
{
23+
public class AlertTests : RMTestBase
24+
{
25+
public XunitTracingInterceptor _logger;
26+
27+
public AlertTests(Xunit.Abstractions.ITestOutputHelper output)
28+
{
29+
_logger = new XunitTracingInterceptor(output);
30+
XunitTracingInterceptor.AddToContext(_logger);
31+
}
32+
33+
[Fact]
34+
[Trait(Category.AcceptanceType, Category.CheckIn)]
35+
public void TestAlertChangeState()
36+
{
37+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AlertChangeState");
38+
}
39+
40+
[Fact]
41+
[Trait(Category.AcceptanceType, Category.CheckIn)]
42+
public void TestGetAlertsFilteredByParameters()
43+
{
44+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetAlertsFilteredByParameters");
45+
}
46+
47+
[Fact]
48+
[Trait(Category.AcceptanceType, Category.CheckIn)]
49+
public void TestAlertsSummary()
50+
{
51+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AlertsSummary");
52+
}
53+
}
54+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
<#
16+
.SYNOPSIS
17+
Test Alerts Operations
18+
#>
19+
function Test-AlertChangeState
20+
{
21+
# Get latest alert
22+
$alerts = Get-AzAlert -State "New" -TimeRange 1h
23+
$alert = $alerts[0]
24+
25+
$oldState = $alert.State
26+
$newState = "Closed"
27+
$updatedAlert = Update-AzAlertState -AlertId $alert.Id -State $newState
28+
Assert-AreEqual $newState $updatedAlert.State
29+
30+
# Revert the state change operation
31+
$alert = Update-AzAlertState -AlertId $alert.Id -State $oldState
32+
}
33+
34+
function Test-AlertsSummary
35+
{
36+
$summary = Measure-AzAlertStatistic -GroupBy "severity,alertstate"
37+
38+
Assert-AreEqual "severity" $summary.GroupBy
39+
Assert-NotNull $summary.TotalAlerts
40+
41+
ForEach ($item in $summary.AggregatedCounts.Content){
42+
Assert-AreEqual "alertState" $item.GroupedBy
43+
Assert-NotNull $item.Count
44+
}
45+
}
46+
47+
function Test-GetAlertsFilteredByParameters
48+
{
49+
$severityFilter = "Sev3"
50+
$monitorServiceFilter = "Platform"
51+
$alerts = Get-AzAlert -Severity $severityFilter -MonitorService $monitorServiceFilter
52+
ForEach ($alert in $alerts){
53+
Assert-AreEqual $severityFilter $alert.Severity
54+
Assert-AreEqual $monitorServiceFilter $alert.MonitorService
55+
}
56+
}

0 commit comments

Comments
 (0)