Skip to content

Commit abc3847

Browse files
authored
{scheduled-query} Fix parse bug for --condition with " and ' in query (Azure#2995)
* fix parse bug for --condition * Update src/scheduled-query/HISTORY.rst
1 parent a4c8da4 commit abc3847

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

src/scheduled-query/HISTORY.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
33
Release History
44
===============
5+
0.2.2
6+
++++++
7+
* Fix parse bug for `--condition` parameter.
8+
59
0.2.0
610
++++++
711
* Adjust pattern for `--condition` parameter.
812

913
0.1.0
1014
++++++
11-
* Initial release.
15+
* Initial release.

src/scheduled-query/azext_scheduled_query/_help.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
Dimensions can be queried by adding the 'where' keyword and multiple dimensions can be queried by combining them with the 'and' keyword.
3636
examples:
3737
- name: Create a scheduled query for a VM.
38-
text: az monitor scheduled-query create -g {rg} -n {name1} --scopes {vm_id} --condition "count 'union Event, Syslog | where TimeGenerated > ago(1h) | where EventLevelName==\"Error\" or SeverityLevel==\"err\"' > 360 resource id _ResourceID at least 1 violations out of 5 aggregated points" --description "Test rule"
38+
text: az monitor scheduled-query create -g {rg} -n {name1} --scopes {vm_id} --condition "count 'union Event, Syslog | where TimeGenerated > ago(1h) | where EventLevelName==\\'Error\\' or SeverityLevel==\\'err\\'' > 360 resource id _ResourceID at least 1 violations out of 5 aggregated points" --description "Test rule"
3939
- name: Create a scheduled query for VMs in a resource group.
40-
text: az monitor scheduled-query create -g {rg} -n {name1} --scopes {rg_id} --condition "count 'union Event, Syslog | where TimeGenerated > ago(1h) | where EventLevelName==\"Error\" or SeverityLevel==\"err\"' > 360 resource id _ResourceID at least 1 violations out of 5 aggregated points" --description "Test rule"
40+
text: az monitor scheduled-query create -g {rg} -n {name1} --scopes {rg_id} --condition "count 'union Event, Syslog | where TimeGenerated > ago(1h) | where EventLevelName==\\'Error\\' or SeverityLevel==\\'err\\'' > 360 resource id _ResourceID at least 1 violations out of 5 aggregated points" --description "Test rule"
4141
"""
4242

4343
helps['monitor scheduled-query update'] = """

src/scheduled-query/azext_scheduled_query/grammar/scheduled_query/ScheduleQueryConditionValidator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ def exitThreshold(self, ctx):
5757

5858
# Exit a parse tree produced by MetricAlertConditionParser#threshold.
5959
def exitQuery(self, ctx):
60-
self.parameters['query'] = ctx.getText().strip()
60+
query = ctx.getText().strip()
61+
query = query.replace("\\\"", "\"")
62+
query = query.replace("\\\'", "\'")
63+
self.parameters['query'] = query
6164

6265
# Exit a parse tree produced by MetricAlertConditionParser#threshold.
6366
def exitResource_id(self, ctx):

src/scheduled-query/azext_scheduled_query/tests/latest/test_scheduled_query_scenario.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,19 @@ def test_monitor_scheduled_query_condition_action(self):
125125

126126
ns = self._build_namespace()
127127
self.call_condition(ns, 'avg "% Processor Time" from "Perf | where ObjectName == \\\"Processor\\\"" > 70 resource id resourceId')
128-
self.check_condition(ns, 'Average', 'Perf | where ObjectName == \\\"Processor\\\"', 'GreaterThan', '70', '% Processor Time', 'resourceId')
128+
self.check_condition(ns, 'Average', 'Perf | where ObjectName == \"Processor\"', 'GreaterThan', '70', '% Processor Time', 'resourceId')
129129

130130
ns = self._build_namespace()
131131
self.call_condition(ns, 'count "diagnostics | where Category == \\\"A\\\"| where SubscriptionId contains \\\"111\\\" | summarize count() by bin(TimeGenerated, 1m)" > 1')
132-
self.check_condition(ns, 'Count', 'diagnostics | where Category == \\\"A\\\"| where SubscriptionId contains \\\"111\\\" | summarize count() by bin(TimeGenerated, 1m)', 'GreaterThan', '1')
132+
self.check_condition(ns, 'Count', 'diagnostics | where Category == \"A\"| where SubscriptionId contains \"111\" | summarize count() by bin(TimeGenerated, 1m)', 'GreaterThan', '1')
133133

134134
ns = self._build_namespace()
135135
self.call_condition(ns, 'count "diagnostics | where Time > ago(3h) | where Category == \\\"manager\\\" | where not (log_s hasprefix \\\"I11\\\") | where log_s contains \\\"Code=1\\\" | summarize count(log_s) by bin(TimeGenerated, 1m)" > 10')
136-
self.check_condition(ns, 'Count', 'diagnostics | where Time > ago(3h) | where Category == \\\"manager\\\" | where not (log_s hasprefix \\\"I11\\\") | where log_s contains \\\"Code=1\\\" | summarize count(log_s) by bin(TimeGenerated, 1m)', 'GreaterThan', '10')
136+
self.check_condition(ns, 'Count', 'diagnostics | where Time > ago(3h) | where Category == \"manager\" | where not (log_s hasprefix \"I11\") | where log_s contains \"Code=1\" | summarize count(log_s) by bin(TimeGenerated, 1m)', 'GreaterThan', '10')
137137

138138
ns = self._build_namespace()
139139
self.call_condition(ns, 'avg "% Processor Time" from "Perf | where ObjectName == \\\"Processor\\\" and C>=D && E<<F" > 70 resource id resourceId where ApiName includes GetBlob or PutBlob and DpiName excludes CCC at least 1.1 violations out of 10.1 aggregated points')
140-
self.check_condition(ns, 'Average', 'Perf | where ObjectName == \\\"Processor\\\" and C>=D && E<<F', 'GreaterThan', '70', '% Processor Time', 'resourceId')
140+
self.check_condition(ns, 'Average', 'Perf | where ObjectName == \"Processor\" and C>=D && E<<F', 'GreaterThan', '70', '% Processor Time', 'resourceId')
141141
self.check_dimension(ns, 0, 'ApiName', 'Include', ['GetBlob', 'PutBlob'])
142142
self.check_dimension(ns, 1, 'DpiName', 'Exclude', ['CCC'])
143143
self.check_falling_period(ns, 1, 10)

src/scheduled-query/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# TODO: Confirm this is the right version number you want and it matches your
1818
# HISTORY.rst entry.
19-
VERSION = '0.2.1'
19+
VERSION = '0.2.2'
2020

2121
# The full list of classifiers is available at
2222
# https://pypi.python.org/pypi?%3Aaction=list_classifiers

0 commit comments

Comments
 (0)