Azure / Azure/azure-cli

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

Open
#23,064 1 comment 0 reactions 1 assignee Claimed by @kairu-ms View on GitHub
act-observability-squad Auto-Assign customer-reported Monitor
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

**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:

```powershell
$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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.