Skip to content

Commit

Permalink
{Monitor-control-service} Data collection migrate (#7120)
Browse files Browse the repository at this point in the history
* add generated code and adjust rule file json key
  • Loading branch information
AllyW authored Dec 27, 2023
1 parent cad08ff commit 5bc032e
Show file tree
Hide file tree
Showing 54 changed files with 10,736 additions and 1,795 deletions.
5 changes: 5 additions & 0 deletions src/monitor-control-service/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Release History
===============
1.0.0
++++++
* Enable all of the facilities of `data-collection` in stable version `2022-06-01`
* Remove `id_part` of subcommands `data-flow`, `log-analytics`, `performance-counter`, `windows-event-log` and `syslog` for `az monitor data-collection rule`

0.4.1
++++++
* `az monitor data-collection rule association create/update`: Add parameter --endpoint-id.
Expand Down
36 changes: 15 additions & 21 deletions src/monitor-control-service/azext_amcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,31 @@ class MonitorClientCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from azext_amcs.generated._client_factory import cf_monitor_control_service_cl
from azext_amcs._client_factory import cf_monitor_control_service_cl
monitor_control_service_custom = CliCommandType(
operations_tmpl='azext_amcs.custom#{}',
client_factory=cf_monitor_control_service_cl)
parent = super(MonitorClientCommandsLoader, self)
parent.__init__(cli_ctx=cli_ctx, custom_command_type=monitor_control_service_custom)
super().__init__(cli_ctx=cli_ctx, custom_command_type=monitor_control_service_custom)

def load_command_table(self, args):
from azext_amcs.generated.commands import load_command_table
load_command_table(self, args)
from azure.cli.core.aaz import load_aaz_command_table
try:
from azext_amcs.manual.commands import load_command_table as load_command_table_manual
load_command_table_manual(self, args)
except ImportError as e:
if e.name.endswith('manual.commands'):
pass
else:
raise e
from . import aaz
except ImportError:
aaz = None
if aaz:
load_aaz_command_table(
loader=self,
aaz_pkg_name=aaz.__name__,
args=args
)
from azext_amcs.commands import load_command_table
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azext_amcs.generated._params import load_arguments
from azext_amcs._params import load_arguments
load_arguments(self, command)
try:
from azext_amcs.manual._params import load_arguments as load_arguments_manual
load_arguments_manual(self, command)
except ImportError as e:
if e.name.endswith('manual._params'):
pass
else:
raise e


COMMAND_LOADER_CLS = MonitorClientCommandsLoader
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@
def cf_monitor_control_service_cl(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azext_amcs.vendored_sdks.amcs import MonitorClient
return get_mgmt_service_client(cli_ctx,
MonitorClient)
return get_mgmt_service_client(cli_ctx, MonitorClient)


def cf_data_collection_endpoint(cli_ctx, *_):
return cf_monitor_control_service_cl(cli_ctx).data_collection_endpoints


def cf_data_collection_rule_association(cli_ctx, *_):
return cf_monitor_control_service_cl(cli_ctx).data_collection_rule_associations


def cf_data_collection_rule(cli_ctx, *_):
return cf_monitor_control_service_cl(cli_ctx).data_collection_rules
37 changes: 36 additions & 1 deletion src/monitor-control-service/azext_amcs/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,46 @@
# pylint: disable=wildcard-import
# pylint: disable=unused-wildcard-import
# pylint: disable=unused-import
from .generated._help import helps # pylint: disable=reimported

try:
from .manual._help import helps # pylint: disable=reimported
except ImportError as e:
if e.name.endswith('manual._help'):
pass
else:
raise e


helps['monitor data-collection'] = '''
type: group
short-summary: Manage Monitor
'''

helps['monitor data-collection rule'] = """
type: group
short-summary: Manage data collection rule with monitor control service
"""

helps['monitor data-collection rule association'] = """
type: group
short-summary: Manage data collection rule association with monitor control service
"""

helps['monitor data-collection rule association list'] = """
type: command
short-summary: "Lists associations for the specified data collection rule. And Lists associations for the \
specified data collection endpoint. And Lists associations for the specified resource."
examples:
- name: List associations for specified data collection rule
text: |-
az monitor data-collection rule association list --rule-name "myCollectionRule" --resource-group \
"myResourceGroup"
- name: List associations for specified data collection endpoint
text: |-
az monitor data-collection rule association list --data-collection-endpoint-name \
"myDataCollectionEndpointName" --resource-group "myResourceGroup"
- name: List associations for specified resource
text: |-
az monitor data-collection rule association list --resource "subscriptions/703362b3-f278-4e4b-9179-c76ea\
f41ffc2/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVm"
"""
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# coding=utf-8
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: disable=too-many-lines
# pylint: disable=too-many-statements


from azure.cli.core.commands.parameters import (
tags_type,
resource_group_name_type,
get_location_type,
get_enum_type
)
from azure.cli.core.commands.validators import (
get_default_location_from_resource_group,
validate_file_or_dict
)
from azext_amcs.action import (
Expand All @@ -25,43 +24,34 @@
AddDataSourcesWindowsEventLogs,
AddDataSourcesSyslog
)
from azext_amcs.manual._validators import validate_association_name_with_endpoint
from azext_amcs._validators import validate_association_name_with_endpoint

from azext_amcs.vendored_sdks.amcs.models import KnownDataFlowStreams, KnownPerfCounterDataSourceStreams, \
KnownWindowsEventLogDataSourceStreams, KnownSyslogDataSourceStreams, \
KnownSyslogDataSourceFacilityNames, KnownSyslogDataSourceLogLevels


def load_arguments(self, _):

with self.argument_context('monitor data-collection endpoint') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('data_collection_endpoint_name', options_list=['--name', '-n'], type=str,
help='The name of the data collection endpoint. The name is case insensitive.', id_part='name')
c.argument('location', arg_type=get_location_type(self.cli_ctx), required=False,
validator=get_default_location_from_resource_group)
c.argument('tags', tags_type)
c.argument('kind', arg_type=get_enum_type(['Linux', 'Windows']), help='The kind of the resource.')
c.argument('description', type=str, help='Description of the data collection endpoint.')
c.argument('public_network_access', arg_type=get_enum_type(['Enabled', 'Disabled']),
help='The configuration to set whether network access from public internet to the endpoints '
'are allowed.',
arg_group='Network Acls')

with self.argument_context('monitor data-collection endpoint create') as c:
c.argument('data_collection_endpoint_name', id_part=None)
def load_arguments(self, _): # pylint: disable=unused-argument

with self.argument_context('monitor data-collection rule association') as c:
c.argument('resource_uri', options_list=['--resource'], help='The identifier of the resource.')
c.argument('resource_group_name', resource_group_name_type)
c.argument('resource_uri', options_list=['--resource', '--resource-uri'],
help='The identifier of the resource.')
c.argument('association_name', options_list=['--name', '-n'], help='The name of the association.')
c.argument('description', help='Description of the association.')
c.argument('rule_id', help='The resource ID of the data collection rule that is to be associated.')
c.argument('endpoint_id', help='The resource ID of the data collection endpoint that is to be associated.',
validator=validate_association_name_with_endpoint)
c.argument('data_collection_rule_name', options_list=['--rule-name'])
c.argument('data_collection_rule_name', options_list=['--rule-name', '--data-collection-rule-name'])

with self.argument_context('monitor data-collection rule association list') as c:
c.argument('data_collection_rule_name', options_list=['--rule-name'], id_part=None)
c.argument('data_collection_rule_name', options_list=['--rule-name', '--data-collection-rule-name'],
type=str, id_part=None,
help='The name of the data collection rule. The name is case insensitive.')
c.argument('data_collection_endpoint_name', options_list=['--endpoint-name', '--data-collection-endpoint-name'],
type=str, help='The name of the data collection endpoint. The name is case insensitive.')
c.argument('resource_uri', options_list=['--resource', '--resource-uri'],
type=str, help='The identifier of the resource.')

with self.argument_context('monitor data-collection rule') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand Down Expand Up @@ -90,38 +80,23 @@ def load_arguments(self, _):
type=validate_file_or_dict, help='The list of Azure VM extension data source configurations. '
'Expected value: json-string/@json-file.')

with self.argument_context('monitor data-collection rule list') as c:
c.argument('data_collection_rule_name', id_part=None)

with self.argument_context('monitor data-collection rule create') as c:
c.argument('data_collection_rule_name', id_part=None)
c.argument('rule_file', type=str, help='The json file for rule parameters.', required=True)
c.argument('location', arg_type=get_location_type(self.cli_ctx), required=False,
validator=get_default_location_from_resource_group)

with self.argument_context('monitor data-collection rule data-flow') as c:
c.argument('data_collection_rule_name', options_list=['--rule-name'])
c.argument('data_collection_rule_name', options_list=['--rule-name'], id_part=None)
c.argument('streams', options_list=['--streams'], arg_type=get_enum_type(KnownDataFlowStreams),
nargs='+', help='List of streams for this data flow.')
c.argument('destinations', options_list=['--destinations'], nargs='+',
help='List of destinations for this data flow.')

with self.argument_context('monitor data-collection rule data-flow list') as c:
c.argument('data_collection_rule_name', id_part=None)

with self.argument_context('monitor data-collection rule log-analytics') as c:
c.argument('data_collection_rule_name', options_list=['--rule-name'])
c.argument('data_collection_rule_name', options_list=['--rule-name'], id_part=None)
c.argument('name', options_list=['--name', '-n'],
help='A friendly name for the destination. This name should be unique across all destinations '
'(regardless of type) within the data collection rule.')
c.argument('workspace_resource_id', options_list=['--resource-id'],
help='The resource ID of the Log Analytics workspace.')

with self.argument_context('monitor data-collection rule log-analytics list') as c:
c.argument('data_collection_rule_name', id_part=None)

with self.argument_context('monitor data-collection rule performance-counter') as c:
c.argument('data_collection_rule_name', options_list=['--rule-name'])
c.argument('data_collection_rule_name', options_list=['--rule-name'], id_part=None)
c.argument('name', options_list=['--name', '-n'],
help='A friendly name for the data source. This name should be unique across all data sources '
'(regardless of type) within the data collection rule.')
Expand All @@ -136,11 +111,8 @@ def load_arguments(self, _):
"Use a wildcard (*) to collect a counter for all instances. "
"To get a list of performance counters on Windows, run the command 'typeperf'.")

