Skip to content

feat: support "automitigate" parameter #14635

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

Merged
merged 2 commits into from
Mar 30, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,57 @@ public void NewMetricAlertRuleV2ByTargetResourceScopeActionGroupAndActionGroupId
It.IsAny<CancellationToken>()), Times.Once);
}


[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewMetricAlertRuleV2WithFalseAutoMitigateFlag()
{
_cmdlet.AutoMitigate = false;
_cmdlet.ExecuteCmdlet();

Func<MetricAlertResource, bool> verify = metricAlert =>
{
Assert.Equal(false, metricAlert.AutoMitigate);
return true;
};

this._insightsMetricAlertsOperationsMock.Verify(o => o.CreateOrUpdateWithHttpMessagesAsync(It.IsAny<string>(), It.IsAny<string>(), It.Is<MetricAlertResource>(r => verify(r)), It.IsAny<Dictionary<string, List<string>>>(),
It.IsAny<CancellationToken>()), Times.Once);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewMetricAlertRuleV2WithTrueAutoMitigateFlag()
{
_cmdlet.AutoMitigate = true; ;
_cmdlet.ExecuteCmdlet();

Func<MetricAlertResource, bool> verify = metricAlert =>
{
Assert.Equal(true, metricAlert.AutoMitigate);
return true;
};

this._insightsMetricAlertsOperationsMock.Verify(o => o.CreateOrUpdateWithHttpMessagesAsync(It.IsAny<string>(), It.IsAny<string>(), It.Is<MetricAlertResource>(r => verify(r)), It.IsAny<Dictionary<string, List<string>>>(),
It.IsAny<CancellationToken>()), Times.Once);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewMetricAlertRuleV2WithDefaultAutoMitigateFlag()
{
_cmdlet.ExecuteCmdlet();

Func<MetricAlertResource, bool> verify = metricAlert =>
{
Assert.Equal(true, metricAlert.AutoMitigate);
return true;
};

this._insightsMetricAlertsOperationsMock.Verify(o => o.CreateOrUpdateWithHttpMessagesAsync(It.IsAny<string>(), It.IsAny<string>(), It.Is<MetricAlertResource>(r => verify(r)), It.IsAny<Dictionary<string, List<string>>>(),
It.IsAny<CancellationToken>()), Times.Once);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewMetricAlertRuleV2WithWebtestConditionProcessing()
Expand Down
7 changes: 7 additions & 0 deletions src/Monitor/Monitor.Test/ScenarioTests/AlertsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ public void TestAddAzureRmMetricAlertRuleV2WithSkipMetricValidation()
TestsController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmMetricAlertRuleV2-SkipMetricValidation");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAddAzureRmMetricAlertRuleV2WithAutoMitigate()
{
TestsController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmMetricAlertRuleV2-autoMitigate");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestDisableAzureRmMetricAlertRuleV2WithActionGroups()
Expand Down
33 changes: 33 additions & 0 deletions src/Monitor/Monitor.Test/ScenarioTests/AlertsTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,39 @@ function Test-AddAzureRmMetricAlertRuleV2-skipMetricValidation
}


<#
.SYNOPSIS
Tests adding a GenV2 metric alert rule with AutoMitigate = false
#>
function Test-AddAzureRmMetricAlertRuleV2-autoMitigate
{
# Setup
$sub = Get-AzContext
$subscription = $sub.subscription.subscriptionId
$rgname = Get-ResourceGroupName
$location =Get-ProviderLocation ResourceManagement
$resourceName = Get-ResourceName
$ruleName = Get-ResourceName
$targetResourceId = '/subscriptions/'+$subscription+'/resourceGroups/'+$rgname+'/providers/Microsoft.Storage/storageAccounts/'+$resourceName
New-AzResourceGroup -Name $rgname -Location $location -Force
New-AzStorageAccount -ResourceGroupName $rgname -Name $resourceName -Location $location -Type Standard_GRS
$condition = New-AzMetricAlertRuleV2Criteria -MetricName "UsedCapacity" -Operator GreaterThan -Threshold 8 -TimeAggregation Average
try
{
# Test
$actual = Add-AzMetricAlertRuleV2 -Name $ruleName -ResourceGroupName $rgname -WindowSize 01:00:00 -Frequency 00:01:00 -TargetResourceId $targetResourceId -Condition $condition -Severity 3 -AutoMitigate $false
Assert-AreEqual $actual.Name $ruleName
}
finally
{
# Cleanup
Remove-AzMetricAlertRuleV2 -ResourceGroupName $rgname -Name $ruleName
Remove-AzureRmStorageAccount -ResourceGroupName $rgName -Name $resourceName
Remove-AzResourceGroup -Name $rgname -Force
}
}


<#
.SYNOPSIS
Tests disabling a GenV2 metric alert rule with action groups.
Expand Down
Loading