diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index affd6418e95..d68ffc29fb9 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -162,6 +162,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Fix getting gcp compute instance metadata with partial zone/region in config. {pull}18757[18757] - Add missing network.sent_packets_count metric into compute metricset in googlecloud module. {pull}18802[18802] - Fix compute and pubsub dashboard for googlecloud module. {issue}18962[18962] {pull}18980[18980] +- Fix crash on vsphere module when Host information is not available. {issue}18996[18996] {pull}19078[19078] *Packetbeat* diff --git a/metricbeat/module/vsphere/virtualmachine/virtualmachine.go b/metricbeat/module/vsphere/virtualmachine/virtualmachine.go index 82dd9c90ad8..1179b36b5b8 100644 --- a/metricbeat/module/vsphere/virtualmachine/virtualmachine.go +++ b/metricbeat/module/vsphere/virtualmachine/virtualmachine.go @@ -164,20 +164,20 @@ func (m *MetricSet) Fetch(ctx context.Context, reporter mb.ReporterV2) error { }, } - if vm.Summary.Runtime.Host != nil { - event["host.id"] = vm.Summary.Runtime.Host.Value + if host := vm.Summary.Runtime.Host; host != nil { + event["host.id"] = host.Value + hostSystem, err := getHostSystem(ctx, c, host.Reference()) + if err == nil { + event["host.hostname"] = hostSystem.Summary.Config.Name + } else { + m.Logger().Debug(err.Error()) + } } else { m.Logger().Debug("'Host', 'Runtime' or 'Summary' data not found. This is either a parsing error " + "from vsphere library, an error trying to reach host/guest or incomplete information returned " + "from host/guest") } - hostSystem, err := getHostSystem(ctx, c, vm.Summary.Runtime.Host.Reference()) - if err != nil { - m.Logger().Debug(err.Error()) - } else { - event["host.hostname"] = hostSystem.Summary.Config.Name - } // Get custom fields (attributes) values if get_custom_fields is true. if m.GetCustomFields && vm.Summary.CustomValue != nil { customFields := getCustomFields(vm.Summary.CustomValue, customFieldsMap)