Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Marketplace Contribution] - EXPANDR-2805 - Update Get VM Details Command #36048

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
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ def get_vm_command(client: MsGraphClient, args: dict, params: dict):
provisioning_state = properties.get('provisioningState')
location = response.get('location')
user_data = properties.get('userData')
tags = response.get('tags')
network_interfaces = properties.get('networkProfile', {}).get('networkInterfaces')
statuses = properties.get('instanceView', {}).get('statuses', [])
power_state = None
Expand All @@ -666,7 +667,8 @@ def get_vm_command(client: MsGraphClient, args: dict, params: dict):
'PowerState': power_state,
'ResourceGroup': resource_group,
'NetworkInterfaces': network_interfaces,
'UserData': user_data
'UserData': user_data,
'Tags': tags
}

title = f'Properties of VM "{vm_name}"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ script:
- contextPath: Azure.Compute.UserData
description: UserData for the VM.
type: string
- contextPath: Azure.Compute.Tags
description: Tags associated with the VM.
type: string
- arguments:
- description: "The subscription ID. Note: This argument will override the instance parameter ‘Default Subscription ID'."
name: subscription_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from AzureCompute_v2 import MsGraphClient, screen_errors, assign_image_attributes, list_vms_command, \
create_vm_parameters, get_network_interface_command, get_public_ip_details_command, \
get_all_public_ip_details_command, create_nic_command, get_single_ip_details_from_list_of_ip_details
get_all_public_ip_details_command, create_nic_command, get_single_ip_details_from_list_of_ip_details, \
get_vm_command

# test_create_vm_parameters data:
CREATE_VM_PARAMS_ARGS = {"nic_name": "test-compute-integration-nic",
Expand Down Expand Up @@ -71,6 +72,14 @@ def load_test_data(json_path):
{'Name': 'vm2_name', 'ID': 'vm2_id', 'Size': 32, 'OS': 'Linux', 'Location': 'westeurope',
'ProvisioningState': 'Succeeded', 'ResourceGroup': 'resource_group'}]}

SINGLE_VM_EC = {'Azure.Compute(val.Name && val.Name == obj.Name)':
{'Name': 'test-vm-1',
'ID': 'aabbccd-123a-123d-a1a1-123aaabb123b',
'Size': 30, 'OS': 'Linux', 'Location': 'westeurope',
'ProvisioningState': 'Succeeded', 'ResourceGroup': 'fake-rg-1', 'Tags': {'owner': 'fake@email.com', 'env': 'dev'}
}
}

INTERFACE_EC = {
'Azure.Network.Interfaces(val.ID && val.ID == obj.ID)':
{
Expand Down Expand Up @@ -229,6 +238,13 @@ def test_list_vms_command(mocker):
assert command_results.to_context()['EntryContext'] == VM_LIST_EC


def test_get_vm_command(mocker):
vms_data = load_test_data('./test_data/get_vm_command.json')
mocker.patch.object(client, 'get_vm', return_value=vms_data)
command_results = get_vm_command(client, params={}, args={'virtual_machine_name': 'test-vm-1', 'resource_group': 'fake-rg-1'})
assert command_results.to_context().get('Contents').get('tags') == {'owner': 'fake@email.com', 'env': 'dev'}


def test_get_network_interface_command(mocker):
interface_data = load_test_data('./test_data/get_network_interface_command.json')
mocker.patch.object(client, 'get_network_interface', return_value=interface_data)
Expand Down
7 changes: 6 additions & 1 deletion Packs/AzureCompute/Integrations/AzureCompute_v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ Gets the properties of a given virtual machine.
| Azure.Compute.ResourceGroup | string | The resource group to which the virtual machine belongs. |
| Azure.Compute.NetworkInterfaces | Unknown | The list of network interfaces attached to this machine. |
| Azure.Compute.UserData | string | UserData for the VM. |
| Azure.Compute.Tags | string | Tags associated with the VM. |

#### Command example
```!azure-vm-get-instance-details resource_group=Compute-Labs virtual_machine_name=webserver```
Expand All @@ -276,7 +277,11 @@ Gets the properties of a given virtual machine.
"PowerState": "VM running",
"ProvisioningState": "Succeeded",
"ResourceGroup": "Compute-Labs",
"Size": 127
"Size": 127,
"Tags": {
"env": "dev",
"owner" : "testuser"
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
{
"id": "/subscriptions/aabbccd-123a-123d-a1a1-123aaabb123b/resourceGroups/fake-rg-1/providers/Microsoft.Compute/virtualMachines/test-vm-1",
"location": "westeurope",
"name": "test-vm-1",
"properties": {
"additionalCapabilities": {
"hibernationEnabled": false
},
"applicationProfile": {
"galleryApplications": [
{
"enableAutomaticUpgrade": false,
"manuallyManaged": false,
"packageReferenceId": "/subscriptions/aabbccd-123a-123d-a1a1-123aaabb123b/resourceGroups/fake-profile/providers/Microsoft.Compute/galleries/xdr/applications/linux-xdr/versions/8.3.0",
"treatFailureAsDeploymentFailure": false
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true
}
},
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"instanceView": {
"bootDiagnostics": {},
"computerName": "test-vm-1",
"disks": [
{
"name": "test-vm-1_disk1_aaabbbbbccccc123123123123123",
"statuses": [
{
"code": "ProvisioningState/succeeded",
"displayStatus": "Provisioning succeeded",
"level": "Info",
"time": "2023-12-21T00:00:00.9991605+00:00"
}
]
}
],
"extensions": [
{
"name": "enablevmAccess",
"statuses": [
{
"code": "ProvisioningState/succeeded",
"displayStatus": "Provisioning succeeded",
"level": "Info",
"message": "Enable succeeded."
}
],
"type": "Microsoft.OSTCExtensions.VMAccessForLinux",
"typeHandlerVersion": "1.5.18"
}
],
"hyperVGeneration": "V2",
"osName": "ubuntu",
"osVersion": "20.04",
"statuses": [
{
"code": "ProvisioningState/succeeded",
"displayStatus": "Provisioning succeeded",
"level": "Info",
"time": "2024-08-20T00:00:00.6656328+00:00"
},
{
"code": "PowerState/running",
"displayStatus": "VM running",
"level": "Info"
}
],
"vmAgent": {
"extensionHandlers": [
{
"status": {
"code": "ProvisioningState/succeeded",
"displayStatus": "Ready",
"level": "Info",
"message": "Plugin enabled"
},
"type": "Microsoft.OSTCExtensions.VMAccessForLinux",
"typeHandlerVersion": "1.5.18"
},
{
"status": {
"code": "ProvisioningState/succeeded",
"displayStatus": "Ready",
"level": "Info",
"message": "Plugin enabled"
},
"type": "Microsoft.CPlat.Core.VMApplicationManagerLinux",
"typeHandlerVersion": "1.0.13"
}
],
"statuses": [
{
"code": "ProvisioningState/succeeded",
"displayStatus": "Ready",
"level": "Info",
"message": "Guest Agent is running",
"time": "2024-08-27T15:43:14+00:00"
}
],
"vmAgentVersion": "1.1.1.9"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/aabbccd-123a-123d-a1a1-123aaabb123b/resourceGroups/fake-rg-1/providers/Microsoft.Network/networkInterfaces/test-vm-0000_z1",
"properties": {
"deleteOption": "Detach"
}
}
]
},
"osProfile": {
"adminUsername": "azureuser",
"allowExtensionOperations": true,
"computerName": "test-vm-1",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"enableVMAgentPlatformUpdates": false,
"patchSettings": {
"assessmentMode": "ImageDefault",
"patchMode": "ImageDefault"
},
"provisionVMAgent": true
},
"requireGuestProvisionSignal": true,
"secrets": []
},
"provisioningState": "Succeeded",
"storageProfile": {
"dataDisks": [],
"diskControllerType": "SCSI",
"imageReference": {
"exactVersion": "20.04.202312080",
"offer": "0001-com-ubuntu-server-focal",
"publisher": "canonical",
"sku": "20_04-lts-gen2",
"version": "latest"
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"deleteOption": "Delete",
"diskSizeGB": 30,
"managedDisk": {
"id": "/subscriptions/aabbccd-123a-123d-a1a1-123aaabb123b/resourceGroups/fake-rg-1/providers/Microsoft.Compute/disks/test-vm-1_disk1_d2f1bf7581b64d3191c7dc0569f22516",
"storageAccountType": "Premium_LRS"
},
"name": "test-vm-1_disk1_aaabbbbbccccc123123123123123",
"osType": "Linux"
}
},
"timeCreated": "2023-12-21T00:00:00.6553161+00:00",
"vmId": "aabbccd-123a-123d-a1a1-123aaabb123b"
},
"resources": [
{
"id": "/subscriptions/aabbccd-123a-123d-a1a1-123aaabb123b/resourceGroups/fake-rg-1/providers/Microsoft.Compute/virtualMachines/test-vm-1/extensions/enablevmAccess",
"location": "westeurope",
"name": "enablevmAccess",
"properties": {
"autoUpgradeMinorVersion": true,
"provisioningState": "Succeeded",
"publisher": "Microsoft.OSTCExtensions",
"type": "VMAccessForLinux",
"typeHandlerVersion": "1.5"
},
"type": "Microsoft.Compute/virtualMachines/extensions"
}
],
"tags": {
"owner": "fake@email.com",
"env": "dev"
},
"type": "Microsoft.Compute/virtualMachines",
"zones": [
"1"
]
}
6 changes: 6 additions & 0 deletions Packs/AzureCompute/ReleaseNotes/1_2_29.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Azure Compute v2

- Updated the `azure-vm-get-instance-details` command to add `Tags` from a VM instance to alert context.
2 changes: 1 addition & 1 deletion Packs/AzureCompute/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Azure Compute",
"description": "Create and Manage Azure Virtual Machines",
"support": "xsoar",
"currentVersion": "1.2.28",
"currentVersion": "1.2.29",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
Loading