Skip to content

feat(inputs.vsphere): Allow adding custom properties as fields#19161

Open
tguenneguez wants to merge 31 commits into
influxdata:masterfrom
tguenneguez:add-custom-properties-vsphere
Open

feat(inputs.vsphere): Allow adding custom properties as fields#19161
tguenneguez wants to merge 31 commits into
influxdata:masterfrom
tguenneguez:add-custom-properties-vsphere

Conversation

@tguenneguez

@tguenneguez tguenneguez commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Add the capabilitie to collecte properties of elements.

For sample :

  • host :
    • summary.runtime.powerState
    • summary.overallStatus
    • summary.runtime.inMaintenanceMode
    • summary.runtime.connectionState
  • vm :
    • runtime.powerState
  • cluster :
    • overallStatus
    • configuration.drsConfig.enabled
  • datastore :
    • summary.accessible
  • resource_pool :
    • overallStatus

This change collect data for VM Power Off. There was no information about this subtility.

Checklist

Related issues

resolves #18858

@tguenneguez tguenneguez changed the title feat(input.vsphere) : add custom properties feat(inputs.vsphere) : add custom properties Jun 25, 2026
@tguenneguez tguenneguez changed the title feat(inputs.vsphere) : add custom properties feat(inputs.vsphere): add custom properties Jun 29, 2026
@telegraf-tiger telegraf-tiger Bot added area/vsphere feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Jun 29, 2026
@srebhan

srebhan commented Jul 3, 2026

Copy link
Copy Markdown
Member

Thanks for your contribution @tguenneguez! Can you please check and fix the linter issues!? Furthermore, you can't check "I've used no AI" and "I've used AI" at the same time. :-) Please fix the checkboxes in the PR description. :-)

@srebhan srebhan self-assigned this Jul 3, 2026
@tguenneguez

Copy link
Copy Markdown
Contributor Author

Yes, I have seen it, but I do lot off think in the same time so, i change when I have time.
I think it will be good.

@srebhan srebhan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution @tguenneguez! I do have some comments in the code. IMO, the most important issues are

  1. You are changing unrelated parts of the code resulting in a larger diff than necessary. Please avoid changing code you don't need to touch in this PR. If you want it changed, do it in a separate PR!
  2. Spelling and comments are French AFAICS. Please check spelling and convert everything to English please!

Looking forward to your update of the PR!

Comment thread plugins/inputs/vsphere/endpoint.go
Comment thread plugins/inputs/vsphere/endpoint.go Outdated
Comment thread plugins/inputs/vsphere/endpoint.go Outdated
Comment thread plugins/inputs/vsphere/endpoint.go Outdated
Comment thread plugins/inputs/vsphere/endpoint.go
// resourceInfo is a utility class grouping a type and relevant parameters.
type resourceInfo struct {
resType string
custoFields []string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This abbreviation saves one character while humpering readability a lot. Please be generous and add the m here. :-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's because of resourceFilter containe a resType

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry but custo is not a word! Use customFields please. I don't see how this is related to resType or resourceFilter at all.

fields = append(fields, af...)
}
fields = append(fields, resourceInfo.custoFields...)
uniqueFields := removeDuplicates(fields)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

fields are defined by resourceInfo.custoFields which in turn stem from user-settings, don't they? If so, wouldn't it be better to deduplicate those user-settings in Init instead of doing it in every gather cycle?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It will be, but they are agregate to addFields[resourceInfo.resType].
To be able to do this, it will be necessaire to agregate this info only one time...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm talking about removeDuplicates here. You are removing duplicates from something that is user-set and does not change over the lifetime of the plugin (that's at least my understanding). Instead of doing this every time you collect data you could remove the duplicates once in the plugin's Init function and save processing time by removing the function call here.

Comment thread plugins/inputs/vsphere/README.md Outdated
Comment thread plugins/inputs/vsphere/vsphere.go Outdated
Comment thread plugins/inputs/vsphere/vsphere_test.go Outdated
@srebhan srebhan changed the title feat(inputs.vsphere): add custom properties feat(inputs.vsphere): Allow adding custom properties as fields Jul 15, 2026

@srebhan srebhan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @tguenneguez for your update. I have some more comments. Please check spelling of your variables as propertie is not an English word.

Comment thread plugins/inputs/vsphere/endpoint.go Outdated
include []string
simple bool
metrics performance.MetricList
parent string
latestSample time.Time
lastColl time.Time
propertieInclude []string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Spelling. How about

Suggested change
propertieInclude []string
propertiesInclude []string

// resourceInfo is a utility class grouping a type and relevant parameters.
type resourceInfo struct {
resType string
custoFields []string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry but custo is not a word! Use customFields please. I don't see how this is related to resType or resourceFilter at all.

}

// findAll returns the union of resources found given the supplied resource type and paths.
func (f *finder) findAll(ctx context.Context, resType string, paths, excludePaths []string, dst interface{}) error {
func (f *finder) findAll(ctx context.Context, resourceInfo resourceInfo, paths, excludePaths []string, dst interface{}) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Having variables named the same as types is usually confusing, how about

Suggested change
func (f *finder) findAll(ctx context.Context, resourceInfo resourceInfo, paths, excludePaths []string, dst interface{}) error {
func (f *finder) findAll(ctx context.Context, resource resourceInfo, paths, excludePaths []string, dst interface{}) error {

fields = append(fields, af...)
}
fields = append(fields, resourceInfo.custoFields...)
uniqueFields := removeDuplicates(fields)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm talking about removeDuplicates here. You are removing duplicates from something that is user-set and does not change over the lifetime of the plugin (that's at least my understanding). Instead of doing this every time you collect data you could remove the duplicates once in the plugin's Init function and save processing time by removing the function call here.

Comment thread plugins/inputs/vsphere/endpoint.go Outdated
Comment thread plugins/inputs/vsphere/endpoint.go Outdated
Comment on lines +1546 to +1556
func capitalizeAfterDot(input string) string {
var result []rune
for i, r := range input {
if i == 0 || input[i-1] == '.' {
result = append(result, unicode.ToUpper(r))
} else {
result = append(result, r)
}
}
return string(result)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please do the capitilization in getExtraData or do it in Init if the input is based on user settings.

Comment thread plugins/inputs/vsphere/README.md Outdated
Comment thread plugins/inputs/vsphere/README.md Outdated
Comment thread plugins/inputs/vsphere/endpoint.go Outdated
@telegraf-tiger

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/vsphere feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[inputs.vsphere] More informations about VMs

2 participants