alanrenouf / vCheck-vSphere

vCheck Daily Report for vSphere
MIT License
733 stars 325 forks source link

Add the option to store plugin variables in an external CSV file #728

Open monahancj opened 3 years ago

monahancj commented 3 years ago

The general code logic is if a CSV file exists in the plugin directory with the same name as the plugin then import the variables from the CSV file. The code snippet would go after any variable setting in the plugin.

  1. Variables in an external CSV file would take precedence over variables set in the plugin.ps1 file and not impact anyone's current environment. If a CSV file doesn't exist
  2. Upgrading becomes much easier. Variables set in a plugin's PS1 file are lost when a new version of a plugin is copied in. This method separates the data from the code.

I'll be submitting a PR linked to this issue shortly.

Code that will be added to the plugins:

# Update settings if there is a CSV file with a name matching the plugin ps1 file name.
if (Test-Path -Path (($MyInvocation).MyCommand.Source).Replace("ps1", "csv")) {
    Import-Csv (($MyInvocation).MyCommand.Source).Replace("ps1", "csv") | ForEach-Object { Set-Variable -Name $_.Name -Value $_.Value }
}

Using '10 HA Configuration Issues.ps1' as an example.

Add a CSV file in the same directory as the plugin with the same name as the plugin but with the CSV extension: 10 HA Configuration Issues.csv

Populate the CSV file:

Name,Value
ClustersDoNotInclude,"NameOfACluster|SomeOthercluster"
CLusterHAShouldBeEnabled,$true
ClusterHAHostMonitoringShouldBeEnabled,$true
ClusterHAAdmissionControlShouldBeEnabled,$true
monahancj commented 3 years ago

If this method is approved how should the PR be structured to update the other plugins? One PR per plugin or one PR for all the plugins?

lucdekens commented 3 years ago

That feature is included in the v7 I'm still writing

monahancj commented 3 years ago

Awesome.

Will v7 be released soon enough that it's not worth adding to the current version?

lucdekens commented 3 years ago

I don't have a fixed target date for now, I'm afraid. If you need it now, you could continue and we could make a new branch in the current release

Sneddo commented 3 years ago

This is possibly a good candidate for implementing in Get-vCheckSetting, although it will probably require some tweaks as we only pass the module title and setting name to the function

Luc- have you started on v7 at all? I've got a bit of time (and more importantly, working with vSphere again), so happy to help out a bit if you want?

lucdekens commented 3 years ago

Excuse me?