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

Create plugin to list Virtual Machines in order to test include/exclude options #851

Closed
atc0005 opened this issue Jul 26, 2023 · 1 comment · Fixed by #858
Closed

Create plugin to list Virtual Machines in order to test include/exclude options #851

atc0005 opened this issue Jul 26, 2023 · 1 comment · Fixed by #858
Assignees
Milestone

Comments

@atc0005
Copy link
Owner

atc0005 commented Jul 26, 2023

Overview

Provide a plugin to list Virtual Machines n order to test include/exclude options.

This plugin would provide a way to test the include/exclude options supported by other plugins:

  • include/exclude based on Virtual Machine name
  • include/exclude based on Resource Pool name
  • include/exclude based on power state
  • and so on

The idea is that this could be useful for sysadmins, but also to anyone developing a plugin or extending features for existing plugins (e.g., #588, #595).

A later version of the plugin might provide a flag to accept a list of Virtual Machine names as an assertion check: error if the results from applying include/exclude filters do not exactly match the given list.

References

@atc0005
Copy link
Owner Author

atc0005 commented Jul 27, 2023

Also related:

What does "filtered by" mean?

If we look solely at this line:

Str("vms_filtered_by_power_state", strings.Join(vsphere.VMNames(filteredVMs), ", ")).

it isn't so clear to me, but if we add in the other lines for that function call it becomes clearer:

log.Debug().
Str("vms_filtered_by_power_state", strings.Join(vsphere.VMNames(filteredVMs), ", ")).
Int("vms_excluded_by_power_state", numVMsExcludedByPowerState).
Msg("VMs after power state filtering")

VMs filtered by X is the VMs remaining after X filtering is applied to drop those which don't meet the criteria.

This becomes even clearer when you take in the surrounding logic:

log.Debug().
Str("vms_evaluated", strings.Join(vsphere.VMNames(vms), ", ")).
Msg("Evaluated Virtual Machines")
log.Debug().Msg("Drop any VMs we've been asked to exclude from checks")
filteredVMs, numVMsExcludedByName := vsphere.ExcludeVMsByName(vms, cfg.IgnoredVMs)
log.Debug().
Str("vms_filtered_by_name", strings.Join(vsphere.VMNames(filteredVMs), ", ")).
Int("vms_excluded_by_name", numVMsExcludedByName).
Msg("VMs after name filtering")
log.Debug().Msg("Filter VMs to specified power state")
filteredVMs, numVMsExcludedByPowerState := vsphere.FilterVMsByPowerState(filteredVMs, cfg.PoweredOff)
log.Debug().
Str("vms_filtered_by_power_state", strings.Join(vsphere.VMNames(filteredVMs), ", ")).
Int("vms_excluded_by_power_state", numVMsExcludedByPowerState).
Msg("VMs after power state filtering")

The vms_evaluated line is clearly meant (at least from reading my own writing) to indicate what we have to work with "at the beginning". The value for this line is the vms collection.

That said, the vsphere.VMPowerCycleUptimeReport function has these parameters:

allVMs []mo.VirtualMachine,
evaluatedVMs []mo.VirtualMachine,

but we give it these arguments:

vms,
filteredVMs,

  • vms in main.go map to allVMs in vms.go
  • filteredVMs in main.go map to evaluatedVMs in vms.go

I find other examples like this sprinkled about.

I expect that within a single plugin I was probably consistent (variable scope helps with this), but since shared logic spans multiple files and functions the meaning behind the terms was mixed up.

At some point I'll need to carve out the time to build a brief terms list and enforce the consistent use of those terms across the project.

In particular, the mixing of "all" VMs and "filtered" VMs (see /cmd/check_vmware_vm_power_uptime/main.go and /internal/vsphere/vms.go) are problematic.

atc0005 added a commit that referenced this issue Jul 27, 2023
This plugin provides a way to test the include/exclude options
supported by other plugins (e.g., Virtual Machine or Resource Pool
name, power state).

The plan is to update this plugin whenever new filtering logic
is added to project plugins.

Doc updates have been applied, example usage has been added,
including a command definition "contrib" file illustrating how
the plugin would be referenced within a production Nagios
configuration.

refs GH-851
@atc0005 atc0005 modified the milestones: Future, v0.34.0 Jul 27, 2023
atc0005 added a commit that referenced this issue Jul 28, 2023
This plugin provides a way to test the include/exclude options
supported by other plugins (e.g., Virtual Machine or Resource Pool
name, power state).

The plan is to update this plugin whenever new filtering logic
is added to project plugins.

Doc updates have been applied, example usage has been added,
including a command definition "contrib" file illustrating how
the plugin would be referenced within a production Nagios
configuration.

refs GH-851
atc0005 added a commit that referenced this issue Jul 28, 2023
This plugin provides a way to test the include/exclude options
supported by other plugins (e.g., Virtual Machine or Resource Pool
name, power state).

The plan is to update this plugin whenever new filtering logic
is added to project plugins.

Doc updates have been applied, example usage has been added,
including a command definition "contrib" file illustrating how
the plugin would be referenced within a production Nagios
configuration.

refs GH-851
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant