Azure / Azure/azure-cli

"mismatched input '/' expecting WHITESPACE" - az monitor metrics alert create throws error when specifying dimension availabilityResult/name

Open
#30,755 3 comments 0 reactions 1 assignee Claimed by @AllyW View on GitHub
act-observability-squad Auto-Assign Azure CLI Team customer-reported Monitor question Similar-Issue
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

### Describe the bug

Tested on version 2.57.0 and 2.68.0 (latest release)

I'm trying to create a metric alert which will fire if a standard web-test availability metric goes below 100%.
If I do not add a dimension, the rule creates successfully, with no errors.

If I add a dimension for Test Name, the azure cli seems to trip up on the required "/" in `availabilityResult/name`

I've tried escaping this using `\`, `//`, `(availabilityResult/name)`, `[availabilityResult].name`, `availabilityResult.name` but no luck.

Weirdly, despite the error print out, the rule does go off and create the dimension and alert rule successfully.

### Related command

az monitor metrics alert create

### Errors

```
Generated Condition: avg availabilityResults/availabilityPercentage < 100 where availabilityResult/name INCLUDES test-availability

az : line 1:77 mismatched input '/' expecting WHITESPACE
At line:10 char:1
+ az monitor metrics alert create `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (line 1:77 misma...ting WHITESPACE:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

```

### Issue script & Debug output

```
$condition = "avg availabilityResults/availabilityPercentage < 100 where availabilityResult/name INCLUDES $metricName"

az monitor metrics alert create `
--name "$alertName" `
--resource-group "$resourceGroup" `
--scopes "$appInsightsScope" `
--description "Alert if availability test '$metricName' fails in more than 2 regions" `
--condition "$condition" `
--evaluation-frequency "PT1M" `
--window-size "PT5M" `
--severity 0 `
--action "$devActionGroup" --debug
```

```
PS C:\WINDOWS\system32> az monitor metrics alert create `
--name "$alertName" `
--resource-group "$resourceGroup" `
--scopes "$appInsightsScope" `
--description "Alert if availability test '$metricName' fails in more than 2 regions" `
--condition "$condition" `
--evaluation-frequency "PT1M" `
--window-size "PT5M" `
--severity 0 `
--action "$devActionGroup" --debug
az : DEBUG: cli.knack.cli: Command arguments: ['monitor', 'metrics', 'alert', 'create', '--name', 'availability-alert', '--resource-group', 'Application-Insights', '--scopes',
'/subscriptions/xxx/resourceGroups/Application-Insights/providers/microsoft.insights/components/app-insights', '--description', "Alert if availability test 'my-live-availability' fails in more than 2
regions", '--condition', 'avg availabilityResults/availabilityPercentage < 100 where availabilityResult/name INCLUDES my-live-availability', '--evaluation-frequency', 'PT1M', '--window-size', 'PT5M', '--severity', '0', '--action',
'/subscriptions/xxx/resourceGroups/Application-Insights/providers/Microsoft.Insights/actiongroups/My-Action-Group', '--debug']
At line:1 char:1
+ az monitor metrics alert create `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (DEBUG: cli.knac...on', '--debug']:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

DEBUG: cli.knack.cli: __init__ debug log:
Cannot enable color.
DEBUG: cli.knack.cli: Event: Cli.PreExecute []
DEBUG: cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [, , ]
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
DEBUG: cli.azure.cli.core: Modules found from index for 'monitor': ['azure.cli.command_modules.monitor', 'azext_applicationinsights']
DEBUG: cli.azure.cli.core: Loading command modules:
DEBUG: cli.azure.cli.core: Name Load Time Groups Commands
DEBUG: cli.azure.cli.core: monitor 0.676 22 69
DEBUG: cli.azure.cli.core: Total (1) 0.676 22 69
DEBUG: cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
DEBUG: cli.azure.cli.core: Loading extensions:
DEBUG: cli.azure.cli.core: Name Load Time Groups Commands Directory
DEBUG: cli.azure.cli.core: application-insights 0.007 10 30 C:\Users\xxx\.azure\cliextensions\application-insights
DEBUG: cli.azure.cli.core: Total (1) 0.007 10 30
DEBUG: cli.azure.cli.core: Loaded 31 groups, 99 commands.
DEBUG: cli.azure.cli.core: Found a match in the command table.
DEBUG: cli.azure.cli.core: Raw command : monitor metrics alert create
DEBUG: cli.azure.cli.core: Command table: monitor metrics alert create
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate []
DEBUG: cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to 'C:\Users\xxx\.azure\commands\2025-02-04.09-10-26.monitor_metrics_alert_create.28372.log'.
INFO: az_command_data_logger: command args: monitor metrics alert create --name {} --resource-group {} --scopes {} --description {} --condition {} --evaluation-frequency {} --window-size {} --severity {} --action {} --debug
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [.add_subscription_parameter at 0x04975208>]
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [.add_ids_arguments at 0x0498E708>, .add_cache_arguments at 0x0499C8E8>]
DEBUG: cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
line 1:77 mismatched input '/' expecting WHITESPACE
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [, , .parse_ids_arguments at
0x0499C898>]
DEBUG: cli.azure.cli.core.commands.client_factory: Getting management service client client_type=MonitorManagementClient
DEBUG: cli.azure.cli.core.auth.persistence: build_persistence: location='C:\\Users\\xxx\\.azure\\msal_token_cache.bin', encrypt=True
DEBUG: cli.azure.cli.core.auth.binary_cache: load: C:\Users\xxx\.azure\msal_http_cache.bin
DEBUG: urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None)
DEBUG: msal.authority: openid_config = {'token_endpoint': 'https://login.microsoftonline.com/xxx/oauth2/v2.0/token', 'token_endpoint_auth_methods_supported': ['client_secret_post', 'private_key_jwt',
'client_secret_basic'], 'jwks_uri': 'https://login.microsoftonline.com/xxx/discovery/v2.0/keys', 'response_modes_supported': ['query', 'fragment', 'form_post'], 'subject_types_supported': ['pairwise'],
'id_token_signing_alg_values_supported': ['RS256'], 'response_types_supported': ['code', 'id_token', 'code id_token', 'id_token token'], 'scopes_supported': ['openid', 'profile', 'email', 'offline_access'], 'issuer':
'https://login.microsoftonline.com/xxx/v2.0', 'request_uri_parameter_supported': False, 'userinfo_endpoint': 'https://graph.microsoft.com/oidc/userinfo', 'authorization_endpoint':
'https://login.microsoftonline.com/xxx/oauth2/v2.0/authorize', 'device_authorization_endpoint': 'https://login.microsoftonline.com/xxx/oauth2/v2.0/devicecode', 'http_logout_supported':
True, 'frontchannel_logout_supported': True, 'end_session_endpoint': 'https://login.microsoftonline.com/xxx/oauth2/v2.0/logout', 'claims_supported': ['sub', 'iss', 'cloud_instance_name', 'cloud_instance_host_name',
'cloud_graph_host_name', 'msgraph_host', 'aud', 'exp', 'iat', 'auth_time', 'acr', 'nonce', 'preferred_username', 'name', 'tid', 'ver', 'at_hash', 'c_hash', 'email'], 'kerberos_endpoint':
'https://login.microsoftonline.com/xxx/kerberos', 'tenant_region_scope': 'EU', 'cloud_instance_name': 'microsoftonline.com', 'cloud_graph_host_name': 'graph.windows.net', 'msgraph_host': 'graph.microsoft.com', 'rbac_url':
'https://pas.windows.net'}
DEBUG: msal.application: Broker enabled? False
DEBUG: urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None)
DEBUG: msal.authority: openid_config = {'token_endpoint': 'https://login.microsoftonline.com/xxx/oauth2/v2.0/token', 'token_endpoint_auth_methods_supported': ['client_secret_post', 'private_key_jwt',
'client_secret_basic'], 'jwks_uri': 'https://login.microsoftonline.com/xxx/discovery/v2.0/keys', 'response_modes_supported': ['query', 'fragment', 'form_post'], 'subject_types_supported': ['pairwise'],
'id_token_signing_alg_values_supported': ['RS256'], 'response_types_supported': ['code', 'id_token', 'code id_token', 'id_token token'], 'scopes_supported': ['openid', 'profile', 'email', 'offline_access'], 'issuer':
'https://login.microsoftonline.com/xxx/v2.0', 'request_uri_parameter_supported': False, 'userinfo_endpoint': 'https://graph.microsoft.com/oidc/userinfo', 'authorization_endpoint':
'https://login.microsoftonline.com/xxx/oauth2/v2.0/authorize', 'device_authorization_endpoint': 'https://login.microsoftonline.com/xxx/oauth2/v2.0/devicecode', 'http_logout_supported':
True, 'frontchannel_logout_supported': True, 'end_session_endpoint': 'https://login.microsoftonline.com/xxx/oauth2/v2.0/logout', 'claims_supported': ['sub', 'iss', 'cloud_instance_name', 'cloud_instance_host_name',
'cloud_graph_host_name', 'msgraph_host', 'aud', 'exp', 'iat', 'auth_time', 'acr', 'nonce', 'preferred_username', 'name', 'tid', 'ver', 'at_hash', 'c_hash', 'email'], 'kerberos_endpoint':
'https://login.microsoftonline.com/xxx/kerberos', 'tenant_region_scope': 'EU', 'cloud_instance_name': 'microsoftonline.com', 'cloud_graph_host_name': 'graph.windows.net', 'msgraph_host': 'graph.microsoft.com', 'rbac_url':
'https://pas.windows.net'}
DEBUG: msal.application: Broker enabled? False
DEBUG: cli.azure.cli.core.auth.credential_adaptor: CredentialAdaptor.get_token: scopes=('https://management.core.windows.net//.default',), kwargs={}
DEBUG: cli.azure.cli.core.auth.msal_authentication: UserCredential.get_token: scopes=('https://management.core.windows.net//.default',), claims=None, kwargs={}
DEBUG: msal.application: Cache hit an AT
DEBUG: msal.telemetry: Generate or reuse correlation_id: aaaaaaaa-ada7-454f-a221-e614e7dd9c0c
DEBUG: cli.azure.cli.core.sdk.policies: Request URL:
'https://management.azure.com/subscriptions/xxx/resourceGroups/Application-Insights/providers/Microsoft.Insights/metricAlerts/live-availability-alert?api-version=2018-03-01'
DEBUG: cli.azure.cli.core.sdk.policies: Request method: 'PUT'
DEBUG: cli.azure.cli.core.sdk.policies: Request headers:
DEBUG: cli.azure.cli.core.sdk.policies: 'Content-Type': 'application/json'
DEBUG: cli.azure.cli.core.sdk.policies: 'Accept': 'application/json'
DEBUG: cli.azure.cli.core.sdk.policies: 'Content-Length': '1017'
DEBUG: cli.azure.cli.core.sdk.policies: 'x-ms-client-request-id': 'defd23cd-e2d7-11ef-bebe-ac74b18486ee'
DEBUG: cli.azure.cli.core.sdk.policies: 'CommandName': 'monitor metrics alert create'
DEBUG: cli.azure.cli.core.sdk.policies: 'ParameterSetName': '--name --resource-group --scopes --description --condition --evaluation-frequency --window-size --severity --action --debug'
DEBUG: cli.azure.cli.core.sdk.policies: 'User-Agent': 'AZURECLI/2.57.0 (MSI) (AAZ) azsdk-python-core/1.28.0 Python/3.11.7 (Windows-10-10.0.26100-SP0)'
DEBUG: cli.azure.cli.core.sdk.policies: 'Authorization': '*****'
DEBUG: cli.azure.cli.core.sdk.policies: Request body:
DEBUG: cli.azure.cli.core.sdk.policies: {"location": "global", "properties": {"actions": [{"actionGroupId":
"/subscriptions/xxx/resourceGroups/Application-Insights/providers/Microsoft.Insights/actiongroups/MyActionGroup"}], "criteria": {"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
"allOf": [{"criterionType": "StaticThresholdCriterion", "dimensions": [{"name": "availabilityResult/name", "operator": "Include", "values": ["my-live-availability"]}], "metricName": "availabilityResults/availabilityPercentage", "name":
"cond0", "operator": "LessThan", "threshold": 100.0, "timeAggregation": "Average"}]}, "description": "Alert if availability test 'live-availability' fails in more than 2 regions", "enabled": true, "evaluationFrequency": "PT1M",
"scopes": ["/subscriptions/xxx/resourceGroups/Application-Insights/providers/microsoft.insights/components/app-insights"], "severity": 0, "windowSize": "PT5M"}}
DEBUG: urllib3.connectionpool: Starting new HTTPS connection (1): management.azure.com:443
DEBUG: urllib3.connectionpool: https://management.azure.com:443 "PUT
/subscriptions/xxx/resourceGroups/Application-Insights/providers/Microsoft.Insights/metricAlerts/my-live-availability-alert?api-version=2018-03-01 HTTP/1.1" 200 1652
DEBUG: cli.azure.cli.core.sdk.policies: Response status: 200
DEBUG: cli.azure.cli.core.sdk.policies: Response headers:
DEBUG: cli.azure.cli.core.sdk.policies: 'Cache-Control': 'no-cache'
DEBUG: cli.azure.cli.core.sdk.policies: 'Pragma': 'no-cache'
DEBUG: cli.azure.cli.core.sdk.policies: 'Content-Length': '1652'
DEBUG: cli.azure.cli.core.sdk.policies: 'Content-Type': 'application/json; charset=utf-8'
DEBUG: cli.azure.cli.core.sdk.policies: 'Expires': '-1'
DEBUG: cli.azure.cli.core.sdk.policies: 'Vary': 'Accept-Encoding'
DEBUG: cli.azure.cli.core.sdk.policies: 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
DEBUG: cli.azure.cli.core.sdk.policies: 'x-ms-request-id': '4064a58c-a0f6-4e61-a773-71ab3819b622, 4064a58c-a0f6-4e61-a773-71ab3819b622'
DEBUG: cli.azure.cli.core.sdk.policies: 'api-supported-versions': '2017-09-01-preview, 2018-03-01, 2024-01-01-preview'
DEBUG: cli.azure.cli.core.sdk.policies: 'Arr-Disable-Session-Affinity': 'true'
DEBUG: cli.azure.cli.core.sdk.policies: 'X-Content-Type-Options': 'nosniff'
DEBUG: cli.azure.cli.core.sdk.policies: 'X-AspNet-Version': '4.0.30319'
DEBUG: cli.azure.cli.core.sdk.policies: 'X-Powered-By': 'ASP.NET'
DEBUG: cli.azure.cli.core.sdk.policies: 'x-ms-ratelimit-remaining-subscription-resource-requests': '299'
DEBUG: cli.azure.cli.core.sdk.policies: 'x-ms-correlation-request-id': '4064a58c-a0f6-4e61-a773-71ab3819b622'
DEBUG: cli.azure.cli.core.sdk.policies: 'x-ms-routing-request-id': 'UKSOUTH:20250204T091028Z:4064a58c-a0f6-4e61-a773-71ab3819b622'
DEBUG: cli.azure.cli.core.sdk.policies: 'X-Cache': 'CONFIG_NOCACHE'
DEBUG: cli.azure.cli.core.sdk.policies: 'X-MSEdge-Ref': 'Ref A: 63534B490B224A88A1B3F00CE24CA790 Ref B: AMS231020615039 Ref C: 2025-02-04T09:10:27Z'
DEBUG: cli.azure.cli.core.sdk.policies: 'Date': 'Tue, 04 Feb 2025 09:10:27 GMT'
DEBUG: cli.azure.cli.core.sdk.policies: Response content:
DEBUG: cli.azure.cli.core.sdk.policies: {
"id": "/subscriptions/xxx/resourceGroups/Application-Insights/providers/Microsoft.Insights/metricAlerts/live-availability-alert",
"name": "live-availability-alert",
"type": "Microsoft.Insights/metricAlerts",
"location": "global",
"properties": {
"description": "Alert if availability test 'my-live-availability' fails in more than 2 regions",
"severity": 0,
"enabled": true,
"scopes": [
"/subscriptions/xxx/resourceGroups/Application-Insights/providers/microsoft.insights/components/app-insights"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT5M",
"criteria": {
"allOf": [
{
"threshold": 100.0,
"name": "cond0",
"metricName": "availabilityResults/availabilityPercentage",
"dimensions": [
{
"name": "availabilityResult/name",
"operator": "Include",
"values": [
"my-live-availability"
]
}
],
"operator": "LessThan",
"timeAggregation": "Average",
"criterionType": "StaticThresholdCriterion"
}
],
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria"
},
"actions": [
{
"actionGroupId": "/subscriptions/xxx/resourceGroups/Application-Insights/providers/Microsoft.Insights/actiongroups/MyActionGroup"
}
]
}
}
DEBUG: cli.knack.cli: Event: CommandInvoker.OnTransformResult [, ]
DEBUG: cli.knack.cli: Event: CommandInvoker.OnFilterResult []
DEBUG: cli.knack.cli: Event: Cli.SuccessfulExecute []
DEBUG: cli.knack.cli: Event: Cli.PostExecute []
INFO: az_command_data_logger: exit code: 0
INFO: cli.__main__: Command ran in 3.542 seconds (init: 0.560, invoke: 2.982)
INFO: cli.azure.cli.core.decorators: Suppress exception:
Traceback (most recent call last):
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/__main__.py", line 62, in
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/__main__.py", line 55, in
SystemExit: 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/decorators.py", line 79, in _wrapped_func
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/telemetry.py", line 532, in _get_secrets_warning_config
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/config.py", line 147, in getboolean
ValueError: Not a boolean: None
INFO: telemetry.main: Begin splitting cli events and extra events, total events: 1
INFO: telemetry.client: Accumulated 0 events. Flush the clients.
INFO: telemetry.main: Finish splitting cli events and extra events, cli events: 1
INFO: telemetry.save: Save telemetry record of length 3468 in cache
INFO: telemetry.main: Begin creating telemetry upload process.
INFO: telemetry.process: Creating upload process: "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\Lib\site-packages\azure\cli\telemetry\__init__.pyc C:\Users\xxx\.azure"
INFO: telemetry.process: Return from creating process
INFO: telemetry.main: Finish creating telemetry upload process.
```

### Expected behavior

No error returned as "/" is valid.

It might be related to similar problems that were addressed in versions:
2.2.0 - az monitor metrics alert create: support ~ in --condition
2.50.0 - az monitor metrics alert create: Add () into --condition grammar

Maybe we need a new release that adds support for "/" in the condition grammar?

### Environment Summary

azure-cli 2.68.0

core 2.68.0
telemetry 1.1.0

Extensions:
aks-preview 0.5.136
application-insights 0.1.15
azure-devops 0.25.0
kusto 0.5.0

Dependencies:
msal 1.31.1
azure-mgmt-resource 23.1.1

Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
Extensions directory 'C:\Users\tscamell\.azure\cliextensions'

Python (Windows) 3.12.8 (tags/v3.12.8:2dc476b, Dec 3 2024, 19:07:15) [MSC v.1942 32 bit (Intel)]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

### Additional context

_No response_

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.