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

panic: runtime at property.(*Collector).Retrieve #933

Closed
amandahla opened this issue Nov 22, 2017 · 2 comments
Closed

panic: runtime at property.(*Collector).Retrieve #933

amandahla opened this issue Nov 22, 2017 · 2 comments

Comments

@amandahla
Copy link

amandahla commented Nov 22, 2017

I'm collecting vms like this:

        mgr := view.NewManager(c)

	v, err := mgr.CreateContainerView(ctx, c.ServiceContent.RootFolder, []string{"VirtualMachine"}, true)
	if err != nil {
		return nil, err
	}

	defer v.Destroy(ctx)

	// Retrieve summary property for all machines
	var vmt []mo.VirtualMachine
	err = v.Retrieve(ctx, []string{"VirtualMachine"}, []string{"summary"}, &vmt)
	if err != nil {
		return nil, err
	}

Then I want to see the network names from which VM and made like this:

        pc := property.DefaultCollector(c)

	var nets []mo.Network
	err := pc.Retrieve(ctx, vm.Network, []string{"name", "summary"}, &nets)
	if err != nil {
		return nil, err
	}

	for _, net := range nets {
		name := strings.Replace(net.Name, ".", "_", -1)
		outputNetworkNames.Put("name", name)
	}

Then I got:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x230becc]

goroutine 90 [running]:
github.com/elastic/beats/metricbeat/module/vsphere/vendor/github.com/vmware/govmomi/property.(*Collector).Retrieve(0xc420051370, 0x3714980, 0xc420346200, 0x0, 0x0, 0x0, 0xc42022e110, 0x1, 0x1, 0x2423000, ...)
	/home/user/project/beats/src/github.com/elastic/beats/metricbeat/module/vsphere/vendor/github.com/vmware/govmomi/property/collector.go:157 +0x50c
github.com/elastic/beats/metricbeat/module/vsphere/virtualmachine.getNetworkNames(0x3714980, 0xc420346200, 0xc4202ec580, 0x0, 0x0, 0x0, 0x4, 0x1000000007, 0x0)

I don't know why this is happening here. Any help?

@dougm
Copy link
Member

dougm commented Nov 22, 2017

Avoid the call toRetrieve if len(vm.Network) == 0. We can also change Retrieve to handle that case.

@amandahla
Copy link
Author

Great @dougm
You made me see that I was doing wrong actually. Since I retrieved only Summary, I needed to use vm.Summary.Vm.Reference() instead vm.Network then retrieve this reference for finally get network.

        pc := property.DefaultCollector(c)

	var vm mo.VirtualMachine
	err := pc.RetrieveOne(ctx, vm.Summary.Vm.Reference(), []string{"network"}, &vm)
	if err != nil {
		return nil, err
	}

	if len(vm.Network) == 0 {
		return nil, nil
	}

	var nets []mo.Network
	err = pc.Retrieve(ctx, vm.Network, []string{"name"}, &nets)
	if err != nil {
		return nil, err
	}

	for _, net := range nets {
		name := strings.Replace(net.Name, ".", "_", -1)
		outputNetworkNames.Put("name", name)
	}

amandahla pushed a commit to estaleiro/govmomi that referenced this issue Nov 23, 2017
@dougm dougm closed this as completed in 426a675 Nov 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants