Skip to content
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
3 changes: 2 additions & 1 deletion src/azure-cli-core/azure/cli/core/profiles/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ def default_api_version(self):
'private_link_scoped_resources': '2019-10-17-preview',
'private_link_scope_operation_status': '2019-10-17-preview',
'private_link_scopes': '2019-10-17-preview',
'private_endpoint_connections': '2019-10-17-preview'
'private_endpoint_connections': '2019-10-17-preview',
'subscription_diagnostic_settings': '2017-05-01-preview'
}),
ResourceType.MGMT_APPSERVICE: '2019-08-01',
ResourceType.MGMT_IOTHUB: '2020-03-01',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def cf_diagnostics_category(cli_ctx, _):
return cf_monitor(cli_ctx).diagnostic_settings_category


def cf_subscription_diagnostics(cli_ctx, _):
return cf_monitor(cli_ctx).subscription_diagnostic_settings


def cf_log_profiles(cli_ctx, _):
return cf_monitor(cli_ctx).log_profiles

Expand Down
53 changes: 53 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 @@ -864,6 +864,59 @@
crafted: true
"""

helps['monitor diagnostic-settings subscription'] = """
type: group
short-summary: Manage diagnostic settings for subscription.
"""

helps['monitor diagnostic-settings subscription create'] = """
type: command
short-summary: Create diagnostic settings for a subscription
examples:
- name: Create diagnostic settings for a subscription with EventHub.
text: |
az monitor diagnostic-settings subscription create -n {name} --location westus --event-hub-auth-rule {eventHubRuleID} --storage-account {storageAccount} \\
--logs '[
{
"category": "Security",
"enabled": true,
},
{
"category": "Administrative",
"enabled": true,
},
{
"category": "ServiceHealth",
"enabled": true,
},
{
"category": "Alert",
"enabled": true,
},
{
"category": "Recommendation",
"enabled": true,
},
{
"category": "Policy",
"enabled": true,
},
{
"category": "Autoscale",
"enabled": true,
},
{
"category": "ResourceHealth",
"enabled": true,
}
]'
"""

helps['monitor diagnostic-settings subscription update'] = """
type: command
short-summary: Update diagnostic settings for a subscription.
"""

helps['monitor log-analytics'] = """
type: group
short-summary: Manage Azure log analytics.
Expand Down
14 changes: 13 additions & 1 deletion src/azure-cli/azure/cli/command_modules/monitor/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from azure.cli.command_modules.monitor.util import get_operator_map, get_aggregation_map
from azure.cli.command_modules.monitor.validators import (
process_webhook_prop, validate_autoscale_recurrence, validate_autoscale_timegrain, get_action_group_validator,
get_action_group_id_validator, validate_metric_dimension, validate_storage_accounts_name_or_id)
get_action_group_id_validator, validate_metric_dimension, validate_storage_accounts_name_or_id,
process_subscription_id)

from knack.arguments import CLIArgumentType

Expand Down Expand Up @@ -244,6 +245,17 @@ def load_arguments(self, _):

with self.argument_context('monitor diagnostic-settings categories show') as c:
c.resource_parameter('resource_uri', required=True)

with self.argument_context('monitor diagnostic-settings subscription') as c:
import argparse
c.argument('subscription_id', validator=process_subscription_id, help=argparse.SUPPRESS, required=False)
c.argument('logs', type=get_json_object, help="JSON encoded list of logs settings. Use '@{file}' to load from a file.")
c.argument('name', help='The name of the diagnostic setting.', options_list=['--name', '-n'])
c.argument('event_hub_name', help='The name of the event hub. If none is specified, the default event hub will be selected.')
c.argument('event_hub_auth_rule', help='The resource Id for the event hub authorization rule.')
c.argument('workspace', help='The resource id of the log analytics workspace.')
c.argument('storage_account', help='The resource id of the storage account to which you would like to send the Activity Log.')
c.argument('service_bus_rule', help="The service bus rule ID of the service bus namespace in which you would like to have Event Hubs created for streaming the Activity Log. The rule ID is of the format '{service bus resource ID}/authorizationrules/{key name}'.")
# endregion

