New-AzSchedulequeryRule Succesfull but not in the Protal

Klinger, Florian 36 Reputation points


i want to automate some AlertRules from Type "ScheduledQueryRule"

First i want to do this with ARM Template, but this failes because i can´t add an LogicApp Action, respectively when i do this, deployment failed (Bad Request)

Then i do this with Powershell and the Deployment works fine, but the Problem is, the Alert was unable to find in the Portal.

Here is my Code:

$tags = @{TagName = 'Value1';TagName2 = 'Value2'}

$Source = New-AzScheduledQueryRuleSource -Query 'AzureDiagnostics | where ResourceProvider == "MICROSOFT.AUTOMATION"| where StreamType_s == "Error" | project TimeGenerated, Category, JobId_g, OperationName, RunbookName_s, ResultDescription, _ResourceId' -DataSourceId "/subscriptions/***********************" -QueryType ResultCount
$TriggerMetric = New-AzScheduledQueryRuleLogMetricTrigger -ThresholdOperator GreaterThanOrEqual -Threshold "1" -MetricTriggerType Total -MetricColumn "_ResourceId"
$TriggerCondition = New-AzScheduledQueryRuleTriggerCondition -MetricTrigger $TriggerMetric -ThresholdOperator GreaterThan -Threshold 2
$aznsActionGroup = New-AzScheduledQueryRuleAznsActionGroup -ActionGroup @("/subscriptions/************************/resourcegroups/**********************/providers/microsoft.insights/actiongroups/****************") -EmailSubject "" -CustomWebhookPayload ""
$alertingAction = New-AzScheduledQueryRuleAlertingAction -AznsAction $aznsActionGroup -Severity "1" -Trigger $TriggerCondition
$schedule = New-AzScheduledQueryRuleSchedule -FrequencyInMinutes 60 -TimeWindowInMinutes 60

$scheduledQueryRule = New-AzScheduledQueryRule -Source $Source -Schedule $schedule -Action $alertingAction -Name "AA-Test" -Enabled $True -ResourceGroupName "TestGroup" -Description "Test" -Tag $tags -Location "westeurope"

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,015 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. SwathiDhanwada-MSFT 18,551 Reputation points

    @Klinger, Florian Welcome to Microsoft Q & A Community Forum. I have tested your code and I was able to create alert successfully and can see it in portal. There are two ways you can if alert has been created.

    • Traverse to Monitor -> Click Alerts ->select Manage Alert Rules -> search by typing alert name.
    • Go to Resource Group where alert should be created -> Check Show hidden types -> search by typing alert name.

    Kindly revert if you are still not noticing the alert which was created using PowerShell.

    0 comments No comments