Skip to content

valid azure monitor query with asterisk * fails during cli create #17847

@cicorias

Description

@cicorias

Describe the bug

When attempting to create a query that has an asterisk as part of a string, for example in extract regular expression, the CLI fails. The Portal allows the exact same query to be setup exactly as is and works as a saved alert. We even attempted to use the same query/condition from az monitor scheduled-query show that is part of the json response.

Command Name
az monitor scheduled-query create

Condition used

The following is the parm to the --condition switch

count 'StorageBlobLogs  | where Uri has \'*\' | take 1 ' <= 0 resource id _ResourceID at least 1 violations out of 1 aggregated points

Valid Query
This query works OK in KQL/Azure Monitor logs -- note that this is a simplified repro of the condition. While this query seem simple it is. The real goal was a desire to use regular expressions in extract command from KQL which required an asterisk as part of the query.

In addition other symbols for regular expressions such as `+' fail too.

Errors:

line 1:42 mismatched input '*' expecting QUOTE
line 1:46 mismatched input '|' expecting OPERATOR
line 1:55 no viable alternative at input ' ''
usage error: --condition {avg,min,max,total,count} ["METRIC COLUMN" from]
                         "QUERY" {=,!=,>,>=,<,<=} THRESHOLD
                         [resource id RESOURCEID]
                         [where DIMENSION {includes,excludes} VALUE [or VALUE ...]
                         [and   DIMENSION {includes,excludes} VALUE [or VALUE ...] ...]]
                         [at least MinTimeToFail violations out of EvaluationPeriod aggregated points]

To Reproduce:

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

We tried even filling the file form @cond.txt

Neither work below

 az monitor scheduled-query create -g FOOBAR -n fizbuzz --scopes /subscriptions/GUID/resourcegroups/FOOBAR/providers/microsoft.operationalinsights/workspaces/LOGWORKSPACE --condition "count 'StorageBlobLogs  | where Uri has \'*\' | take 1 ' <= 0 resource id _ResourceID at least 1 violations out of 1 aggregated points" --description "Test rule"



 az monitor scheduled-query create -g spz-hot-path-dv-01 -n fizbuzz --scopes /subscriptions/GUID/resourcegroups/FOOBAR/providers/microsoft.operationalinsights/workspaces/LOGWORKSPACE --condition '@cond.txt' --description "Test rule"


## Expected Behavior
command succeeds - alert created.

## Environment Summary

Linux-5.4.72-microsoft-standard-WSL2-x86_64-with-debian-buster-sid
Python 3.6.10
Installer: DEB

azure-cli 2.19.1 *

Extensions:
azure-devops 0.18.0
scheduled-query 0.2.2
stream-analytics 0.1.0

## Additional Context

<!--Please don't remove this:-->
<!--auto-generated-->

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions