Skip to content

Commit a0c45a7

Browse files
authored
{Monitor} Apply single api of azure-mgmt-monitor sdk (#30824)
1 parent 7481ead commit a0c45a7

12 files changed

Lines changed: 9 additions & 177 deletions

File tree

src/azure-cli-core/azure/cli/core/profiles/_shared.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -220,39 +220,7 @@ def default_api_version(self):
220220
ResourceType.DATA_COSMOS_TABLE: '2017-04-17',
221221
ResourceType.MGMT_SERVICEBUS: '2022-10-01-preview',
222222
ResourceType.MGMT_EVENTHUB: '2022-01-01-preview',
223-
ResourceType.MGMT_MONITOR: SDKProfile('2019-06-01', {
224-
'action_groups': '2022-06-01',
225-
'activity_log_alerts': '2017-04-01',
226-
'activity_logs': '2015-04-01',
227-
'alert_rule_incidents': '2016-03-01',
228-
'alert_rules': '2016-03-01',
229-
'autoscale_settings': '2022-10-01',
230-
'baseline': '2018-09-01',
231-
'baselines': '2019-03-01',
232-
'diagnostic_settings': '2021-05-01-preview',
233-
'diagnostic_settings_category': '2017-05-01-preview',
234-
'event_categories': '2015-04-01',
235-
'guest_diagnostics_settings': '2018-06-01-preview',
236-
'guest_diagnostics_settings_association': '2018-06-01-preview',
237-
'log_profiles': '2016-03-01',
238-
'metric_alerts': '2018-03-01',
239-
'metric_alerts_status': '2018-03-01',
240-
'metric_baseline': '2018-09-01',
241-
'metric_definitions': '2018-01-01',
242-
'metric_namespaces': '2017-12-01-preview',
243-
'metrics': '2018-01-01',
244-
'operations': '2015-04-01',
245-
'scheduled_query_rules': '2018-04-16',
246-
'service_diagnostic_settings': '2016-09-01',
247-
'tenant_activity_logs': '2015-04-01',
248-
'vm_insights': '2018-11-27-preview',
249-
'private_link_resources': '2019-10-17-preview',
250-
'private_link_scoped_resources': '2019-10-17-preview',
251-
'private_link_scope_operation_status': '2019-10-17-preview',
252-
'private_link_scopes': '2019-10-17-preview',
253-
'private_endpoint_connections': '2019-10-17-preview',
254-
'subscription_diagnostic_settings': '2017-05-01-preview'
255-
}),
223+
ResourceType.MGMT_MONITOR: None,
256224
ResourceType.MGMT_MSI: '2023-01-31',
257225
ResourceType.MGMT_APPSERVICE: '2023-01-01',
258226
ResourceType.MGMT_IOTHUB: '2023-06-30-preview',

src/azure-cli/azure/cli/command_modules/monitor/_client_factory.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ def cf_monitor(cli_ctx, **kwargs):
1111
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_MONITOR, **kwargs)
1212

1313

14-
def cf_alert_rules(cli_ctx, _):
15-
return cf_monitor(cli_ctx).alert_rules
16-
17-
1814
def cf_alert_rule_incidents(cli_ctx, _):
1915
return cf_monitor(cli_ctx).alert_rule_incidents
2016

src/azure-cli/azure/cli/command_modules/monitor/_params.py

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
from azure.cli.core.commands.validators import get_default_location_from_resource_group
1111

