Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{Scheduled-query} Fix help message and update failure #7423

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/scheduled-query/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Release History
===============
1.0.0b1
++++++
* Fix update action group failure with empty actions
* Fix action group parameter help message

0.5.3
++++++
* Upgrade antlr to 4.13.1
Expand Down
3 changes: 0 additions & 3 deletions src/scheduled-query/azext_scheduled_query/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
short-summary: Update a scheduled query.
parameters:
- name: --action-groups
short-summary: Action Group resource Ids to invoke when the alert fires.
long-summary: |
Usage: --action-groups ACTION_GROUP_NAME_OR_ID [NAME_OR_ID,...]
- name: --custom-properties
short-summary: The properties of an alert payload.
long-summary: |
Expand Down
3 changes: 3 additions & 0 deletions src/scheduled-query/azext_scheduled_query/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def update_scheduled_query(cmd,
c.set_param('tags', tags)
c.set_param('enabled', not disabled)
c.set_param('description', description)
if instance.actions is None:
from azext_scheduled_query.vendored_sdks.azure_mgmt_scheduled_query.models import Actions
c.set_param("actions", Actions())
c.set_param('actions.action_groups', action_groups)
c.set_param('actions.custom_properties', custom_properties)
c.set_param('severity', severity)
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_scheduled_query(self, resource_group):
'action_group2': self.create_random_name('clitest', 20)
})
with mock.patch('azure.cli.command_modules.vm.custom._gen_guid', side_effect=self.create_guid):
vm = self.cmd('vm create -n {vm} -g {rg} --image UbuntuLTS --nsg-rule None --workspace {ws} --generate-ssh-keys').get_output_in_json()
vm = self.cmd('vm create -n {vm} -g {rg} --image Ubuntu2204 --nsg-rule None --workspace {ws} --generate-ssh-keys').get_output_in_json()
self.kwargs.update({
'vm_id': vm['id'],
'rg_id': resource_id(subscription=self.get_subscription_id(),
Expand Down Expand Up @@ -90,11 +90,11 @@ def test_scheduled_query(self, resource_group):
})
self.cmd('monitor scheduled-query create -g {rg} -n {name3} --scopes {rg_id} --condition "count \'union Event, Syslog | where TimeGenerated > ago(1h)\' > 360 resource id _ResourceId" --description "Test rule" --action-groups {action_group_id_1} --custom-properties k1=v1', checks=[
self.check('actions.actionGroups', [action_group_1['id']]),
self.check('actions.customProperties', {'k1':'v1'})
self.check('actions.customProperties', {'k1': 'v1'})
])
self.cmd('monitor scheduled-query update -g {rg} -n {name3} --action-groups {action_group_id_2} --custom-properties k2=v2', checks=[
self.check('actions.actionGroups', [action_group_2['id']]),
self.check('actions.customProperties', {'k2':'v2'})
self.check('actions.customProperties', {'k2': 'v2'})
])
self.cmd('monitor scheduled-query show -g {rg} -n {name1}',
checks=[
Expand All @@ -112,6 +112,90 @@ def test_scheduled_query(self, resource_group):
self.cmd('monitor scheduled-query show -g {rg} -n {name1}')


@ResourceGroupPreparer(name_prefix='cli_test_scheduled_query_update', location='eastus')
def test_scheduled_query_update_action_group(self, resource_group):
from azure.mgmt.core.tools import resource_id
import time
from unittest import mock
self.kwargs.update({
'name1': 'sq01',
'name2': 'sq02',
'rg': resource_group,
'vm': 'myvm1',
'ws': self.create_random_name('clitest', 20),
'action_group1': self.create_random_name('clitest', 20),
'action_group2': self.create_random_name('clitest', 20),
'action_group3': self.create_random_name('clitest', 20)
})
with mock.patch('azure.cli.command_modules.vm.custom._gen_guid', side_effect=self.create_guid):
vm = self.cmd('vm create -n {vm} -g {rg} --image Ubuntu2204 --nsg-rule None --workspace {ws} --generate-ssh-keys').get_output_in_json()
self.kwargs.update({
'vm_id': vm['id'],
'rg_id': resource_id(subscription=self.get_subscription_id(),
resource_group=resource_group),
'sub_id': resource_id(subscription=self.get_subscription_id(),
resource_group=resource_group),
})
action_group_1 = self.cmd('monitor action-group create -n {action_group1} -g {rg}').get_output_in_json()
action_group_2 = self.cmd('monitor action-group create -n {action_group2} -g {rg}').get_output_in_json()
action_group_3 = self.cmd('monitor action-group create -n {action_group3} -g {rg}').get_output_in_json()
self.kwargs.update({
'action_group_id_1': action_group_1['id'],
'action_group_id_2': action_group_2['id'],
'action_group_id_3': action_group_3['id']
})
self.cmd('monitor scheduled-query create -g {rg} -n {name1} --scopes {vm_id} --condition "count \'placeholder_1\' > 360" --condition-query placeholder_1="union Event, Syslog | where TimeGenerated > ago(1h)" --description "Test rule"',
checks=[
self.check('name', '{name1}'),
self.check('scopes[0]', '{vm_id}'),
self.check('severity', 2),
self.check('actions', None),
self.check('criteria.allOf[0].query', 'union Event, Syslog | where TimeGenerated > ago(1h)'),
self.check('criteria.allOf[0].threshold', 360),
self.check('criteria.allOf[0].timeAggregation', 'Count'),
self.check('criteria.allOf[0].operator', 'GreaterThan'),
self.check('criteria.allOf[0].failingPeriods.minFailingPeriodsToAlert', 1),
self.check('criteria.allOf[0].failingPeriods.numberOfEvaluationPeriods', 1),
self.check('criteria.allOf[0].failingPeriods.minFailingPeriodsToAlert', 1),
self.check('criteria.allOf[0].failingPeriods.numberOfEvaluationPeriods', 1),
self.check('autoMitigate', True),
self.check('skipQueryValidation', False),
self.check('checkWorkspaceAlertsStorageConfigured', False)
])
self.cmd('monitor scheduled-query update -g {rg} -n {name1} --description "Test rule 2" --severity 4 --disabled --evaluation-frequency 10m --window-size 10m',
checks=[
self.check('name', '{name1}'),
self.check('scopes[0]', '{vm_id}'),
self.check('severity', 4),
self.check('windowSize', '0:10:00'),
self.check('evaluationFrequency', '0:10:00')
])
self.cmd('monitor scheduled-query update -g {rg} -n {name1} --mad PT30M --auto-mitigate False --skip-query-validation True --action-groups {action_group_id_1} --custom-properties k1=v1',
checks=[
self.check('skipQueryValidation', True),
self.check('muteActionsDuration', '0:30:00'),
self.check('actions.actionGroups', [action_group_1['id']]),
self.check('actions.customProperties', {'k1': 'v1'}),
self.check('autoMitigate', False)
])

self.cmd('monitor scheduled-query create -g {rg} -n {name2} --scopes {rg_id} --condition "count \'union Event, Syslog | where TimeGenerated > ago(1h)\' > 360 resource id _ResourceId" --description "Test rule" --action-groups {action_group_id_1} --custom-properties k1=v1', checks=[
self.check('actions.actionGroups', [action_group_1['id']]),
self.check('actions.customProperties', {'k1':'v1'})
])

self.cmd('monitor scheduled-query update -g {rg} -n {name2} --action-groups {action_group_id_2} --custom-properties k2=v2', checks=[
self.check('actions.actionGroups', [action_group_2['id']]),
self.check('actions.customProperties', {'k2':'v2'})
])
self.cmd('monitor scheduled-query list -g {rg}',
checks=[
self.check('length(@)', 2)
])
self.cmd('monitor scheduled-query delete -g {rg} -n {name1} -y')
self.cmd('monitor scheduled-query delete -g {rg} -n {name2} -y')


@ResourceGroupPreparer(name_prefix='cli_test_scheduled_query_operator', location='eastus')
def test_scheduled_query_condition_operator(self, resource_group):
from azure.mgmt.core.tools import resource_id
Expand All @@ -124,7 +208,7 @@ def test_scheduled_query_condition_operator(self, resource_group):
'ws': self.create_random_name('clitest', 20),
})
with mock.patch('azure.cli.command_modules.vm.custom._gen_guid', side_effect=self.create_guid):
vm = self.cmd('vm create -n {vm} -g {rg} --image UbuntuLTS --nsg-rule None --workspace {ws} --generate-ssh-keys').get_output_in_json()
vm = self.cmd('vm create -n {vm} -g {rg} --image Ubuntu2204 --nsg-rule None --workspace {ws} --generate-ssh-keys').get_output_in_json()
self.kwargs.update({
'vm_id': vm['id'],
'rg_id': resource_id(subscription=self.get_subscription_id(),
Expand Down
2 changes: 1 addition & 1 deletion src/scheduled-query/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# TODO: Confirm this is the right version number you want and it matches your
# HISTORY.rst entry.
VERSION = '0.5.3'
VERSION = '1.0.0b1'

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