Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Use VM id instead of resource id and fix default config
Browse files Browse the repository at this point in the history
  • Loading branch information
girodav committed Sep 19, 2023
1 parent 04a7dad commit 4b44eef
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 42 deletions.
22 changes: 11 additions & 11 deletions input/azure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ The Azure Assets Input supports the following configuration options plus the [Co

#### Exported fields

| Field | Description | Example |
|-------------------------------|-----------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| asset.type | The type of asset | `"azure.vm.instance"` |
| asset.kind | The kind of asset | `"host` |
| asset.id | The id of the Azure instance | `"/subscriptions/12cabcb4-86e8-404f-111111111111/resourceGroups/TESTVM/providers/Microsoft.Compute/virtualMachines/test"` |
| asset.ean | The EAN of this specific resource | `"host:/subscriptions/12cabcb4-86e8-404f-111111111111/resourceGroups/TESTVM/providers/Microsoft.Compute/virtualMachines/test"` |
| asset.metadata.resource_group | The Azure resource group | `TESTVM` |
| asset.metadata.state | The status of the VM instance | `"VM running"` |
| Field | Description | Example |
|-------------------------------|-----------------------------------|-----------------------------------------------|
| asset.type | The type of asset | `"azure.vm.instance"` |
| asset.kind | The kind of asset | `"host` |
| asset.id | The VM id of the Azure instance | `"00830b08-f63d-495b-9b04-989f83c50111"` |
| asset.ean | The EAN of this specific resource | `"host:00830b08-f63d-495b-9b04-989f83c50111"` |
| asset.metadata.resource_group | The Azure resource group | `TESTVM` |
| asset.metadata.state | The status of the VM instance | `"VM running"` |

#### Example

```json
{
"@timestamp": "2023-09-13T14:42:51.494Z",
"asset.metadata.resource_group": "GIZASVM",
"asset.metadata.resource_group": "TESTVM",
"host": {
"name": "host"
},
Expand All @@ -75,8 +75,8 @@ The Azure Assets Input supports the following configuration options plus the [Co
},
"cloud.account.id": "12cabcb4-86e8-404f-a3d2-111111111111",
"asset.kind": "host",
"asset.id": "/subscriptions/12cabcb4-86e8-404f-a3d2-111111111111/resourceGroups/GIZASVM/providers/Microsoft.Compute/virtualMachines/gizasvmWindowsenterprise",
"asset.ean": "host:/subscriptions/12cabcb4-86e8-404f-a3d2-111111111111/resourceGroups/GIZASVM/providers/Microsoft.Compute/virtualMachines/gizasvmWindowsenterprise",
"asset.id": "00830b08-f63d-495b-9b04-989f83c50111",
"asset.ean": "host:00830b08-f63d-495b-9b04-989f83c50111",
"asset.metadata.state": "VM running",
"asset.type": "azure.vm.instance",
"ecs": {
Expand Down
2 changes: 1 addition & 1 deletion input/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func defaultConfig() config {
Period: time.Second * 600,
AssetTypes: nil,
},
Regions: []string{"westeurope"},
Regions: []string{},
ClientID: "",
ClientSecret: "",
SubscriptionID: "",
Expand Down
2 changes: 1 addition & 1 deletion input/azure/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestAssetsAzure_Run(t *testing.T) {
assert.NoError(t, err)
}()

time.Sleep(time.Millisecond)
time.Sleep(time.Second)
cancel()
timeout := time.After(time.Second)
closeCh := make(chan struct{})
Expand Down
2 changes: 1 addition & 1 deletion input/azure/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func getAllAzureVMInstances(ctx context.Context, client *armcompute.VirtualMachi
status = *v.Properties.InstanceView.Statuses[1].DisplayStatus
}
vmInstance := AzureVMInstance{
ID: *v.ID,
ID: *v.Properties.VMID,
Name: *v.Name,
SubscriptionID: subscriptionId,
Region: *v.Location,
Expand Down
65 changes: 37 additions & 28 deletions input/azure/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,51 @@ const resourceGroup2 = "WRONGVM"
const subscriptionId = "12cabcb4-86e8-404f-111111111111"
const instance1Name = "instance1"

const instanceVMId1 = "1"

var instanceid1 = fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s", subscriptionId, resourceGroup1, instance1Name)

const instance2Name = "instance2"
const instanceVMId2 = "2"

var instanceid2 = fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s", subscriptionId, resourceGroup1, instance2Name)

const instance3Name = "instance3"
const instanceVMId3 = "3"

var instanceid3 = fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s", subscriptionId, resourceGroup1, instance3Name)

const instanceDiffResourceGroupName = "instanceDiffResourceGroup"
const instance4Name = "instance4"
const instanceVMId4 = "4"

var instanceIdDiffResourceGroup = fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s", subscriptionId, resourceGroup2, instanceDiffResourceGroupName)
var instanceIdDiffResourceGroup = fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s", subscriptionId, resourceGroup2, instance4Name)

var instance1 = armcompute.VirtualMachine{
Location: to.Ptr("westeurope"),
ID: to.Ptr(instanceid1),
Name: to.Ptr(instance1Name),
Location: to.Ptr("westeurope"),
ID: to.Ptr(instanceid1),
Name: to.Ptr(instance1Name),
Properties: &armcompute.VirtualMachineProperties{VMID: to.Ptr(instanceVMId1)},
}

var instance2 = armcompute.VirtualMachine{
Location: to.Ptr("northeurope"),
ID: to.Ptr(instanceid2),
Name: to.Ptr(instance2Name),
Location: to.Ptr("northeurope"),
ID: to.Ptr(instanceid2),
Name: to.Ptr(instance2Name),
Properties: &armcompute.VirtualMachineProperties{VMID: to.Ptr(instanceVMId2)},
}

var instance3 = armcompute.VirtualMachine{
Location: to.Ptr("eastus"),
ID: to.Ptr(instanceid3),
Name: to.Ptr(instance3Name),
Location: to.Ptr("eastus"),
ID: to.Ptr(instanceid3),
Name: to.Ptr(instance3Name),
Properties: &armcompute.VirtualMachineProperties{VMID: to.Ptr(instanceVMId3)},
}

var instanceDiffResourceGroup = armcompute.VirtualMachine{
Location: to.Ptr("northeurope"),
ID: to.Ptr(instanceIdDiffResourceGroup),
Name: to.Ptr(instanceDiffResourceGroupName),
Location: to.Ptr("northeurope"),
ID: to.Ptr(instanceIdDiffResourceGroup),
Name: to.Ptr(instance4Name),
Properties: &armcompute.VirtualMachineProperties{VMID: to.Ptr(instanceVMId4)},
}

func TestAssetsAzure_collectAzureAssets(t *testing.T) {
Expand Down Expand Up @@ -110,8 +119,8 @@ func TestAssetsAzure_collectAzureAssets(t *testing.T) {
expectedEvents: []beat.Event{
{
Fields: mapstr.M{
"asset.ean": "host:" + instanceid1,
"asset.id": instanceid1,
"asset.ean": "host:" + instanceVMId1,
"asset.id": instanceVMId1,
"asset.type": "azure.vm.instance",
"asset.kind": "host",
"asset.metadata.state": "",
Expand All @@ -126,8 +135,8 @@ func TestAssetsAzure_collectAzureAssets(t *testing.T) {
},
{
Fields: mapstr.M{
"asset.ean": "host:" + instanceid2,
"asset.id": instanceid2,
"asset.ean": "host:" + instanceVMId2,
"asset.id": instanceVMId2,
"asset.type": "azure.vm.instance",
"asset.kind": "host",
"asset.metadata.state": "",
Expand All @@ -142,8 +151,8 @@ func TestAssetsAzure_collectAzureAssets(t *testing.T) {
},
{
Fields: mapstr.M{
"asset.ean": "host:" + instanceid3,
"asset.id": instanceid3,
"asset.ean": "host:" + instanceVMId3,
"asset.id": instanceVMId3,
"asset.type": "azure.vm.instance",
"asset.kind": "host",
"asset.metadata.state": "",
Expand Down Expand Up @@ -181,8 +190,8 @@ func TestAssetsAzure_collectAzureAssets(t *testing.T) {
expectedEvents: []beat.Event{
{
Fields: mapstr.M{
"asset.ean": "host:" + instanceid1,
"asset.id": instanceid1,
"asset.ean": "host:" + instanceVMId1,
"asset.id": instanceVMId1,
"asset.type": "azure.vm.instance",
"asset.kind": "host",
"asset.metadata.state": "",
Expand All @@ -197,8 +206,8 @@ func TestAssetsAzure_collectAzureAssets(t *testing.T) {
},
{
Fields: mapstr.M{
"asset.ean": "host:" + instanceid2,
"asset.id": instanceid2,
"asset.ean": "host:" + instanceVMId2,
"asset.id": instanceVMId2,
"asset.type": "azure.vm.instance",
"asset.kind": "host",
"asset.metadata.state": "",
Expand Down Expand Up @@ -238,8 +247,8 @@ func TestAssetsAzure_collectAzureAssets(t *testing.T) {
expectedEvents: []beat.Event{
{
Fields: mapstr.M{
"asset.ean": "host:" + instanceid1,
"asset.id": instanceid1,
"asset.ean": "host:" + instanceVMId1,
"asset.id": instanceVMId1,
"asset.type": "azure.vm.instance",
"asset.kind": "host",
"asset.metadata.state": "",
Expand All @@ -254,8 +263,8 @@ func TestAssetsAzure_collectAzureAssets(t *testing.T) {
},
{
Fields: mapstr.M{
"asset.ean": "host:" + instanceid2,
"asset.id": instanceid2,
"asset.ean": "host:" + instanceVMId2,
"asset.id": instanceVMId2,
"asset.type": "azure.vm.instance",
"asset.kind": "host",
"asset.metadata.state": "",
Expand Down

0 comments on commit 4b44eef

Please sign in to comment.