1212
from azure.cli.command_modules.monitor.actions import (
13-
AlertAddAction, AlertRemoveAction, ConditionAction,
1413
AutoscaleScaleAction, AutoscaleConditionAction, get_period_type, AutoscaleCreateAction,
1514
timezone_offset_type, timezone_name_type, MetricAlertConditionAction, MetricAlertAddAction)
16-
from azure.cli.command_modules.monitor.util import get_operator_map, get_aggregation_map
1715
from azure.cli.command_modules.monitor.validators import (
1816
validate_loganalytics_workspace_search_table_name, validate_loganalytics_workspace_restore_table_name,
1917
validate_autoscale_recurrence, validate_autoscale_timegrain, get_action_group_validator,
@@ -25,7 +23,7 @@
2523

2624
# pylint: disable=line-too-long, too-many-statements
2725
def load_arguments(self, _):
28-
from azure.mgmt.monitor.models import ConditionOperator, TimeAggregationOperator, EventData, PredictiveAutoscalePolicyScaleMode
26+
from azure.mgmt.monitor.models import EventData, PredictiveAutoscalePolicyScaleMode
2927
from .grammar.metric_alert.MetricAlertConditionValidator import dim_op_conversion, agg_conversion, op_conversion, sens_conversion
3028
name_arg_type = CLIArgumentType(options_list=['--name', '-n'], metavar='NAME')
3129

@@ -37,54 +35,6 @@ def load_arguments(self, _):
3735
c.argument('location', get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group)
3836
c.argument('tags', tags_type)
3937

40-
# region Alerts
41-
with self.argument_context('monitor alert') as c:
42-
c.argument('rule_name', name_arg_type, id_part='name', help='Name of the alert rule.')
43-
44-
with self.argument_context('monitor alert create') as c:
45-
c.resource_parameter('target', arg_group='Target Resource', alias='target', preserve_resource_group_parameter=True)
46-
c.argument('rule_name', name_arg_type, id_part='name', help='Name of the alert rule.')
47-
c.argument('disabled', arg_type=get_three_state_flag())
48-
c.argument('condition', action=ConditionAction, nargs='+')
49-
50-
with self.argument_context('monitor alert create', arg_group='Action') as c:
51-
c.argument('custom_emails', nargs='+')
52-
c.argument('email_service_owners', arg_type=get_three_state_flag())
53-
c.argument('actions', options_list=['--action', '-a'], action=AlertAddAction, nargs='+')
54-
55-
with self.argument_context('monitor alert create', arg_group='Condition') as c:
56-
c.argument('metric_name')
57-
c.argument('operator', arg_type=get_enum_type(ConditionOperator))
58-
c.argument('threshold')
59-
c.argument('time_aggregation', arg_type=get_enum_type(TimeAggregationOperator))
60-
c.argument('window_size')
61-
62-
with self.argument_context('monitor alert update') as c:
63-
c.argument('rule_name', name_arg_type, id_part='name', help='Name of the alert rule.')
64-
c.resource_parameter('target', arg_group='Target Resource', required=False, preserve_resource_group_parameter=True)
65-
66-
with self.argument_context('monitor alert update', arg_group='Action') as c:
67-
c.argument('email_service_owners', arg_type=get_three_state_flag())
68-
c.argument('add_actions', options_list=['--add-action', '-a'], nargs='+', action=AlertAddAction)
69-
c.argument('remove_actions', options_list=['--remove-action', '-r'], nargs='+', action=AlertRemoveAction)
70-
71-
with self.argument_context('monitor alert update', arg_group='Condition') as c:
72-
c.argument('condition', action=ConditionAction, nargs='+')
73-
c.argument('metric')
74-
c.argument('operator', arg_type=get_enum_type(get_operator_map().keys()))
75-
c.argument('threshold')
76-
c.argument('aggregation', arg_type=get_enum_type(get_aggregation_map().keys()))
77-
c.argument('period', type=get_period_type())
78-
79-
for scope in ['monitor alert show-incident', 'monitor alert list-incidents']:
80-
with self.argument_context(scope) as c:
81-
c.argument('rule_name', options_list=['--rule-name'], id_part='name')
82-
c.argument('incident_name', name_arg_type, id_part='child_name_1')
83-
84-
with self.argument_context('monitor alert list-incidents') as c:
85-
c.argument('rule_name', options_list=['--rule-name'], id_part=None)
86-
# endregion
87-
8838
# region Metrics
8939
with self.argument_context('monitor metrics') as c:
9040
c.argument('metricnamespace', options_list=['--namespace'], help='Namespace to query metric definitions for.')

src/azure-cli/azure/cli/command_modules/monitor/actions.py

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
from knack.arguments import CLIArgumentType
1111
from knack.log import get_logger
1212
from knack.util import CLIError
13-
from azure.cli.command_modules.monitor.util import (
14-
get_aggregation_map, get_operator_map, get_autoscale_scale_direction_map)
13+
from azure.cli.command_modules.monitor.util import get_autoscale_scale_direction_map
1514

1615
from azure.cli.core.azclierror import InvalidArgumentValueError
1716
from azure.cli.core.aaz._arg import AAZCompoundTypeArg, AAZListType
@@ -211,54 +210,6 @@ def __call__(self, parser, namespace, values, option_string=None):
211210
super().__call__(parser, namespace, action, option_string)
212211

213212

214-
# pylint: disable=too-few-public-methods
215-
class ConditionAction(argparse.Action):
216-
def __call__(self, parser, namespace, values, option_string=None):
217-
from azure.mgmt.monitor.models import ThresholdRuleCondition, RuleMetricDataSource
218-
# get default description if not specified
219-
if namespace.description is None:
220-
namespace.description = ' '.join(values)
221-
if len(values) == 1:
222-
# workaround because CMD.exe eats > character... Allows condition to be
223-
# specified as a quoted expression
224-
values = values[0].split(' ')
225-
if len(values) < 5:
226-
raise InvalidArgumentValueError(
227-
'--condition METRIC {>,>=,<,<=} THRESHOLD {avg,min,max,total,last} DURATION')
228-
metric_name = ' '.join(values[:-4])
229-
operator = get_operator_map()[values[-4]]
230-
threshold = int(values[-3])
231-
aggregation = get_aggregation_map()[values[-2].lower()]
232-
window = get_period_type()(values[-1])
233-
metric = RuleMetricDataSource(resource_uri=None, metric_name=metric_name) # target URI will be filled in later
234-
condition = ThresholdRuleCondition(
235-
operator=operator, threshold=threshold, data_source=metric,
236-
window_size=window, time_aggregation=aggregation)
237-
namespace.condition = condition
238-
239-
240-
# pylint: disable=protected-access
241-
class AlertAddAction(argparse._AppendAction):
242-
def __call__(self, parser, namespace, values, option_string=None):
243-
action = self.get_action(values, option_string)
244-
super().__call__(parser, namespace, action, option_string)
245-
246-
def get_action(self, values, option_string): # pylint: disable=no-self-use
247-
_type = values[0].lower()
248-
if _type == 'email':
249-
from azure.mgmt.monitor.models import RuleEmailAction
250-
return RuleEmailAction(custom_emails=values[1:])
251-
if _type == 'webhook':
252-
from azure.mgmt.monitor.models import RuleWebhookAction
253-
uri = values[1]
254-
try:
255-
properties = dict(x.split('=', 1) for x in values[2:])
256-
except ValueError:
257-
raise InvalidArgumentValueError('{} webhook URI [KEY=VALUE ...]'.format(option_string))
258-
return RuleWebhookAction(service_uri=uri, properties=properties)
259-
raise InvalidArgumentValueError('usage error: {} TYPE KEY [ARGS]'.format(option_string))
260-
261-
262213
class AlertRemoveAction(argparse._AppendAction):
263214
def __call__(self, parser, namespace, values, option_string=None):
264215
action = self.get_action(values, option_string)

src/azure-cli/azure/cli/command_modules/monitor/commands.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# pylint: disable=line-too-long, too-many-locals, too-many-statements
99
def load_command_table(self, _):
1010
from ._client_factory import (
11-
cf_alert_rules, cf_autoscale,
11+
cf_autoscale,
1212
cf_action_groups, cf_event_categories,
1313
cf_metric_alerts, cf_log_analytics_workspace, cf_log_analytics_linked_storage)
1414
from .transformers import (action_group_list_table)
@@ -52,8 +52,6 @@ def load_command_table(self, _):
5252

5353
alert_custom = CliCommandType(
5454
operations_tmpl='azure.cli.command_modules.monitor.operations.metric_alert#{}',
55-
client_factory=cf_alert_rules,
56-
operation_group='alert_rules',
5755
exception_handler=exception_handler)
5856

5957
metric_alert_sdk = CliCommandType(

src/azure-cli/azure/cli/command_modules/monitor/operations/metric_alert.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -321,24 +321,6 @@ def create_metric_alert_condition(condition_type, aggregation, metric_name, oper
321321
return condition.strip()
322322

323323

324-
def _parse_actions(actions):
325-
""" Actions come in as a combined list. This method separates the webhook actions into a
326-
separate collection and combines any number of email actions into a single email collection
327-
and a single value for `email_service_owners`. If any email action contains a True value
328-
for `send_to_service_owners` then it is assumed the entire value should be True. """
329-
from azure.mgmt.monitor.models import RuleEmailAction, RuleWebhookAction
330-
actions = actions or []
331-
email_service_owners = None
332-
webhooks = [x for x in actions if isinstance(x, RuleWebhookAction)]
333-
custom_emails = set()
334-
for action in actions:
335-
if isinstance(action, RuleEmailAction):
336-
if action.send_to_service_owners:
337-
email_service_owners = True
338-
custom_emails = custom_emails | set(action.custom_emails)
339-
return list(custom_emails), webhooks, email_service_owners
340-
341-
342324
def _parse_action_removals(actions):
343325
""" Separates the combined list of keys to remove into webhooks and emails. """
344326
flattened = list({x for sublist in actions for x in sublist})

src/azure-cli/azure/cli/command_modules/monitor/util.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@ def get_resource_group_location(cli_ctx, name):
1616
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES).resource_groups.get(name).location
1717

1818

19-
def get_operator_map():
20-
from azure.mgmt.monitor.models import ConditionOperator
21-
return {'>': ConditionOperator.greater_than, '>=': ConditionOperator.greater_than_or_equal,
22-
'<': ConditionOperator.less_than, '<=': ConditionOperator.less_than_or_equal}
23-
24-
25-
def get_aggregation_map():
26-
from azure.mgmt.monitor.models import TimeAggregationOperator
27-
return {'avg': TimeAggregationOperator.average, 'min': TimeAggregationOperator.minimum,
28-
'max': TimeAggregationOperator.maximum, 'total': TimeAggregationOperator.total,
29-
'last': TimeAggregationOperator.last}
30-
31-
3219
# region Autoscale Maps
3320
def get_autoscale_statistic_map():
3421
from azure.mgmt.monitor.models import MetricStatisticType

src/azure-cli/azure/cli/command_modules/vm/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def load_command_table(self, _):
534534
with self.command_group('vm monitor log', client_factory=cf_log_analytics_data_plane) as g:
535535
g.custom_command('show', 'execute_query_for_vm', transform=transform_log_analytics_query_output) # pylint: disable=show-command
536536

537-
with self.command_group('vm monitor metrics', custom_command_type=monitor_custom, command_type=metric_definitions_sdk, resource_type=ResourceType.MGMT_MONITOR, operation_group='metric_definitions', min_api='2018-01-01', is_preview=True) as g:
537+
with self.command_group('vm monitor metrics', custom_command_type=monitor_custom, command_type=metric_definitions_sdk, resource_type=ResourceType.MGMT_MONITOR, operation_group='metric_definitions', is_preview=True) as g:
538538
from azure.cli.command_modules.monitor.transformers import metrics_table, metrics_definitions_table
539539
from azure.cli.core.profiles._shared import APIVersionException
540540
try:

src/azure-cli/requirements.py3.Darwin.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ azure-mgmt-managementgroups==1.0.0
5353
azure-mgmt-maps==2.0.0
5454
azure-mgmt-marketplaceordering==1.1.0
5555
azure-mgmt-media==9.0.0
56-
azure-mgmt-monitor==5.0.0
56+
azure-mgmt-monitor==7.0.0b1
5757
azure-mgmt-msi==7.0.0
5858
azure-mgmt-netapp==10.1.0
5959
azure-mgmt-policyinsights==1.1.0b4

src/azure-cli/requirements.py3.Linux.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ azure-mgmt-managementgroups==1.0.0
5353
azure-mgmt-maps==2.0.0
5454
azure-mgmt-marketplaceordering==1.1.0
5555
azure-mgmt-media==9.0.0
56-
azure-mgmt-monitor==5.0.0
56+
azure-mgmt-monitor==7.0.0b1
5757
azure-mgmt-msi==7.0.0
5858
azure-mgmt-netapp==10.1.0
5959
azure-mgmt-policyinsights==1.1.0b4

0 commit comments

Comments
 (0)