with self.argument_context('monitor data-collection rule performance-counter list') as c:
c.argument('data_collection_rule_name', id_part=None)

with self.argument_context('monitor data-collection rule windows-event-log') as c:
c.argument('data_collection_rule_name', options_list=['--rule-name'])
c.argument('data_collection_rule_name', options_list=['--rule-name'], id_part=None)
c.argument('name', options_list=['--name', '-n'],
help='A friendly name for the data source. This name should be unique across all data sources '
'(regardless of type) within the data collection rule.')
Expand All @@ -151,11 +123,8 @@ def load_arguments(self, _):
c.argument('x_path_queries', options_list=['--x-path-queries'], nargs='+',
help='A list of Windows Event Log queries in XPATH format.')

with self.argument_context('monitor data-collection rule windows-event-log list') as c:
c.argument('data_collection_rule_name', id_part=None)

with self.argument_context('monitor data-collection rule syslog') as c:
c.argument('data_collection_rule_name', options_list=['--rule-name'])
c.argument('data_collection_rule_name', options_list=['--rule-name'], id_part=None)
c.argument('name', options_list=['--name', '-n'],
help='A friendly name for the data source. This name should be unique across all data sources '
'(regardless of type) within the data collection rule.')
Expand All @@ -168,6 +137,3 @@ def load_arguments(self, _):
help='The list of facility names.')
c.argument('log_levels', options_list=['--log-levels'], arg_type=get_enum_type(KnownSyslogDataSourceLogLevels),
nargs='+', help='The log levels to collect.')

with self.argument_context('monitor data-collection rule syslog list') as c:
c.argument('data_collection_rule_name', id_part=None)
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# --------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# --------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command_group(
"monitor",
)
class __CMDGroup(AAZCommandGroup):
"""Monitor.
"""
pass


__all__ = ["__CMDGroup"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from .__cmd_group import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command_group(
"monitor data-collection",
)
class __CMDGroup(AAZCommandGroup):
"""Manage data collection for monitor control service.
"""
pass


__all__ = ["__CMDGroup"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from .__cmd_group import *
Loading

0 comments on commit 5bc032e

Please sign in to comment.