From b1cdf075cb4392d250610f169632904421010a71 Mon Sep 17 00:00:00 2001 From: ishleenk17 Date: Tue, 3 Sep 2024 16:16:07 +0530 Subject: [PATCH 01/11] Add support of snapshot in virtualmachine --- .../module/vsphere/virtualmachine/data.go | 5 +++ .../vsphere/virtualmachine/data_test.go | 21 +++++++++++++ .../vsphere/virtualmachine/virtualmachine.go | 31 +++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/metricbeat/module/vsphere/virtualmachine/data.go b/metricbeat/module/vsphere/virtualmachine/data.go index 5c814105f90..00a563f4df8 100644 --- a/metricbeat/module/vsphere/virtualmachine/data.go +++ b/metricbeat/module/vsphere/virtualmachine/data.go @@ -72,5 +72,10 @@ func (m *MetricSet) mapEvent(data VMData) mapstr.M { if len(data.DatastoreNames) > 0 { event["datastore.names"] = data.DatastoreNames } + if len(data.Snapshots) > 0 { + event["snapshots"] = data.Snapshots + event["snapshots.count"] = len(data.Snapshots) + } + return event } diff --git a/metricbeat/module/vsphere/virtualmachine/data_test.go b/metricbeat/module/vsphere/virtualmachine/data_test.go index 351daea7c11..8edc5c9fe53 100644 --- a/metricbeat/module/vsphere/virtualmachine/data_test.go +++ b/metricbeat/module/vsphere/virtualmachine/data_test.go @@ -58,6 +58,16 @@ func TestEventMapping(t *testing.T) { "customField1": "value1", "customField2": "value2", }, + Snapshots: []VMSnapshotData{ + { + Name: "Snapshot1", + Description: "Test snapshot 1", + }, + { + Name: "Snapshot2", + Description: "Test snapshot 2", + }, + }, } event := m.mapEvent(data) @@ -108,6 +118,17 @@ func TestEventMapping(t *testing.T) { "network.names": []string{"network-1", "network-2"}, "network_names": []string{"network-1", "network-2"}, "datastore.names": []string{"ds1", "ds2"}, + "snapshots": []VMSnapshotData{ + { + Name: "Snapshot1", + Description: "Test snapshot 1", + }, + { + Name: "Snapshot2", + Description: "Test snapshot 2", + }, + }, + "snapshots.count": 2, } // Assert that the output event matches the expected event diff --git a/metricbeat/module/vsphere/virtualmachine/virtualmachine.go b/metricbeat/module/vsphere/virtualmachine/virtualmachine.go index 107aabbc4bd..81052e1eed8 100644 --- a/metricbeat/module/vsphere/virtualmachine/virtualmachine.go +++ b/metricbeat/module/vsphere/virtualmachine/virtualmachine.go @@ -22,6 +22,7 @@ import ( "errors" "fmt" "strings" + "time" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/vsphere" @@ -56,6 +57,13 @@ type VMData struct { NetworkNames []string DatastoreNames []string CustomFields mapstr.M + Snapshots []VMSnapshotData +} + +type VMSnapshotData struct { + Name string + Description string + CreateTime time.Time } // New creates a new instance of the MetricSet. @@ -136,6 +144,7 @@ func (m *MetricSet) Fetch(ctx context.Context, reporter mb.ReporterV2) error { var hostID, hostName string var networkNames, datastoreNames []string var customFields mapstr.M + var snapshots []VMSnapshotData if host := vm.Summary.Runtime.Host; host != nil { hostID = host.Value @@ -179,6 +188,10 @@ func (m *MetricSet) Fetch(ctx context.Context, reporter mb.ReporterV2) error { } } + if vm.Snapshot != nil { + snapshots = fetchSnapshots(vm.Snapshot.RootSnapshotList) + } + data := VMData{ VM: vm, HostID: hostID, @@ -186,6 +199,7 @@ func (m *MetricSet) Fetch(ctx context.Context, reporter mb.ReporterV2) error { NetworkNames: networkNames, DatastoreNames: datastoreNames, CustomFields: customFields, + Snapshots: snapshots, } reporter.Event(mb.Event{ @@ -270,3 +284,20 @@ func getHostSystem(ctx context.Context, c *vim25.Client, ref types.ManagedObject } return &hs, nil } + +func fetchSnapshots(snapshotTree []types.VirtualMachineSnapshotTree) []VMSnapshotData { + var snapshots []VMSnapshotData + for _, snapshot := range snapshotTree { + snapshots = append(snapshots, VMSnapshotData{ + Name: snapshot.Name, + Description: snapshot.Description, + CreateTime: snapshot.CreateTime, + }) + + // Recursively add child snapshots + if len(snapshot.ChildSnapshotList) > 0 { + snapshots = append(snapshots, fetchSnapshots(snapshot.ChildSnapshotList)...) + } + } + return snapshots +} From 28af39bdb96c4a52a7a9ca1635e93a204f8b5436 Mon Sep 17 00:00:00 2001 From: ishleenk17 Date: Wed, 4 Sep 2024 10:22:28 +0530 Subject: [PATCH 02/11] mage update and add fields.yml --- metricbeat/docs/fields.asciidoc | 18 ++++++++++++++++++ metricbeat/module/vsphere/fields.go | 2 +- .../vsphere/virtualmachine/_meta/fields.yml | 6 ++++++ .../module/vsphere/virtualmachine/data.go | 2 +- .../module/vsphere/virtualmachine/data_test.go | 2 +- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/metricbeat/docs/fields.asciidoc b/metricbeat/docs/fields.asciidoc index 953b15b83c0..b327b64e7b3 100644 --- a/metricbeat/docs/fields.asciidoc +++ b/metricbeat/docs/fields.asciidoc @@ -68090,6 +68090,24 @@ type: keyword The uptime of the VM in seconds. +type: long + +-- + +*`vsphere.virtualmachine.snapshots`*:: ++ +-- +Deatils of the snapshots of this virtualmachine. + +type: object + +-- + +*`vsphere.virtualmachine.snapshot.count`*:: ++ +-- +The number of snapshots of this virtualmachine. + type: long -- diff --git a/metricbeat/module/vsphere/fields.go b/metricbeat/module/vsphere/fields.go index 86bbe2a7704..6b63fd13737 100644 --- a/metricbeat/module/vsphere/fields.go +++ b/metricbeat/module/vsphere/fields.go @@ -32,5 +32,5 @@ func init() { // AssetVsphere returns asset data. // This is the base64 encoded zlib format compressed contents of module/vsphere. func AssetVsphere() string { - return "eJzUXE9v27gSv+dTDPbyWiD13nN4QF+K3RZ4aRd1NteApsYWXyhSjxzZcD/9gqT+2ZZky6acxIccHJvzm//DmZE/wQtu72Bt8xQN3gCQIIl38Nt67t/57QYgQcuNyElodQf/vgEAKP8LmU4K6b5mUCKzeAcrdgOwFCgTe+c/+gkUy7BNwr1om7sPG13k5TsdVHYPah/GZWEJTf1+14HuVcNaILHW+53Ewus+HA1CLbXJmPvIrPWBfURtVAkjZknXTA5j6zutfaL7aw/+W534gtuNNknH/wf4q17/FZZAL4FJCZQifKnAB6LArNVcMMIENoJS/5lS7LNevFwXinrxSq1W54H9XmQLNA5uDXMEwkY/9plr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NrNCmy/ueC32NqaOLjx0pCn4LtbISUsMB60e3QethCrxEE2VDkNCf+vxDGB9oIZUa1Enm19NFIqFJ4h3f1Lm6SBlM4A3y8vyyLcJ3lBm3futJRrk/0o4bbhmClyIbJ9l7q4/25zjTdMwiqNScz7U7//V68RJxSvcLkp7ylGNAFXHmMNhJirYbwtfJbRydTA4h6Txr/5IRvvcS+RC5dGBQDPzYxc//EX1Js++3AjlxUuuWAGO7LLNa/J6kjhoh9quWTsGoF83DrM/DQ1MTPyaSv9pzMEOXIz8l8WTMh2ULiUeLtReH+4U2MdWG9LGc2cbaaewcykbCWj4VFWRCPL9idNfF4kvVmGB9te+c+AlheWNLZU8gZnRD14n948GsQ4c2nS36pxhMuk9Vb2zZ/Vz88tnPf1zxH1/r9meoObbeQeM0Lv6TzV8dOwTnV7xhdS0Gq49eM3p5+zkU5VZ/0c7dHYirZ6ZNOuviJvpDWrKKVa17NKlqPVBTLbappRKDdgfEVGQlZm1J9XP3k+kmqKb91wdqZb5xrWzkdRvOffwIAAP//GH6+lQ==" } diff --git a/metricbeat/module/vsphere/virtualmachine/_meta/fields.yml b/metricbeat/module/vsphere/virtualmachine/_meta/fields.yml index 6720da18765..d5a86f69a4c 100644 --- a/metricbeat/module/vsphere/virtualmachine/_meta/fields.yml +++ b/metricbeat/module/vsphere/virtualmachine/_meta/fields.yml @@ -91,5 +91,11 @@ type: long description: > The uptime of the VM in seconds. + - name: snapshots + type: object + description: Deatils of the snapshots of this virtualmachine. + - name: snapshot.count + type: long + description: The number of snapshots of this virtualmachine. diff --git a/metricbeat/module/vsphere/virtualmachine/data.go b/metricbeat/module/vsphere/virtualmachine/data.go index 00a563f4df8..964cb7f7b78 100644 --- a/metricbeat/module/vsphere/virtualmachine/data.go +++ b/metricbeat/module/vsphere/virtualmachine/data.go @@ -74,7 +74,7 @@ func (m *MetricSet) mapEvent(data VMData) mapstr.M { } if len(data.Snapshots) > 0 { event["snapshots"] = data.Snapshots - event["snapshots.count"] = len(data.Snapshots) + event["snapshot.count"] = len(data.Snapshots) } return event diff --git a/metricbeat/module/vsphere/virtualmachine/data_test.go b/metricbeat/module/vsphere/virtualmachine/data_test.go index 8edc5c9fe53..4ff2466d7a1 100644 --- a/metricbeat/module/vsphere/virtualmachine/data_test.go +++ b/metricbeat/module/vsphere/virtualmachine/data_test.go @@ -128,7 +128,7 @@ func TestEventMapping(t *testing.T) { Description: "Test snapshot 2", }, }, - "snapshots.count": 2, + "snapshot.count": 2, } // Assert that the output event matches the expected event From 5649cf4069e492e10718c9dd49e6d08a11cb225a Mon Sep 17 00:00:00 2001 From: Ishleen Kaur <102962586+ishleenk17@users.noreply.github.com> Date: Wed, 4 Sep 2024 12:38:20 +0530 Subject: [PATCH 03/11] Update data_test.go --- metricbeat/module/vsphere/virtualmachine/data_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/metricbeat/module/vsphere/virtualmachine/data_test.go b/metricbeat/module/vsphere/virtualmachine/data_test.go index 4ff2466d7a1..fc4389c49c0 100644 --- a/metricbeat/module/vsphere/virtualmachine/data_test.go +++ b/metricbeat/module/vsphere/virtualmachine/data_test.go @@ -60,11 +60,11 @@ func TestEventMapping(t *testing.T) { }, Snapshots: []VMSnapshotData{ { - Name: "Snapshot1", + Name: "Snapshot_1", Description: "Test snapshot 1", }, { - Name: "Snapshot2", + Name: "Snapshot_2", Description: "Test snapshot 2", }, }, @@ -120,11 +120,11 @@ func TestEventMapping(t *testing.T) { "datastore.names": []string{"ds1", "ds2"}, "snapshots": []VMSnapshotData{ { - Name: "Snapshot1", + Name: "Snapshot_1", Description: "Test snapshot 1", }, { - Name: "Snapshot2", + Name: "Snapshot_2", Description: "Test snapshot 2", }, }, From d3b0d2943448002266d08e8ff90a59b5b3c3b955 Mon Sep 17 00:00:00 2001 From: ishleenk17 Date: Thu, 5 Sep 2024 16:21:43 +0530 Subject: [PATCH 04/11] address comments, mage update --- CHANGELOG.next.asciidoc | 1 + metricbeat/docs/fields.asciidoc | 5 +++-- metricbeat/module/vsphere/fields.go | 2 +- .../vsphere/virtualmachine/_meta/data.json | 16 +++++++++++++++- .../vsphere/virtualmachine/_meta/fields.yml | 17 ++++++++++------- .../module/vsphere/virtualmachine/data.go | 2 +- .../module/vsphere/virtualmachine/data_test.go | 4 ++-- 7 files changed, 33 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 0ece7c88964..42c96f9f145 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -60,6 +60,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - Update metrics for the vSphere Host metricset. {pull}40429[40429] - Mark system process metricsets as running if metrics are partially available {pull}40565[40565] - Added back `elasticsearch.node.stats.jvm.mem.pools.*` to the `node_stats` metricset {pull}40571[40571] +- Add support for snapshot information in virtualmachine {pull}40683[40683] *Osquerybeat* diff --git a/metricbeat/docs/fields.asciidoc b/metricbeat/docs/fields.asciidoc index b327b64e7b3..0016c473805 100644 --- a/metricbeat/docs/fields.asciidoc +++ b/metricbeat/docs/fields.asciidoc @@ -67947,7 +67947,7 @@ type: long *`vsphere.virtualmachine.cpu.total.mhz`*:: + -- -Total CPU in Mhz. +Total Reserved CPU in Mhz. type: long @@ -68094,7 +68094,8 @@ type: long -- -*`vsphere.virtualmachine.snapshots`*:: + +*`vsphere.virtualmachine.snapshot.info`*:: + -- Deatils of the snapshots of this virtualmachine. diff --git a/metricbeat/module/vsphere/fields.go b/metricbeat/module/vsphere/fields.go index 6b63fd13737..05e29ff253c 100644 --- a/metricbeat/module/vsphere/fields.go +++ b/metricbeat/module/vsphere/fields.go @@ -32,5 +32,5 @@ func init() { // AssetVsphere returns asset data. // This is the base64 encoded zlib format compressed contents of module/vsphere. func AssetVsphere() string { - return "eJzUXM1v2zgWv/eveJjLtkDqueewQDfFTAts2kGdyTWgqWeLG4rUkk82nL9+QFJftiXZsikn8aEoHJvv974/+OTP8IzbW1jbPEW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bYySK6ReT+DihnFHzp8SE8J+K5di52B8wCZ5JXoURbbOHT9/mhwGAvcQg+oNPUvAViO4x1tVbvYu2Fkf4gHq5z0jreJFazqtBS7xB3l8b1Ev7TUaoFAxUJKX6GCLfnRL1XVA1Lg3PcfcZ8B3ILvvxt1qRs3SqC3EJauzEkiK2VT7L4cY6l1DHmVtzXUaa2mNMDTSorKo1Ys4EViaO8nsCn49GVt84HhlUsLKwMU3XxdcBsKHuUVu9tzlxbnLde1sf+aayHs14D5x12m2/VklggbRDV4T73WZLYMD/4ewWiiG34v6xHHfZRL+d8waTUWk3MuxU/m/6wpgiZEWv/iPq5vn0aY3qNJkc2/Fzwa0wNbXx8GyX0LtjORkgJC2wW3Q6thy30GkGQDUVOe+L/K2F8oE1QZsSVyJulj1ZCUeE93jW4uEkaTOUM8PHhuizCdVEatEPrSke5PtGPWm5bglGRLZPdvdTHh0udabpnEFRnTma6nf7rvXhJOKX6BZOf+pZiRBdw4zHamRAbNYSv1d86OpkaQTR40vlPTvjWS+xL5NqFQTHyYxMz90/6JcWu347syCWlWw+I4aHOYsN7kjphiNinWj8Jq1YwD7c+Iw9NTfycTH7z52S+o0WzPhFC4gdmPqyZkGwh8Sjx7sbw8BQnxd6wXtbDmzTrzYOTmURY6+fDkmyKpxfszr54Osl6M0yPtrt8nwAsryzp4ikkj16IevE/PPhZiPDm0zU/WeMJ11nrpa2dv6pfINu5+GsfqOv8EE28TNutKH7lzV/W+/Njp+Cc6geNbqUg1fOzRi9PP5einKph+rbbLDGV7TRMJ90AJd9Ma3fS6n2vdidtQCqKlTbX6ZZuhFrqQTvoDdwHrH1CRkI25hkh2uax+NsZpW/MGxM8HUn7n38CAAD//7jW0PA=" } diff --git a/metricbeat/module/vsphere/virtualmachine/_meta/data.json b/metricbeat/module/vsphere/virtualmachine/_meta/data.json index d04a8efb42d..d2917e5e6a9 100644 --- a/metricbeat/module/vsphere/virtualmachine/_meta/data.json +++ b/metricbeat/module/vsphere/virtualmachine/_meta/data.json @@ -66,7 +66,21 @@ "datastore.names": [ "VxRailtec-Virtual-SAN-Datastore-247df-bc1d-5aad2" ], - "host.id": "host-20" + "host.id": "host-20", + "snapshot.info": [ + { + "Name": "Snapshot_1", + "Description": "Test snapshot 1", + "CreateTime": "2024-09-01T12:34:56Z" + + }, + { + "Name": "Snapshot_2", + "Description": "Test snapshot 2", + "CreateTime": "2024-09-03T2:34:56Z" + } + ], + "snapshot.count": 2 } } } diff --git a/metricbeat/module/vsphere/virtualmachine/_meta/fields.yml b/metricbeat/module/vsphere/virtualmachine/_meta/fields.yml index d5a86f69a4c..fcfe2b9bbb3 100644 --- a/metricbeat/module/vsphere/virtualmachine/_meta/fields.yml +++ b/metricbeat/module/vsphere/virtualmachine/_meta/fields.yml @@ -27,7 +27,7 @@ - name: cpu.total.mhz type: long description: > - Total CPU in Mhz. + Total Reserved CPU in Mhz. - name: cpu.free.mhz type: long description: > @@ -91,11 +91,14 @@ type: long description: > The uptime of the VM in seconds. - - name: snapshots - type: object - description: Deatils of the snapshots of this virtualmachine. - - name: snapshot.count - type: long - description: The number of snapshots of this virtualmachine. + - name: snapshot + type: group + fields: + - name: info + type: object + description: Deatils of the snapshots of this virtualmachine. + - name: count + type: long + description: The number of snapshots of this virtualmachine. diff --git a/metricbeat/module/vsphere/virtualmachine/data.go b/metricbeat/module/vsphere/virtualmachine/data.go index 964cb7f7b78..69d0bd1df54 100644 --- a/metricbeat/module/vsphere/virtualmachine/data.go +++ b/metricbeat/module/vsphere/virtualmachine/data.go @@ -73,7 +73,7 @@ func (m *MetricSet) mapEvent(data VMData) mapstr.M { event["datastore.names"] = data.DatastoreNames } if len(data.Snapshots) > 0 { - event["snapshots"] = data.Snapshots + event["snapshot.info"] = data.Snapshots event["snapshot.count"] = len(data.Snapshots) } diff --git a/metricbeat/module/vsphere/virtualmachine/data_test.go b/metricbeat/module/vsphere/virtualmachine/data_test.go index fc4389c49c0..a419478559b 100644 --- a/metricbeat/module/vsphere/virtualmachine/data_test.go +++ b/metricbeat/module/vsphere/virtualmachine/data_test.go @@ -118,10 +118,10 @@ func TestEventMapping(t *testing.T) { "network.names": []string{"network-1", "network-2"}, "network_names": []string{"network-1", "network-2"}, "datastore.names": []string{"ds1", "ds2"}, - "snapshots": []VMSnapshotData{ + "snapshot.info": []VMSnapshotData{ { Name: "Snapshot_1", - Description: "Test snapshot 1", + Description: "Test snapshot 1", }, { Name: "Snapshot_2", From 182f936b645f16ebcd76ae9891df9ea5d68123ae Mon Sep 17 00:00:00 2001 From: ishleenk17 Date: Thu, 5 Sep 2024 17:48:01 +0530 Subject: [PATCH 05/11] Lint error --- metricbeat/module/vsphere/virtualmachine/data_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metricbeat/module/vsphere/virtualmachine/data_test.go b/metricbeat/module/vsphere/virtualmachine/data_test.go index a419478559b..58fa9a8b194 100644 --- a/metricbeat/module/vsphere/virtualmachine/data_test.go +++ b/metricbeat/module/vsphere/virtualmachine/data_test.go @@ -121,7 +121,7 @@ func TestEventMapping(t *testing.T) { "snapshot.info": []VMSnapshotData{ { Name: "Snapshot_1", - Description: "Test snapshot 1", + Description: "Test snapshot 1", }, { Name: "Snapshot_2", From 07cdfd7c47c877cc76534ccd7f8ac0aa31384736 Mon Sep 17 00:00:00 2001 From: ishleenk17 Date: Thu, 5 Sep 2024 19:06:31 +0530 Subject: [PATCH 06/11] Add createtime --- metricbeat/module/vsphere/virtualmachine/data_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/metricbeat/module/vsphere/virtualmachine/data_test.go b/metricbeat/module/vsphere/virtualmachine/data_test.go index 58fa9a8b194..c85407af761 100644 --- a/metricbeat/module/vsphere/virtualmachine/data_test.go +++ b/metricbeat/module/vsphere/virtualmachine/data_test.go @@ -19,6 +19,7 @@ package virtualmachine import ( "testing" + "time" "github.com/stretchr/testify/assert" "github.com/vmware/govmomi/vim25/mo" @@ -62,10 +63,12 @@ func TestEventMapping(t *testing.T) { { Name: "Snapshot_1", Description: "Test snapshot 1", + CreateTime: time.Time{}, }, { Name: "Snapshot_2", Description: "Test snapshot 2", + CreateTime: time.Time{}, }, }, } @@ -122,10 +125,12 @@ func TestEventMapping(t *testing.T) { { Name: "Snapshot_1", Description: "Test snapshot 1", + CreateTime: time.Time{}, }, { Name: "Snapshot_2", Description: "Test snapshot 2", + CreateTime: time.Time{}, }, }, "snapshot.count": 2, From 9a3797f57c8a04db063a200a8d4c09941ccd3631 Mon Sep 17 00:00:00 2001 From: Ishleen Kaur <102962586+ishleenk17@users.noreply.github.com> Date: Thu, 5 Sep 2024 22:13:38 +0530 Subject: [PATCH 07/11] Update CHANGELOG.next.asciidoc --- CHANGELOG.next.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index bd675026c7d..bff7ef00749 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -60,7 +60,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - Update metrics for the vSphere Host metricset. {pull}40429[40429] - Mark system process metricsets as running if metrics are partially available {pull}40565[40565] - Added back `elasticsearch.node.stats.jvm.mem.pools.*` to the `node_stats` metricset {pull}40571[40571] -- Add support for snapshot information in virtualmachine {pull}40683[40683] +- Add support for snapshot in virtualmachine {pull}40683[40683] *Osquerybeat* From 05fb025cd2881985c497cd431bd155a52f1b5090 Mon Sep 17 00:00:00 2001 From: ishleenk17 Date: Thu, 5 Sep 2024 23:26:20 +0530 Subject: [PATCH 08/11] Add state and id for snapshot --- metricbeat/module/vsphere/virtualmachine/data_test.go | 8 ++++++++ .../module/vsphere/virtualmachine/virtualmachine.go | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/metricbeat/module/vsphere/virtualmachine/data_test.go b/metricbeat/module/vsphere/virtualmachine/data_test.go index c85407af761..fd3820bd854 100644 --- a/metricbeat/module/vsphere/virtualmachine/data_test.go +++ b/metricbeat/module/vsphere/virtualmachine/data_test.go @@ -61,14 +61,18 @@ func TestEventMapping(t *testing.T) { }, Snapshots: []VMSnapshotData{ { + ID: 123, Name: "Snapshot_1", Description: "Test snapshot 1", CreateTime: time.Time{}, + State: types.VirtualMachinePowerStatePoweredOff, }, { + ID: 745, Name: "Snapshot_2", Description: "Test snapshot 2", CreateTime: time.Time{}, + State: types.VirtualMachinePowerStatePoweredOn, }, }, } @@ -123,14 +127,18 @@ func TestEventMapping(t *testing.T) { "datastore.names": []string{"ds1", "ds2"}, "snapshot.info": []VMSnapshotData{ { + ID: 123, Name: "Snapshot_1", Description: "Test snapshot 1", CreateTime: time.Time{}, + State: types.VirtualMachinePowerStatePoweredOff, }, { + ID: 745, Name: "Snapshot_2", Description: "Test snapshot 2", CreateTime: time.Time{}, + State: types.VirtualMachinePowerStatePoweredOn, }, }, "snapshot.count": 2, diff --git a/metricbeat/module/vsphere/virtualmachine/virtualmachine.go b/metricbeat/module/vsphere/virtualmachine/virtualmachine.go index 81052e1eed8..2f12632c336 100644 --- a/metricbeat/module/vsphere/virtualmachine/virtualmachine.go +++ b/metricbeat/module/vsphere/virtualmachine/virtualmachine.go @@ -61,9 +61,11 @@ type VMData struct { } type VMSnapshotData struct { + ID int32 Name string Description string CreateTime time.Time + State types.VirtualMachinePowerState } // New creates a new instance of the MetricSet. @@ -286,12 +288,14 @@ func getHostSystem(ctx context.Context, c *vim25.Client, ref types.ManagedObject } func fetchSnapshots(snapshotTree []types.VirtualMachineSnapshotTree) []VMSnapshotData { - var snapshots []VMSnapshotData + snapshots := make([]VMSnapshotData, 0, len(snapshotTree)) for _, snapshot := range snapshotTree { snapshots = append(snapshots, VMSnapshotData{ + ID: snapshot.Id, Name: snapshot.Name, Description: snapshot.Description, CreateTime: snapshot.CreateTime, + State: snapshot.State, }) // Recursively add child snapshots From 71c0235322f199e975da15fe16aee4ddf0fc8aae Mon Sep 17 00:00:00 2001 From: ishleenk17 Date: Thu, 5 Sep 2024 23:33:19 +0530 Subject: [PATCH 09/11] update changelog --- CHANGELOG.next.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index bff7ef00749..c49f632b297 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -60,7 +60,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - Update metrics for the vSphere Host metricset. {pull}40429[40429] - Mark system process metricsets as running if metrics are partially available {pull}40565[40565] - Added back `elasticsearch.node.stats.jvm.mem.pools.*` to the `node_stats` metricset {pull}40571[40571] -- Add support for snapshot in virtualmachine {pull}40683[40683] +- Add support for snapshot in vSphere virtualmachine metricset {pull}40683[40683] *Osquerybeat* From ed1551078149271b8a550caaad06456f36aaebad Mon Sep 17 00:00:00 2001 From: ishleenk17 Date: Thu, 5 Sep 2024 23:47:51 +0530 Subject: [PATCH 10/11] lint change --- .../module/vsphere/virtualmachine/data_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/metricbeat/module/vsphere/virtualmachine/data_test.go b/metricbeat/module/vsphere/virtualmachine/data_test.go index fd3820bd854..e11d39a8197 100644 --- a/metricbeat/module/vsphere/virtualmachine/data_test.go +++ b/metricbeat/module/vsphere/virtualmachine/data_test.go @@ -61,18 +61,18 @@ func TestEventMapping(t *testing.T) { }, Snapshots: []VMSnapshotData{ { - ID: 123, + ID: 123, Name: "Snapshot_1", Description: "Test snapshot 1", CreateTime: time.Time{}, - State: types.VirtualMachinePowerStatePoweredOff, + State: types.VirtualMachinePowerStatePoweredOff, }, { - ID: 745, + ID: 745, Name: "Snapshot_2", Description: "Test snapshot 2", CreateTime: time.Time{}, - State: types.VirtualMachinePowerStatePoweredOn, + State: types.VirtualMachinePowerStatePoweredOn, }, }, } @@ -127,18 +127,18 @@ func TestEventMapping(t *testing.T) { "datastore.names": []string{"ds1", "ds2"}, "snapshot.info": []VMSnapshotData{ { - ID: 123, + ID: 123, Name: "Snapshot_1", Description: "Test snapshot 1", CreateTime: time.Time{}, - State: types.VirtualMachinePowerStatePoweredOff, + State: types.VirtualMachinePowerStatePoweredOff, }, { - ID: 745, + ID: 745, Name: "Snapshot_2", Description: "Test snapshot 2", CreateTime: time.Time{}, - State: types.VirtualMachinePowerStatePoweredOn, + State: types.VirtualMachinePowerStatePoweredOn, }, }, "snapshot.count": 2, From 9ea3e420f3be315dc747376480dd366f930713fc Mon Sep 17 00:00:00 2001 From: ishleenk17 Date: Fri, 6 Sep 2024 00:01:02 +0530 Subject: [PATCH 11/11] lint change --- metricbeat/module/vsphere/virtualmachine/virtualmachine.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/metricbeat/module/vsphere/virtualmachine/virtualmachine.go b/metricbeat/module/vsphere/virtualmachine/virtualmachine.go index 2f12632c336..82c92800410 100644 --- a/metricbeat/module/vsphere/virtualmachine/virtualmachine.go +++ b/metricbeat/module/vsphere/virtualmachine/virtualmachine.go @@ -291,11 +291,11 @@ func fetchSnapshots(snapshotTree []types.VirtualMachineSnapshotTree) []VMSnapsho snapshots := make([]VMSnapshotData, 0, len(snapshotTree)) for _, snapshot := range snapshotTree { snapshots = append(snapshots, VMSnapshotData{ - ID: snapshot.Id, + ID: snapshot.Id, Name: snapshot.Name, Description: snapshot.Description, CreateTime: snapshot.CreateTime, - State: snapshot.State, + State: snapshot.State, }) // Recursively add child snapshots