diff --git a/.chloggen/vcenter-nil-pointer.yaml b/.chloggen/vcenter-nil-pointer.yaml new file mode 100644 index 000000000000..bd4c6434b64d --- /dev/null +++ b/.chloggen/vcenter-nil-pointer.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'bug_fix' + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: vcenterreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: collect VM may be panic nil pointer. + +# One or more tracking issues related to the change +issues: [16277] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/receiver/vcenterreceiver/scraper.go b/receiver/vcenterreceiver/scraper.go index 4081169c473a..d6747a61e883 100644 --- a/receiver/vcenterreceiver/scraper.go +++ b/receiver/vcenterreceiver/scraper.go @@ -269,8 +269,6 @@ func (v *vcenterMetricScraper) collectVMs( continue } - vmUUID := moVM.Config.InstanceUuid - if string(moVM.Runtime.PowerState) == "poweredOff" { poweredOffVMs++ } else { @@ -288,6 +286,12 @@ func (v *vcenterMetricScraper) collectVMs( return } + if moVM.Config == nil { + errs.AddPartial(1, fmt.Errorf("vm config empty for %s", hostname)) + continue + } + vmUUID := moVM.Config.InstanceUuid + v.collectVM(ctx, colTime, moVM, errs) v.mb.EmitForResource( metadata.WithVcenterVMName(vm.Name()),