Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 9 additions & 0 deletions src/azure-cli/azure/cli/command_modules/monitor/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,15 @@
az monitor log-analytics workspace table show --resource-group MyResourceGroup --workspace-name MyWorkspace -n MyTable
"""

helps['monitor log-analytics workspace table create'] = """
Comment thread
Jing-song marked this conversation as resolved.
type: command
short-summary: Create a Log Analytics workspace table..
examples:
- name: Create a Log Analytics workspace table.
text: |
az monitor log-analytics workspace table create --resource-group MyResourceGroup --workspace-name MyWorkspace -n MyTable --retention-time 45 --columns MyColumn1=string
"""

helps['monitor log-analytics workspace table update'] = """
Comment thread
Jing-song marked this conversation as resolved.
type: command
short-summary: Update the properties of a Log Analytics workspace table, currently only support updating retention time.
Expand Down
25 changes: 25 additions & 0 deletions src/azure-cli/azure/cli/command_modules/monitor/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ def load_arguments(self, _):
arg_type=get_enum_type(PublicNetworkAccessType))
c.argument('force', options_list=['--force', '-f'], arg_type=get_three_state_flag())

with self.argument_context('monitor log-analytics workspace update') as c:
c.argument('default_data_collection_rule_resource_id', options_list='--data-collection-rule', help='The resource ID of the default Data Collection Rule to use for this workspace.')
Comment thread
Jing-song marked this conversation as resolved.
Outdated

with self.argument_context('monitor log-analytics workspace pack') as c:
c.argument('intelligence_pack_name', options_list=['--name', '-n'])
c.argument('workspace_name', options_list='--workspace-name')
Expand All @@ -441,6 +444,28 @@ def load_arguments(self, _):
c.argument('table_name', name_arg_type, help='Name of the table.')
c.argument('workspace_name', options_list='--workspace-name')
c.argument('retention_in_days', options_list='--retention-time', help='The data table data retention in days, between 30 and 730. Setting this property to null will default to the workspace', type=int, required=True)

with self.argument_context('monitor log-analytics workspace table create') as c:
from azure.mgmt.loganalytics.models import TablePlanEnum
c.argument('columns', nargs='+', help='A list of table custom columns.Extracts multiple space-separated colunms in colunm_name=colunm_type format')
c.argument('plan', arg_type=get_enum_type(TablePlanEnum), help='The table plan. Possible values include: "Basic", "Analytics".')
c.argument('total_retention_in_days', type=int, options_list='--total-retention-time', help='The table data total retention in days, between 4 and 2555. Setting this property to null will default to table retention.')
c.argument('display_name', help='Table display name.')
c.argument('description', help='Table description.')
c.argument('query', options_list=['--search'], help='Search job query.')
c.argument('limit', type=int, help='Limit the search job to return up to specified number of rows.')
c.argument('start_search_time', arg_type=get_datetime_type(help='The timestamp to start the search from (UTC).'))
c.argument('end_search_time', arg_type=get_datetime_type(help='The timestamp to end the search by (UTC).'))
c.argument('search_description', help='Search results table\'s Description.')
c.argument('start_restore_time', arg_type=get_datetime_type(help='The timestamp to start the restore from (UTC).'))
c.argument('end_restore_time', arg_type=get_datetime_type(help='The timestamp to end the restore by (UTC).'))

with self.argument_context('monitor log-analytics workspace table update') as c:
Comment thread
Jing-song marked this conversation as resolved.
from azure.mgmt.loganalytics.models import TablePlanEnum
c.argument('plan', arg_type=get_enum_type(TablePlanEnum), help='The table plan. Possible values include: "Basic", "Analytics".')
c.argument('total_retention_in_days', type=int, options_list='--total-retention-time', help='The table data total retention in days, between 4 and 2555. Setting this property to null will default to table retention.')
c.argument('display_name', help='Table display name.')
c.argument('description', help='Table description.')
# endregion

# region Log Analytics Workspace Data Export
Expand Down
6 changes: 4 additions & 2 deletions src/azure-cli/azure/cli/command_modules/monitor/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,12 @@ def load_command_table(self, _):
g.command('list-management-groups', 'list', command_type=log_analytics_workspace_management_groups_sdk)
g.command('get-shared-keys', 'get_shared_keys', command_type=log_analytics_workspace_shared_keys_sdk)

