Skip to content

Monitor schedule-query does not support new lines in the condition-query #23064

@davidbyoung

Description

@davidbyoung

Describe the bug
In Azure Monitor, we typically define queries with new line characters in them to make them more readable. However, when passing in queries with new line characters, only the very first line of the query is added.

To Reproduce
Here's my code:

$query = @"
AppRequests
| where AppRoleName startswith "test-api"
"@;
# Escape any quotes in the query
# Note: I've tried doing something like $query = $query.Replace("`n", "\n"); to get new line characters working, too, but that creates an invalid query per az monitor.
$query = $query.Replace('"', "\`"");
$args = @(
  '--resource-group="OUR_RESOURCE_GROUP_NAME"'
  '--name="Test"'
  '--condition="count ''Placeholder_1'' > 10000"'
  '--description="Test"'
  '--scopes="/subscriptions/OUR_SUBSCRIPTION_ID/resourcegroups/OUR_RESOURCE_GROUP_NAME/providers/microsoft.operationalinsights/workspaces/OUR_LOG_ANALYTICS_RESOURCE_NAME"'
  '--evaluation-frequency="360m"'
  '--window-size="360m"'
  '--severity=4'
  '--action="/subscriptions/OUR_SUBSCRIPTION_ID/resourceGroups/dashboards/providers/microsoft.insights/actionGroups/alert-rule-runbook"'
  '--subscription="OUR_SUBSCRIPTION_ID"'
  '--condition-query=Placeholder_1="' + $query + '"'
)

Write-Output @args

az monitor scheduled-query create @args

This will create an alert condition with just AppRequests in the query, not the entire query.

Expected behavior
An alert is created with the following query:

AppRequests
| where AppRoleName startswith "test-api"

Environment summary

MSI / 2.36.0 on Windows / Windows 11 / PowerShell

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions