Azure / Azure/azure-powershell
New-AzScheduledQueryRule - AutoMitigate / MuteActionsDuration Errors
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 3d 14h
- Merged PRs (30d)
- 54
Description
### Description
When using the Set-AzScheduledQueryRule command to create/update a log analytics alert the command is failing with the below error when trying to se the MuteActionsDuration:
New-AzScheduledQueryRule : Auto mitigation must be disabled when action suppression is set
It seems that -AutoMitigate cannot be set to false which appears to be causing the issue.
### Issue script & Debug output
```PowerShell
$DebugPreference='Continue'
$subscriptionId=(Get-AzContext).Subscription.Id
$customProperty = @{}
$customProperty.Add('ResourceType', 'MicrosoftCompute/virtualmachines')
$dimension1 = New-AzScheduledQueryRuleDimensionObject -Name Computer -Operator Include -Value *
$dimension2 = New-AzScheduledQueryRuleDimensionObject -Name InstanceName -Operator Include -Value *
$condition=New-AzScheduledQueryRuleConditionObject -Dimension $dimension1,$dimension2 -Query "Perf | where ObjectName == `"LogicalDisk`" and CounterName == `"% Free Space`"" -TimeAggregation "Average" -MetricMeasureColumn "CounterValue" -Operator "LessThan" -Threshold "10" -FailingPeriodNumberOfEvaluationPeriod 1 -FailingPeriodMinFailingPeriodsToAlert 1
New-AzScheduledQueryRule -Name "Bethan-Test1" -ResourceGroupName "xxx" -Location "westeurope" -DisplayName "Bethan-Test1" -Scope "/subscriptions/$subscriptionId/resourceGroups/xxx/providers/Microsoft.OperationalInsights/workspaces/xxx" -Severity 4 -WindowSize ([System.TimeSpan]::New(0,15,0)) -EvaluationFrequency ([System.TimeSpan]::New(0,15,0)) -CriterionAllOf $condition -Description "Resource Purpose: Azure VM EN Non Prod" -ActionGroupResourceId "/subscriptions/xxx/resourceGroups/xxx/providers/microsoft.insights/actionGroups/BethanTest" -ActionCustomProperty $customProperty -MuteActionsDuration "06:00:00" -AutoMitigate
DEBUG: 4:48:46 PM - GetAzureRMContextCommand end processing.
DEBUG: AzureQoSEvent: Module: Az.Monitor:4.4.1; CommandName: New-AzScheduledQueryRuleDimensionObject; PSVersion: 5.1.19041.2673; IsSuccess: True; Duration: 00:00:00.0011177
DEBUG: AzureQoSEvent: Module: Az.Monitor:4.4.1; CommandName: New-AzScheduledQueryRuleDimensionObject; PSVersion: 5.1.19041.2673; IsSuccess: True; Duration: 00:00:00.0009995
DEBUG: AzureQoSEvent: Module: Az.Monitor:4.4.1; CommandName: New-AzScheduledQueryRuleConditionObject; PSVersion: 5.1.19041.2673; IsSuccess: True; Duration: 00:00:00.0009746
DEBUG: 4:48:47 PM - GetAzureRMContextCommand end processing.
DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing:
DEBUG: CmdletProcessRecordStart:
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated: /subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Insights/scheduledQueryRules/Bethan-Test1?api-version=2021-08-01
DEBUG: RequestCreated: /subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Insights/scheduledQueryRules/Bethan-Test1?api-version=2021-08-01
DEBUG: HeaderParametersAdded:
DEBUG: BodyContentSet:
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
PUT
Absolute Uri:
https://management.azure.com/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Insights/scheduledQueryRules/Bethan-Test1?api-version=2021-08-01
Headers:
x-ms-unique-id : 4
x-ms-client-request-id : 493a87d7-e4bc-4e81-8e74-92e6c3b72409
CommandName : New-AzScheduledQueryRule
FullCommandName : New-AzScheduledQueryRule_CreateExpanded
ParameterSetName : __AllParameterSets
User-Agent : AzurePowershell/v0.0.0,PSVersion/v5.1.19041.2673,Az.ScheduledQueryRule/4.4.1
Body:
{
"location": "westeurope",
"properties": {
"criteria": {
"allOf": [
{
"failingPeriods": {
"numberOfEvaluationPeriods": 1,
"minFailingPeriodsToAlert": 1
},
"query": "Perf | where ObjectName == \"LogicalDisk\" and CounterName == \"% Free Space\"",
"timeAggregation": "Average",
"metricMeasureColumn": "CounterValue",
"dimensions": [
{
"name": "Computer",
"operator": "Include",
"values": [
"*"
]
},
{
"name": "InstanceName",
"operator": "Include",
"values": [
"*"
]
}
],
"operator": "LessThan",
"threshold": 10
}
]
},
"actions": {
"actionGroups": [
"/subscriptions/xxx/resourceGroups/xxx/providers/microsoft.insights/actionGroups/BethanTest"
],
"customProperties": {
"ResourceType": "MicrosoftCompute/virtualmachines"
}
},
"description": "Resource Purpose: Azure VM EN Non Prod",
"displayName": "Bethan-Test1",
"severity": 4,
"scopes": [
"/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.OperationalInsights/workspaces/xxx"
],
"evaluationFrequency": "PT15M",
"windowSize": "PT15M",
"muteActionsDuration": "PT6H"
}
}
DEBUG: BeforeCall:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
BadRequest
Headers:
Pragma : no-cache
x-ms-ratelimit-remaining-subscription-writes: 1197
X-Rate-Limit-Limit : 1m
X-Rate-Limit-Remaining : 12
X-Rate-Limit-Reset : 2023-08-15T15:49:03.5198024Z
x-ms-request-id : 6851c731-dc09-428f-91c8-bf32989f0564
x-ms-correlation-request-id : 6851c731-dc09-428f-91c8-bf32989f0564
x-ms-routing-request-id : NORTHEUROPE:20230815T154847Z:6851c731-dc09-428f-91c8-bf32989f0564
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
Cache-Control : no-cache
Date : Tue, 15 Aug 2023 15:48:46 GMT
Server : Kestrel
Body:
{
"error": {
"code": "BadRequest",
"message": "Auto mitigation must be disabled when action suppression is set"
}
}
DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
New-AzScheduledQueryRule : Auto mitigation must be disabled when action suppression is set
At line:9 char:1
+ New-AzScheduledQueryRule -Name "Bethan-Test1" -ResourceGroupName "xx- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ({ SubscriptionI...PT6H"
}
} }:<>f__AnonymousType4`4) [New-AzScheduledQueryRule_CreateExpanded], Exception
+ FullyQualifiedErrorId : BadRequest,Microsoft.Azure.PowerShell.Cmdlets.Monitor.ScheduledQueryRule.Cmdlets.NewAzScheduledQueryRule_CreateExpanded
DEBUG: [Finally]: Getting exception 'Microsoft.Azure.Commands.Common.Exceptions.AzPSCloudException: InternalException' from response
DEBUG: Finally:
DEBUG: CmdletAfterAPICall:
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd:
DEBUG: CmdletProcessRecordEnd:
DEBUG: AzureQoSEvent: Module: Az.Monitor:4.4.1; CommandName: New-AzScheduledQueryRule; PSVersion: 5.1.19041.2673; IsSuccess: False; Duration: 00:00:00.7871548; Exception: InternalException;
##Subscritpion and resource names removed for security
```
### Environment data
```PowerShell
Name Value
---- -----
PSVersion 5.1.19041.2673
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.2673
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
```
### Module versions
```PowerShell
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 2.12.1 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault...}
Script 4.4.1 Az.Monitor {Add-AzLogProfile, Add-AzMetricAlertRule, Add-AzMetricAlertRuleV2, Add-AzWebtestAlertRule...}
Also ran with the below and got the same error:
Script 2.12.5 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault...}
Script 4.5.0 Az.Monitor {Add-AzLogProfile, Add-AzMetricAlertRule, Add-AzMetricAlertRuleV2, Add-AzWebtestAlertRule...}
```
### Error output
```PowerShell
HistoryId: 7
Message : [BadRequest] : Auto mitigation must be disabled when action suppression is set
StackTrace :
Exception : System.Exception
InvocationInfo : {New-AzScheduledQueryRule_CreateExpanded}
Line : New-AzScheduledQueryRule -Name "Bethan-Test1" -ResourceGroupName "xxx" -Location "westeurope" -DisplayName "Bethan-Test1" -Scope
"/subscriptions/$subscriptionId/resourceGroups/rxxx/providers/Microsoft.OperationalInsights/workspaces/log-en-nonprd-01" -Severity 4 -WindowSize ([System.TimeSpan]::New(0,15,0)) -EvaluationFrequency
([System.TimeSpan]::New(0,15,0)) -CriterionAllOf $condition -Description "Resource Purpose: Azure VM EN Non Prod" -ActionGroupResourceId
"/subscriptions/xxx/resourceGroups/xxx/providers/microsoft.insights/actionGroups/BethanTest" -ActionCustomProperty $customProperty -MuteActionsDuration "06:00:00"
Position : At line:9 char:1
+ New-AzScheduledQueryRule -Name "Bethan-Test1" -ResourceGroupName "xx- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 7
```
Contributor guide
Research direction
Start with the New-AzScheduledQueryRule command and the reproduced request body in the issue, focusing on how -AutoMitigate and -MuteActionsDuration are serialized. Compare the behavior with and without action suppression and verify the command can create or update the rule with the intended auto-mitigation setting without the API error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, powershell
- Domain
- api, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100