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

[vSphere] Add id field to all the metricsets #41097

Merged
merged 11 commits into from
Oct 22, 2024
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Added Cisco Meraki module {pull}40836[40836]
- Added Palo Alto Networks module {pull}40686[40686]
- Restore docker.network.in.* and docker.network.out.* fields in docker module {pull}40968[40968]
- Add `id` field to all the vSphere metricsets. {pill}41097[41097]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Add `id` field to all the vSphere metricsets. {pill}41097[41097]
- Add `id` field to all the vSphere metricsets. {pull}41097[41097]


*Metricbeat*

Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/vsphere/cluster/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"entity_name": "121.0.0.0"
}
],
"id": "domain-c1",
"name": "Cluster_1",
"das_config": {
"enabled": false,
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/module/vsphere/cluster/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
type: keyword
description: >
List of all the Host names associated with the cluster.
- name: id
type: keyword
description: >
Cluster ID.
- name: name
type: keyword
description: >
Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/vsphere/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestFetchEventContents(t *testing.T) {

testEvent := mapstr.M{
"name": "DC0_C0",
"id": "domain-c29",
"host": mapstr.M{
"count": 3,
"names": []string{"DC0_C0_H0", "DC0_C0_H1", "DC0_C0_H2"},
Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/vsphere/cluster/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

func (m *ClusterMetricSet) mapEvent(cl mo.ClusterComputeResource, data *metricData) mapstr.M {
event := mapstr.M{
"id": cl.Self.Value,
"host": mapstr.M{
"count": len(data.assetNames.outputHostNames),
"names": data.assetNames.outputHostNames,
Expand Down
6 changes: 6 additions & 0 deletions metricbeat/module/vsphere/cluster/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func TestEventMapping(t *testing.T) {
ComputeResource: mo.ComputeResource{
ManagedEntity: mo.ManagedEntity{
Name: "Cluster_0",
ExtensibleManagedObject: mo.ExtensibleManagedObject{
Self: types.ManagedObjectReference{
Value: "CS_0",
},
},
},
},
Configuration: types.ClusterConfigInfo{
Expand Down Expand Up @@ -64,6 +69,7 @@ func TestEventMapping(t *testing.T) {
},
},
"name": "Cluster_0",
"id": "CS_0",
"host": mapstr.M{
"count": 1,
"names": []string{"Host_0"},
Expand Down
3 changes: 2 additions & 1 deletion metricbeat/module/vsphere/datastore/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
}
},
"fstype": "local",
"name": "LocalDS_0"
"name": "LocalDS_0",
"id": "datastore-0"
}
}
}
4 changes: 4 additions & 0 deletions metricbeat/module/vsphere/datastore/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
type: keyword
description: >
List of all the host names.
- name: id
type: keyword
description: >
Datastore ID.
- name: name
type: keyword
description: >
Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/vsphere/datastore/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
func (m *DataStoreMetricSet) mapEvent(ds mo.Datastore, data *metricData) mapstr.M {
event := mapstr.M{
"name": ds.Summary.Name,
"id": ds.Self.Value,
"fstype": ds.Summary.Type,
"status": ds.OverallStatus,
"host": mapstr.M{
Expand Down
6 changes: 6 additions & 0 deletions metricbeat/module/vsphere/datastore/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func TestEventMapping(t *testing.T) {
},
ManagedEntity: mo.ManagedEntity{
OverallStatus: "green",
ExtensibleManagedObject: mo.ExtensibleManagedObject{
Self: types.ManagedObjectReference{
Value: "DS_1",
},
},
},
Host: []types.DatastoreHostMount{},
Vm: []types.ManagedObjectReference{
Expand All @@ -61,6 +66,7 @@ func TestEventMapping(t *testing.T) {
outputEvent := (&DataStoreMetricSet{}).mapEvent(datastoreTest, &metricDataTest)
testEvent := mapstr.M{
"fstype": "local",
"id": "DS_1",
"status": types.ManagedEntityStatus("green"),
"name": "datastore-test",
"host": mapstr.M{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"vsphere": {
"datastorecluster": {
"id": "group-p1",
"name": "datastore_cluster1",
"capacity": {
"bytes": 8795019280384
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/module/vsphere/datastorecluster/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
description: >
Datastore Cluster
fields:
- name: id
type: keyword
description: >
Datastore Cluster ID.
- name: name
type: keyword
description: >
Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/vsphere/datastorecluster/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
func (m *DatastoreClusterMetricSet) mapEvent(datastoreCluster mo.StoragePod, data *metricData) mapstr.M {
event := mapstr.M{
"name": datastoreCluster.Name,
"id": datastoreCluster.Self.Value,
"capacity": mapstr.M{
"bytes": datastoreCluster.Summary.Capacity,
},
Expand Down
8 changes: 8 additions & 0 deletions metricbeat/module/vsphere/datastorecluster/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func TestEventMapping(t *testing.T) {
Folder: mo.Folder{
ManagedEntity: mo.ManagedEntity{
Name: "Folder1",
ExtensibleManagedObject: mo.ExtensibleManagedObject{
Self: types.ManagedObjectReference{
Value: "FL_0",
},
},
},
},
}
Expand All @@ -43,6 +48,9 @@ func TestEventMapping(t *testing.T) {
name, _ := event.GetValue("name")
assert.Equal(t, "Folder1", name)

id, _ := event.GetValue("id")
assert.Equal(t, "FL_0", id)

capacity, _ := event.GetValue("capacity.bytes")
assert.Equal(t, int64(100), capacity)

Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/vsphere/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions metricbeat/module/vsphere/host/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"network_names": [
"VM Network"
],
"id": "host-0",
"name": "DC0_H0",
"status": "green",
"uptime": 1728865
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/module/vsphere/host/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
description: >
Sum of disk read and write rates each second in bytes.
format: bytes
- name: id
type: keyword
description: >
Host ID.
- name: memory.free.bytes
type: long
description: >
Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/vsphere/host/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (m *HostMetricSet) mapEvent(hs mo.HostSystem, data *metricData) mapstr.M {
const bytesMultiplier int64 = 1024 * 1024
event := mapstr.M{
"name": hs.Summary.Config.Name,
"id": hs.Self.Value,
"status": hs.Summary.OverallStatus,
"uptime": hs.Summary.QuickStats.Uptime,
"cpu": mapstr.M{"used": mapstr.M{"mhz": hs.Summary.QuickStats.OverallCpuUsage}},
Expand Down
10 changes: 10 additions & 0 deletions metricbeat/module/vsphere/host/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ import (
func TestEventMapping(t *testing.T) {
var m *HostMetricSet
HostSystemTest := mo.HostSystem{
ManagedEntity: mo.ManagedEntity{
ExtensibleManagedObject: mo.ExtensibleManagedObject{
Self: types.ManagedObjectReference{
Value: "ha-host",
},
},
},
Summary: types.HostListSummary{
Host: &types.ManagedObjectReference{Type: "HostSystem", Value: "ha-host"},
Hardware: &types.HostHardwareSummary{
Expand Down Expand Up @@ -81,6 +88,9 @@ func TestEventMapping(t *testing.T) {
cpuTotal, _ := event.GetValue("cpu.total.mhz")
assert.EqualValues(t, 4588, cpuTotal)

id, _ := event.GetValue("id")
assert.EqualValues(t, "ha-host", id)

cpuFree, _ := event.GetValue("cpu.free.mhz")
assert.EqualValues(t, 4521, cpuFree)

Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/vsphere/network/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
],
"count": 2
},
"id": "network-1",
"name": "VM Network",
"status": "green",
"accessible": true,
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/module/vsphere/network/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
type: long
description: >
Number of hosts connected to this network.
- name: id
type: keyword
description: >
Network ID.
- name: name
type: keyword
description: >
Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/vsphere/network/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
func (m *NetworkMetricSet) mapEvent(net mo.Network, data *metricData) mapstr.M {
event := mapstr.M{}

event.Put("id", net.Self.Value)
event.Put("name", net.Name)
event.Put("status", net.OverallStatus)
event.Put("accessible", net.Summary.GetNetworkSummary().Accessible)
Expand Down
6 changes: 5 additions & 1 deletion metricbeat/module/vsphere/network/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func TestEventMapping(t *testing.T) {
ConfigStatus: "green",
ExtensibleManagedObject: mo.ExtensibleManagedObject{
Self: types.ManagedObjectReference{
Type: "Network",
Type: "Network",
Value: "NT_0",
},
},
},
Expand All @@ -54,6 +55,9 @@ func TestEventMapping(t *testing.T) {
name, _ := event.GetValue("name")
assert.NotNil(t, name)

id, _ := event.GetValue("id")
assert.EqualValues(t, "NT_0", id)

status, _ := event.GetValue("status")
assert.Equal(t, types.ManagedEntityStatus("green"), status)

Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/vsphere/resourcepool/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"vsphere": {
"resourcepool": {
"id": "resgroup-30",
"name": "Resources",
"status": "green",
"vm": {
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/module/vsphere/resourcepool/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
type: long
description: >
The static CPU resource entitlement for a virtual machine.
- name: id
type: keyword
description: >
Resource Pool ID.
- name: memory
type: group
fields:
Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/vsphere/resourcepool/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (m *ResourcePoolMetricSet) mapEvent(rp mo.ResourcePool, data *metricData) m
event := mapstr.M{
"name": rp.Name,
"status": rp.OverallStatus,
"id": rp.Self.Value,
}

quickStats := rp.Summary.GetResourcePoolSummary().QuickStats
Expand Down
8 changes: 8 additions & 0 deletions metricbeat/module/vsphere/resourcepool/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
ManagedEntity: mo.ManagedEntity{
OverallStatus: "green",
Name: "resourcepool-test",
ExtensibleManagedObject: mo.ExtensibleManagedObject{
Self: types.ManagedObjectReference{
Value: "RS_0",
},
},
},
Summary: &types.ResourcePoolSummary{
QuickStats: &types.ResourcePoolQuickStats{
Expand Down Expand Up @@ -70,7 +75,10 @@
status, _ := event.GetValue("status")
assert.EqualValues(t, "green", status)

id, _ := event.GetValue("id")
assert.EqualValues(t, "RS_0", id)

name := event["name"].(string)

Check failure on line 81 in metricbeat/module/vsphere/resourcepool/data_test.go

View workflow job for this annotation

GitHub Actions / lint (windows)

Error return value is not checked (errcheck)

Check failure on line 81 in metricbeat/module/vsphere/resourcepool/data_test.go

View workflow job for this annotation

GitHub Actions / lint (linux)

Error return value is not checked (errcheck)
assert.EqualValues(t, name, "resourcepool-test")

cpuUsage, _ := event.GetValue("cpu.usage.mhz")
Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/vsphere/virtualmachine/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"vsphere": {
"virtualmachine": {
"id": "vm-51",
"name": "xt0nmfpv9",
"uptime": 5348978,
"status": "green",
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/module/vsphere/virtualmachine/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
type: keyword
description: >
Hostname of the host.
- name: id
type: keyword
description: >
Virtual Machine ID.
- name: name
type: keyword
description: >
Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/vsphere/virtualmachine/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (m *MetricSet) mapEvent(data VMData) mapstr.M {

event := mapstr.M{
"name": data.VM.Summary.Config.Name,
"id": data.VM.Self.Value,
"os": data.VM.Summary.Config.GuestFullName,
"uptime": data.VM.Summary.QuickStats.UptimeSeconds,
"status": data.VM.Summary.OverallStatus,
Expand Down
8 changes: 8 additions & 0 deletions metricbeat/module/vsphere/virtualmachine/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ func TestEventMapping(t *testing.T) {
var m MetricSet

VirtualMachineTest := mo.VirtualMachine{
ManagedEntity: mo.ManagedEntity{
ExtensibleManagedObject: mo.ExtensibleManagedObject{
Self: types.ManagedObjectReference{
Value: "VM_0",
},
},
},
Summary: types.VirtualMachineSummary{
OverallStatus: types.ManagedEntityStatus("green"),
Config: types.VirtualMachineConfigSummary{
Expand Down Expand Up @@ -83,6 +90,7 @@ func TestEventMapping(t *testing.T) {
expectedEvent := mapstr.M{
"name": "localhost.localdomain",
"os": "otherGuest",
"id": "VM_0",
"uptime": int32(10),
"status": types.ManagedEntityStatus("green"),
"cpu": mapstr.M{
Expand Down
Loading