svneswar
Enthusiast
Enthusiast

Unable to retrieve vm monitoring virtual machine settings by editing cluster settings .

Hi All,

I am currently using powershell version 2 and powercli 5.1 on vsphere client and vcenter version 5.0.0 and build 913577. I am facing a tricky issue while retreiving vm monitoring virtual machine settings by editing cluster settings.pls check the attached screenshot. I just deployed a new environment with 6 esxi hosts and created a single vm. Used the below code

#HighAvailability Settings - vSphere HA - VMMonitoring - Virtual machine settings
$count3 = 0
$ClusterObject1.ExtensionData.Configuration.DasVmConfig | %{
if ($_.DasSettings.VmToolsMonitoringSettings.ClusterSettings -eq "True"){$check3 = $count3}
else {$check3 = (++$count3)}
}

if ($check3 -eq 0)
    {
         write-host "Using Cluster Settings"
    }
    else
    {
        if ($check3 -gt 0)
        {
            write-host "NOT Using Cluster settings"

        }
    }

Just after creating the vm [having vmmonitoring  value "Use cluster settings" by default], by running the above script, got  "NOT Using Cluster settings" displayed on the console. [Not expected]

But by editing once, like changing the value from "Use cluster settings" to some other value like "high/medium/low/diabled/custom", got  "NOT Using Cluster settings" displayed on the console[expected].

Now onwards, I am getting the correct statement "Using/NOT Using Cluster settings" on the console as per settings.

Could you please let us know the reason for this behaviour and how to solve this issue.

0 Kudos
7 Replies
LucD
Leadership
Leadership

This is expected behavior for me.

If you haven't configured any VM individually yet,  then  the DasVmConfig property will b $null.

Once you configure at least 1 VM, the entries for the VMs are there.

So your script will have to take this into account.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

svneswar
Enthusiast
Enthusiast

Thanks LucD for your valuable inputs.

I would like to know, if there is a way to fetch VM monitoring details of each individual vm other than using DasVmConfig property. please suggest.

0 Kudos
LucD
Leadership
Leadership

Afaik, that is the only place where you can find the cluster VM monitoring information.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LucD
Leadership
Leadership

I had a go at this, and the way to find the monitoring settings per VM, is a bit more complex than I anticipated.

This seems to work for me

$clusterName = "MyCluster"
$cluster = Get-Cluster -Name $clusterName

$vmTab = @{}
$cluster.ExtensionData.ConfigurationEx.DasVmConfig | %{
   
$vmTab.Add($_.Key,$_.DasSettings.VmToolsMonitoringSettings)
}
Get-VM -Location $cluster |
Select @{N="Cluster";E={$cluster.Name}},
       
@{N="VM";E={$_.Name}},
       
@{N="VM Monitoring";E={
           
if($cluster.ExtensionData.ConfigurationEx.DasVmConfig){
               
if($vmTab.ContainsKey($_.ExtensionData.MoRef)){
                   
if($vmTab[$_.ExtensionData.MoRef].ClusterSettings){
                       
$cluster.ExtensionData.ConfigurationEx.DasConfig.VmMonitoring
                    }
                   
else{
                       
$vmTab[$_.ExtensionData.MoRef].VmMonitoring
                    }
                }
               
else{
                   
$cluster.ExtensionData.ConfigurationEx.DasConfig.VmMonitoring               
                }
            }
           
else{
               
$cluster.ExtensionData.ConfigurationEx.DasConfig.VmMonitoring
            }
        }}
       


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
svneswar
Enthusiast
Enthusiast

Thanks LucD. The script which you posted is showing vm monitoring status like "vm monitoring only".

Actually, I would like to check whether each Virtual machine is using cluster settings or not. In another way, I would like to know the value of

$Cluster.ExtensionData.Configuration.DasVmConfig | % { $_.DasSettings.VmToolsMonitoringSettings.ClusterSettings }

As told by you, If we haven't configured any VM individually yet,  then  the DasVmConfig property will be $null.

In our case , we are not going to configure any VM individually. once we create a VM using default settings through vcenter server, then under "edit cluster settings ->vm monitoring-> virtual machine settings" , each vm is showing  vm monitoring value as " Use Cluster settings".

I want to capture this data and any VM is having vm monitoring value other than " Use Cluster settings", then i woul like to show message as "Not using cluster settings on the console"

0 Kudos
LucD
Leadership
Leadership

You mean like this ?

$clusterName = "MyCluster"
$cluster = Get-Cluster -Name $clusterName

$vmTab = @{}
$cluster.ExtensionData.ConfigurationEx.DasVmConfig | %{
   
$vmTab.Add($_.Key,$_.DasSettings.VmToolsMonitoringSettings)
}
Get-VM -Location $cluster |
Select @{N="Cluster";E={$cluster.Name}},
       
@{N="VM";E={$_.Name}},
       
@{N="VM Uses Cluster Settings";E={
          
if($cluster.ExtensionData.ConfigurationEx.DasVmConfig){
               
if($vmTab.ContainsKey($_.ExtensionData.MoRef)){
                   
$vmTab[$_.ExtensionData.MoRef].ClusterSettings
                }
               
else{
                   
$true
                }
            }
           
else{
               
$true
            }
        }}
       

The script will indicate (True or False) if a VM uses the cluster setting or not.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
svneswar
Enthusiast
Enthusiast

Thanks a lot LucD

0 Kudos