# region LogProfiles
Expand Down
24 changes: 22 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 @@ -17,7 +17,8 @@ def load_command_table(self, _):
cf_log_analytics_workspace_intelligence_packs, cf_log_analytics_cluster,
cf_log_analytics_workspace_linked_service, cf_diagnostics_category,
cf_private_link_resources, cf_private_link_scoped_resources,
cf_private_link_scopes, cf_private_endpoint_connections, cf_log_analytics_linked_storage, cf_log_analytics_workspace_saved_searches)
cf_private_link_scopes, cf_private_endpoint_connections, cf_log_analytics_linked_storage,
cf_log_analytics_workspace_saved_searches, cf_subscription_diagnostics)
from ._exception_handler import monitor_exception_handler, missing_resource_handler
from .transformers import (action_group_list_table)
from .validators import process_autoscale_create_namespace, validate_private_endpoint_connection_id
Expand Down Expand Up @@ -110,6 +111,18 @@ def load_command_table(self, _):
operation_group='log_profiles',
exception_handler=monitor_exception_handler)

subscription_dianostic_settings_sdk = CliCommandType(
operations_tmpl='azure.mgmt.monitor.operations#SubscriptionDiagnosticSettingsOperations.{}',
client_factory=cf_subscription_diagnostics,
operation_group='subscription_diagnostic_settings',
exception_handler=monitor_exception_handler)

subscription_dianostic_settings_custom = CliCommandType(
operations_tmpl='azure.cli.command_modules.monitor.operations.subscription_diagnostic_settings#{}',
client_factory=cf_subscription_diagnostics,
operation_group='subscription_diagnostic_settings',
exception_handler=monitor_exception_handler)

alert_custom = CliCommandType(
operations_tmpl='azure.cli.command_modules.monitor.operations.metric_alert#{}',
client_factory=cf_alert_rules,
Expand Down Expand Up @@ -383,7 +396,7 @@ def load_command_table(self, _):

with self.command_group('monitor log-analytics workspace saved-search', log_analytics_workspace_saved_search_sdk, custom_command_type=log_analytics_workspace_custom) as g:
g.custom_command('create', 'create_log_analytics_workspace_saved_search', client_factory=cf_log_analytics_workspace_saved_searches)
g.generic_update_command('update', custom_func_name='update_log_analytics_workspace_saved_search', client_factory=cf_log_analytics_workspace_saved_searches,)
g.generic_update_command('update', custom_func_name='update_log_analytics_workspace_saved_search', client_factory=cf_log_analytics_workspace_saved_searches)
g.command('delete', 'delete', confirmation=True)
g.show_command('show', 'get')
g.command('list', 'list_by_workspace')
Expand Down Expand Up @@ -443,3 +456,10 @@ def load_command_table(self, _):
validator=validate_private_endpoint_connection_id)
g.custom_command('delete', 'delete_private_endpoint_connection', client_factory=cf_private_endpoint_connections,
validator=validate_private_endpoint_connection_id, confirmation=True)

with self.command_group('monitor diagnostic-settings subscription', subscription_dianostic_settings_sdk, custom_command_type=subscription_dianostic_settings_custom) as g:
g.custom_command('create', 'create_subscription_diagnostic_settings')
g.command('delete', 'delete', confirmation=True)
g.show_command('show', 'get')
g.command('list', 'list')
g.generic_update_command('update', custom_func_name='update_subscription_diagnostic_settings')
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,4 @@ def update_log_analytics_workspace_saved_search(cmd, instance, category=None, di
c.set_param('function_alias', function_alias)
c.set_param('function_parameters', function_parameters)
c.set_param('tags', _format_tags(tags))
# workaround for server's issue. server would return etag instead of eTag.
c.set_param('e_tag', instance.additional_properties['etag'])
return instance
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------


# pylint: disable=unused-argument, line-too-long
def create_subscription_diagnostic_settings(cmd, client,
name, logs,
location,
event_hub_name=None,
event_hub_auth_rule=None,
storage_account=None,
service_bus_rule=None,
workspace=None):
from azure.mgmt.monitor.models import SubscriptionDiagnosticSettingsResource
from azure.cli.core.commands.client_factory import get_subscription_id
parameters = SubscriptionDiagnosticSettingsResource(storage_account_id=storage_account,
workspace_id=workspace,
event_hub_name=event_hub_name,
event_hub_authorization_rule_id=event_hub_auth_rule,
service_bus_rule_id=service_bus_rule,
logs=logs,
location=location)
return client.create_or_update(subscription_id=get_subscription_id(cmd.cli_ctx), parameters=parameters, name=name)


def update_subscription_diagnostic_settings(cmd, instance, event_hub_name=None, logs=None,
event_hub_auth_rule=None, storage_account=None,
service_bus_rule=None, workspace=None):
with cmd.update_context(instance) as c:
c.set_param('storage_account_id', storage_account)
c.set_param('workspace_id', workspace)
c.set_param('event_hub_name', event_hub_name)
c.set_param('event_hub_authorization_rule_id', event_hub_auth_rule)
c.set_param('service_bus_rule_id', service_bus_rule)
c.set_param('logs', logs)
return instance
Loading