with self.command_group('monitor log-analytics workspace table', log_analytics_workspace_table_sdk, custom_command_type=log_analytics_workspace_custom, client_factory=cf_log_analytics_workspace_tables) as g:
with self.command_group('monitor log-analytics workspace table', log_analytics_workspace_table_sdk, custom_command_type=log_analytics_workspace_custom, client_factory=cf_log_analytics_workspace_tables, is_preview=True) as g:
g.command('list', 'list_by_workspace')
g.show_command('show', 'get')
g.custom_command('update', 'update_log_analytics_workspace_table')
g.custom_command('create', 'create_log_analytics_workspace_table', supports_no_wait=True)
g.generic_update_command('update', setter_name='begin_create_or_update', custom_func_name='update_log_analytics_workspace_table', supports_no_wait=True)
Comment thread
Jing-song marked this conversation as resolved.
Outdated
g.command('delete', 'begin_delete', supports_no_wait=True)

with self.command_group('monitor log-analytics workspace data-export', log_analytics_workspace_data_exports_sdk,
custom_command_type=log_analytics_workspace_custom) as g:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
# --------------------------------------------------------------------------------------------
from azure.cli.command_modules.monitor._client_factory import _log_analytics_client_factory
from azure.cli.core.commands.transform import _parse_id
from azure.mgmt.loganalytics.models import WorkspaceSkuNameEnum, Workspace, WorkspaceSku, WorkspaceCapping, Table
from azure.mgmt.loganalytics.models import WorkspaceSkuNameEnum, Workspace, WorkspaceSku, WorkspaceCapping, Table,\
Schema, Column, SearchResults, RestoredLogs, ColumnTypeEnum
from azure.cli.core.util import sdk_no_wait
from azure.cli.core.azclierror import ArgumentUsageError, InvalidArgumentValueError
from knack.util import CLIError


Expand Down Expand Up @@ -35,7 +37,8 @@ def create_log_analytics_workspace(client, resource_group_name, workspace_name,

def update_log_analytics_workspace(instance, tags=None, capacity_reservation_level=None,
retention_time=None, daily_quota_gb=None,
public_network_access_for_query=None, public_network_access_for_ingestion=None):
public_network_access_for_query=None, public_network_access_for_ingestion=None,
default_data_collection_rule_resource_id=None):
if tags is not None:
instance.tags = tags
if capacity_reservation_level is not None:
Expand All @@ -50,6 +53,8 @@ def update_log_analytics_workspace(instance, tags=None, capacity_reservation_lev
instance.public_network_access_for_query = public_network_access_for_query
if public_network_access_for_ingestion is not None:
instance.public_network_access_for_ingestion = public_network_access_for_ingestion
if default_data_collection_rule_resource_id is not None:
instance.default_data_collection_rule_resource_id = default_data_collection_rule_resource_id
return instance


Expand Down Expand Up @@ -142,9 +147,50 @@ def update_log_analytics_workspace_data_exports(cmd, instance, table_names, dest
return instance


def update_log_analytics_workspace_table(client, resource_group_name, workspace_name, table_name, retention_in_days):
table = Table(retention_in_days=retention_in_days)
return client.update(resource_group_name=resource_group_name,
workspace_name=workspace_name,
table_name=table_name,
parameters=table)
# pylint:disable=too-many-locals
def create_log_analytics_workspace_table(client, resource_group_name, workspace_name, table_name, columns,
retention_in_days=None, total_retention_in_days=None, plan=None,
display_name=None, description=None, query=None, search_description=None,
limit=None, start_search_time=None, end_search_time=None,
start_restore_time=None, end_restore_time=None, no_wait=False):

search_results = SearchResults(query=query, description=search_description, limit=limit,
start_search_time=start_search_time, end_search_time=end_search_time)
restored_logs = RestoredLogs(start_restore_time=start_restore_time, end_restore_time=end_restore_time)
columns_list = []
for col in columns:
if '=' in col:
n, t = col.split('=', 1)
if t.lower() not in [x.value.lower() for x in ColumnTypeEnum]:
raise InvalidArgumentValueError('InvalidArgumentValueError: "{}" is not a valid value for type_name. '
'Allowed values: string, int, long, real, boolean, dateTime, guid, '
'dynamic".'.format(t))
else:
raise ArgumentUsageError('Usage error: --columns should be provided in colunm_name=colunm_type format')
columns_list.append(Column(name=n, type=t))
schema = Schema(name=table_name, columns=columns_list, display_name=display_name, description=description)
table = Table(retention_in_days=retention_in_days,
total_retention_in_days=total_retention_in_days,
search_results=search_results,
restored_logs=restored_logs,
schema=schema,
plan=plan
)
return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name,
workspace_name, table_name, table)


def update_log_analytics_workspace_table(instance, retention_in_days=None, total_retention_in_days=None, plan=None,
display_name=None, description=None):
if retention_in_days is not None:
instance.retention_in_days = retention_in_days
if total_retention_in_days is not None:
instance.total_retention_in_days = total_retention_in_days
if plan is not None:
instance.plan = plan
if display_name is not None:
instance.schema.displayName = display_name
if description is not None:
instance.schema.description = description

return instance
Loading