Skip to content

Commit

Permalink
Revert "[Scheduled-Query] update api version (Azure#3399)"
Browse files Browse the repository at this point in the history
This reverts commit 5ed250a.
  • Loading branch information
kairu-ms committed Jun 21, 2021
1 parent ff20eff commit 75217ef
Show file tree
Hide file tree
Showing 19 changed files with 2,060 additions and 1,669 deletions.
3 changes: 0 additions & 3 deletions src/scheduled-query/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ Release History
++++++
* Support query placeholder for `--condition` parameter.
* Add `--condition-query` parameter to support query placeholder.
* Add `--skip-query-validation` parameter
* Add `--check-ws-alerts-storage` parameter
* [Breaking Change] the default value of `--mute-actions-duration` is changed to None, as alert `--auto-mitigate` is supported

0.2.2
++++++
Expand Down
4 changes: 2 additions & 2 deletions src/scheduled-query/azext_scheduled_query/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

def cf_scheduled_query(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from .vendored_sdks.azure_mgmt_scheduled_query._monitor_management_client import MonitorManagementClient
return get_mgmt_service_client(cli_ctx, MonitorManagementClient).scheduled_query_rules
from .vendored_sdks.azure_mgmt_scheduled_query._monitor_client import MonitorClient
return get_mgmt_service_client(cli_ctx, MonitorClient).scheduled_query_rules
6 changes: 1 addition & 5 deletions src/scheduled-query/azext_scheduled_query/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long

from azure.cli.core.commands.parameters import tags_type, get_three_state_flag, get_enum_type
from azure.cli.core.commands.parameters import tags_type, get_three_state_flag
from azure.cli.command_modules.monitor.actions import get_period_type
from azure.cli.command_modules.monitor.validators import get_action_group_validator
from knack.arguments import CLIArgumentType
Expand All @@ -23,7 +23,6 @@ def load_arguments(self, _):
c.argument('severity', type=int, help='Severity of the alert from 0 (critical) to 4 (verbose).')
c.argument('window_size', type=get_period_type(), help='Time over which to aggregate metrics in "##h##m##s" format.')
c.argument('evaluation_frequency', type=get_period_type(), help='Frequency with which to evaluate the rule in "##h##m##s" format.')
c.argument('display_name', help='The display name of the alert rule')
c.argument('condition', options_list=['--condition'], action=ScheduleQueryConditionAction, nargs='+')
c.argument('condition_query', options_list=['--condition-query'], nargs='+', action=ScheduleQueryConditionQueryAction, help='Query deteils to replace the placeholders in `--condition` argument.')
c.argument('description', help='Free-text description of the rule.')
Expand All @@ -37,6 +36,3 @@ def load_arguments(self, _):
options_list=['--mute-actions-duration', '--mad'],
help='Mute actions for the chosen period of time (in ISO 8601 duration format) after the alert is fired.')
c.argument('actions', options_list=['--action', '-a'], action=ScheduleQueryAddAction, nargs='+', validator=get_action_group_validator('actions'))
c.argument('auto_mitigate', arg_type=get_three_state_flag(), help='The flag that indicates whether the alert should be automatically resolved or not. The default is true.')
c.argument('skip_query_validation', arg_type=get_three_state_flag(), help='The flag which indicates whether the provided query should be validated or not.')
c.argument('check_workspace_alerts_storage', options_list=['--check-ws-alerts-storage', '--cwas'], arg_type=get_three_state_flag(), help="The flag which indicates whether this scheduled query rule should be stored in the customer's storage.")
26 changes: 7 additions & 19 deletions src/scheduled-query/azext_scheduled_query/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ def _build_criteria(condition, condition_query):


def create_scheduled_query(client, resource_group_name, rule_name, scopes, condition, condition_query=None,
disabled=False, description=None, tags=None, location=None, display_name=None,
auto_mitigate=True, skip_query_validation=False, check_workspace_alerts_storage=False,
disabled=False, description=None, tags=None, location=None,
actions=None, severity=2, window_size='5m', evaluation_frequency='5m',
target_resource_type=None, mute_actions_duration=None):
target_resource_type=None, mute_actions_duration='PT30M'):
from .vendored_sdks.azure_mgmt_scheduled_query.models import ScheduledQueryRuleResource
criteria = _build_criteria(condition, condition_query)
kwargs = {
'display_name': display_name,
'description': description,
'severity': severity,
'enabled': not disabled,
Expand All @@ -45,10 +43,7 @@ def create_scheduled_query(client, resource_group_name, rule_name, scopes, condi
'actions': actions,
'tags': tags,
'location': location,
'mute_actions_duration': mute_actions_duration,
'check_workspace_alerts_storage_configured': check_workspace_alerts_storage,
'skip_query_validation': skip_query_validation,
'auto_mitigate': auto_mitigate,
'mute_actions_duration': mute_actions_duration
}
return client.create_or_update(resource_group_name, rule_name, ScheduledQueryRuleResource(**kwargs))

Expand All @@ -59,19 +54,12 @@ def list_scheduled_query(client, resource_group_name=None):
return client.list_by_subscription()


def update_scheduled_query(cmd, instance, tags=None, disabled=None, condition=None, condition_query=None,
description=None, actions=None, severity=None, window_size=None, display_name=None,
auto_mitigate=None, evaluation_frequency=None, mute_actions_duration=None,
skip_query_validation=None, check_workspace_alerts_storage=None):
def update_scheduled_query(cmd, instance, tags=None, disabled=False, condition=None, condition_query=None,
description=None, actions=None, severity=None, window_size=None,
evaluation_frequency=None, mute_actions_duration=None):
with cmd.update_context(instance) as c:
c.set_param('tags', tags)
c.set_param('display_name', display_name)
if disabled is not None:
c.set_param('enabled', not disabled)
if auto_mitigate is not None:
c.set_param('auto_mitigate', auto_mitigate)
c.set_param('skip_query_validation', skip_query_validation)
c.set_param('check_workspace_alerts_storage_configured', check_workspace_alerts_storage)
c.set_param('enabled', not disabled)
c.set_param('description', description)
c.set_param('actions', actions)
c.set_param('severity', severity)
Expand Down
Loading

0 comments on commit 75217ef

Please sign in to comment.