Skip to content

Commit e9be452

Browse files
william051200nddq
authored andcommitted
{Compute} az vm monitor log: Migrate command group to aaz-based implementation (Azure#32848)
1 parent 3839025 commit e9be452

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6021,15 +6021,15 @@ def _set_data_source_for_workspace(cmd, os_type, resource_group_name, workspace_
60216021

60226022
def execute_query_for_vm(cmd, client, resource_group_name, vm_name, analytics_query, timespan=None):
60236023
"""Executes a query against the Log Analytics workspace linked with a vm."""
6024-
vm = get_vm(cmd, resource_group_name, vm_name)
6024+
vm = get_vm_by_aaz(cmd, resource_group_name, vm_name)
60256025
workspace = None
6026-
extension_resources = vm.resources or []
6026+
extension_resources = vm.get('resources', [])
60276027
for resource in extension_resources:
6028-
if resource.name == "MicrosoftMonitoringAgent" or resource.name == "OmsAgentForLinux":
6029-
workspace = resource.settings.get('workspaceId', None)
6028+
if resource.get('name') in (_WINDOWS_OMS_AGENT_EXT, _LINUX_OMS_AGENT_EXT):
6029+
workspace = resource.get('settings', {}).get('workspaceId', None)
60306030
if workspace is None:
60316031
raise CLIError('Cannot find the corresponding log analytics workspace. '
6032-
'Please check the status of log analytics workpsace.')
6032+
'Please check the status of log analytics workspace.')
60336033
return client.query_workspace(workspace, analytics_query, timespan=timespan)
60346034

60356035

src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_create_with_monitor.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6927,7 +6927,7 @@ interactions:
69276927
User-Agent:
69286928
- AZURECLI/2.71.0 azsdk-python-core/1.31.0 Python/3.10.11 (Windows-10-10.0.26100-SP0)
69296929
method: GET
6930-
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vm_create_with_monitor000001/providers/Microsoft.Compute/virtualMachines/monitorvm?api-version=2024-11-01
6930+
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vm_create_with_monitor000001/providers/Microsoft.Compute/virtualMachines/monitorvm?api-version=2025-04-01
69316931
response:
69326932
body:
69336933
string: "{\r\n \"name\": \"monitorvm\",\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vm_create_with_monitor000001/providers/Microsoft.Compute/virtualMachines/monitorvm\",\r\n

0 commit comments

Comments
 (0)