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
8 changes: 8 additions & 0 deletions src/application-insights/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
0.1.7
++++++++++++++++++

* support linked storage account for application insights component.
* support link one log analytics workspace to application insights component.
* support setting public network access for application insights component.
* one fix for api-key creation.

0.1.6
++++++++++++++++++

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ def cf_component_billing(cli_ctx, _):

def cf_api_key(cli_ctx, _):
return applicationinsights_mgmt_plane_client(cli_ctx).api_keys


def cf_component_linked_storage_accounts(cli_ctx, _):
return applicationinsights_mgmt_plane_client(cli_ctx).component_linked_storage_accounts
25 changes: 25 additions & 0 deletions src/application-insights/azext_applicationinsights/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,28 @@
text: |
az monitor app-insights events show --app 578f0e27-12e9-4631-bc02-50b965da2633 --type availabilityResults --offset 24h
"""

helps['monitor app-insights component linked-storage'] = """
type: group
short-summary: Manage linked storage account for an Application Insights component.
"""

helps['monitor app-insights component linked-storage show'] = """
type: command
short-summary: Show the details of linked storage account for an Application Insights component.
"""

helps['monitor app-insights component linked-storage link'] = """
type: command
short-summary: Link a storage account with an Application Insights component.
"""

helps['monitor app-insights component linked-storage update'] = """
type: command
short-summary: Update the linked storage account for an Application Insights component.
"""

helps['monitor app-insights component linked-storage unlink'] = """
type: command
short-summary: Unlink a storage account with an Application Insights component.
"""
19 changes: 16 additions & 3 deletions src/application-insights/azext_applicationinsights/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=line-too-long
from azure.cli.core.commands.parameters import get_datetime_type, get_location_type, tags_type, get_three_state_flag
# pylint: disable=line-too-long, too-many-statements
from azure.cli.core.commands.parameters import get_datetime_type, get_location_type, tags_type, get_three_state_flag, get_enum_type
from azure.cli.command_modules.monitor.actions import get_period_type
from ._validators import validate_applications
from ._validators import validate_applications, validate_storage_account_name_or_id, validate_log_analytic_workspace_name_or_id


def load_arguments(self, _):
Expand All @@ -24,6 +24,15 @@ def load_arguments(self, _):
c.argument('application-type', options_list=['application-type', '--type', '-t'], help="Type of application being monitored. Possible values include: 'web', 'other'. Default value: 'web' .")
c.argument('kind', options_list=['--kind', '-k'], help='The kind of application that this component refers to, used to customize UI. This value is a freeform string, values should typically be one of the following: web, ios, other, store, java, phone.')

with self.argument_context('monitor app-insights component') as c:
c.argument('workspace_resource_id', options_list=['--workspace'], validator=validate_log_analytic_workspace_name_or_id,
help='Name or resource ID of a log analytics workspace')
from .vendored_sdks.mgmt_applicationinsights.models import PublicNetworkAccessType
c.argument('public_network_access_for_ingestion', options_list=['--ingestion-access'], help='The public network access type for accessing Application Insights ingestion.',
arg_type=get_enum_type(PublicNetworkAccessType))
c.argument('public_network_access_for_query', options_list=['--query-access'], help='The public network access type for accessing Application Insights query.',
arg_type=get_enum_type(PublicNetworkAccessType))

with self.argument_context('monitor app-insights component update-tags') as c:
c.argument('tags', tags_type)

Expand Down Expand Up @@ -65,3 +74,7 @@ def load_arguments(self, _):
c.argument('start_time', arg_type=get_datetime_type(help='Start-time of time range for which to retrieve data.'))
c.argument('end_time', arg_type=get_datetime_type(help='End of time range for current operation. Defaults to the current time.'))
c.argument('offset', help='Filter results based on UTC hour offset.', type=get_period_type(as_timedelta=True))

with self.argument_context('monitor app-insights component linked-storage') as c:
c.argument('storage_account_id', options_list=['--storage-account', '-s'], validator=validate_storage_account_name_or_id,
help='Name or ID of a linked storage account.')
28 changes: 28 additions & 0 deletions src/application-insights/azext_applicationinsights/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,31 @@ def validate_applications(namespace):
raise CLIError("Specify either a full resource id or an application name and resource group.")
else:
raise CLIError("Resource group only allowed with a single application name.")


def validate_storage_account_name_or_id(cmd, namespace):
if namespace.storage_account_id:
from msrestazure.tools import resource_id
from azure.cli.core.commands.client_factory import get_subscription_id
if not is_valid_resource_id(namespace.storage_account_id):
namespace.storage_account_id = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Storage',
type='storageAccounts',
name=namespace.storage_account_id
)


def validate_log_analytic_workspace_name_or_id(cmd, namespace):
if namespace.workspace_resource_id:
from msrestazure.tools import resource_id
from azure.cli.core.commands.client_factory import get_subscription_id
if not is_valid_resource_id(namespace.workspace_resource_id):
namespace.workspace_resource_id = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='microsoft.OperationalInsights',
type='workspaces',
name=namespace.workspace_resource_id
)
14 changes: 13 additions & 1 deletion src/application-insights/azext_applicationinsights/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
cf_query,
cf_components,
cf_api_key,
cf_component_billing
cf_component_billing,
cf_component_linked_storage_accounts
)


Expand Down Expand Up @@ -63,6 +64,11 @@ def load_command_table(self, _):
client_factory=cf_api_key
)

component_linked_storage_accounts_custom_sdk = CliCommandType(
operations_tmpl='azext_applicationinsights.custom#{}',
client_factory=cf_component_linked_storage_accounts
)

with self.command_group('monitor app-insights component', command_type=components_sdk, custom_command_type=components_custom_sdk) as g:
g.custom_command('create', 'create_or_update_component')
g.custom_command('update', 'update_component')
Expand All @@ -88,3 +94,9 @@ def load_command_table(self, _):

with self.command_group('monitor app-insights', query_sdk) as g:
g.custom_command('query', 'execute_query')

with self.command_group('monitor app-insights component linked-storage', custom_command_type=component_linked_storage_accounts_custom_sdk) as g:
g.custom_show_command('show', 'get_component_linked_storage_account')
g.custom_command('link', 'create_component_linked_storage_account')
g.custom_command('update', 'update_component_linked_storage_account')
g.custom_command('unlink', 'delete_component_linked_storage_account')
59 changes: 53 additions & 6 deletions src/application-insights/azext_applicationinsights/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,46 @@ def get_metrics_metadata(cmd, client, application, resource_group_name=None):
return client.metrics.get_metadata(get_id_from_azure_resource(cmd.cli_ctx, application, resource_group=resource_group_name))


def create_or_update_component(client, application, resource_group_name, location, tags=None, kind="web", application_type='web'):
from .vendored_sdks.mgmt_applicationinsights.models import ApplicationInsightsComponent
component = ApplicationInsightsComponent(location, kind, application_type=application_type, tags=tags)
def create_or_update_component(cmd, client, application, resource_group_name, location, tags=None,
kind="web", application_type='web', workspace_resource_id=None,
public_network_access_for_ingestion=None, public_network_access_for_query=None):
# due to service limitation, we have to do such a hack. We must refract the logic later.
if workspace_resource_id is None:
from .vendored_sdks.mgmt_applicationinsights.v2018_05_01_preview.models import ApplicationInsightsComponent
from ._client_factory import applicationinsights_mgmt_plane_client
client = applicationinsights_mgmt_plane_client(cmd.cli_ctx, api_version='2018-05-01-preview').components
component = ApplicationInsightsComponent(location=location, kind=kind, application_type=application_type, tags=tags,
public_network_access_for_ingestion=public_network_access_for_ingestion,
public_network_access_for_query=public_network_access_for_query)
return client.create_or_update(resource_group_name, application, component)

from .vendored_sdks.mgmt_applicationinsights.v2020_02_02_preview.models import ApplicationInsightsComponent
component = ApplicationInsightsComponent(location=location, kind=kind, application_type=application_type,
tags=tags, workspace_resource_id=workspace_resource_id,
public_network_access_for_ingestion=public_network_access_for_ingestion,
public_network_access_for_query=public_network_access_for_query)
return client.create_or_update(resource_group_name, application, component)


def update_component(client, application, resource_group_name, kind=None):
def update_component(cmd, client, application, resource_group_name, kind=None, workspace_resource_id=None,
public_network_access_for_ingestion=None, public_network_access_for_query=None):
existing_component = client.get(resource_group_name, application)
if kind:
existing_component.kind = kind
return client.create_or_update(resource_group_name, application, existing_component)
if workspace_resource_id is not None:
existing_component.workspace_resource_id = workspace_resource_id or None
if public_network_access_for_ingestion is not None:
existing_component.public_network_access_for_ingestion = public_network_access_for_ingestion
if public_network_access_for_query is not None:
existing_component.public_network_access_for_query = public_network_access_for_query
if hasattr(existing_component, 'workspace_resource_id') and existing_component.workspace_resource_id is not None:
return client.create_or_update(resource_group_name, application, existing_component)

from .vendored_sdks.mgmt_applicationinsights.v2018_05_01_preview.models import ApplicationInsightsComponent
from ._client_factory import applicationinsights_mgmt_plane_client
client = applicationinsights_mgmt_plane_client(cmd.cli_ctx, api_version='2018-05-01-preview').components
component = ApplicationInsightsComponent(**(vars(existing_component)))
return client.create_or_update(resource_group_name, application, component)


def update_component_tags(client, application, resource_group_name, tags):
Expand Down Expand Up @@ -82,7 +111,9 @@ def create_api_key(cmd, client, application, resource_group_name, api_key, read_
if write_properties is None:
write_properties = ['WriteAnnotations']
linked_read_properties, linked_write_properties = get_linked_properties(cmd.cli_ctx, application, resource_group_name, read_properties, write_properties)
api_key_request = APIKeyRequest(api_key, linked_read_properties, linked_write_properties)
api_key_request = APIKeyRequest(name=api_key,
linked_read_properties=linked_read_properties,
linked_write_properties=linked_write_properties)
return client.create(resource_group_name, application, api_key_request)


Expand Down Expand Up @@ -118,3 +149,19 @@ def update_component_billing(client, application, resource_group_name, cap=None,
resource_name=application,
data_volume_cap=billing_features.data_volume_cap,
current_billing_features=billing_features.current_billing_features)


def get_component_linked_storage_account(client, resource_group_name, application):
return client.get(resource_group_name=resource_group_name, resource_name=application)


def create_component_linked_storage_account(client, resource_group_name, application, storage_account_id):
return client.create_and_update(resource_group_name=resource_group_name, resource_name=application, linked_storage_account=storage_account_id)


def update_component_linked_storage_account(client, resource_group_name, application, storage_account_id):
return client.update(resource_group_name=resource_group_name, resource_name=application, linked_storage_account=storage_account_id)


def delete_component_linked_storage_account(client, resource_group_name, application):
return client.delete(resource_group_name=resource_group_name, resource_name=application)
Loading