Managing VMware HA’s VM Monitoring: PowerCLI

In a previous post, I discussed my need to manage HA isolation response and restart priority settings on a per-VM level (separate from the cluster settings). This post is a continuation of that topic, but covers how to manage the VM Monitoring aspect of VMware HA with PowerCLI.

At the time of writing, there are no publicly available PowerCLI cmdlets that offers the ability to manage VM Monitoring at the cluster and VM levels, so in order to accomplish this task, we need to dive a bit deeper into the world of the vSphere API.

Personally, I’ve always found the vSphere API to be a bit confusing. I’ve had difficulty referencing the API and producing the types of objects, keys, and values that are necessary to make a change. I decided to use VMware’s Onyx tool to assist in gathering the necessary code.

According to Onyx, every time a change is made in the GUI that involves an HA or monitoring setting (at the cluster or VM levels), all of the existing settings are reapplied. I’ve decided not to follow this process, for 2 reasons: First, it would add a good amount of code overhead to retrieve & reapply the existing cluster/VM settings. Second, there’s no need to do so. In the code below, you’ll see that the changes are applied using a method named ReconfigureComputeResource_Task. If you visit the method’s description in the API, you’ll see that the boolean parameter passed to the method indicates whether or not the changes are applied incrementally. If $true, then only the specified changes are made. If $false, then all other settings will return to their unset or default settings when the new changes are applied.

I’ve got 2 snippets below. The first one will set VM Monitoring at the cluster level. The second will disable VM Monitoring at the VM level.

Enable VM Monitoring (medium) on cluster:

$spec = New-Object VMware.Vim.ClusterConfigSpecEx
$spec.dasConfig = New-Object VMware.Vim.ClusterDasConfigInfo
$spec.dasConfig.vmMonitoring = "vmMonitoringOnly"
$spec.dasConfig.defaultVmSettings = New-Object VMware.Vim.ClusterDasVmSettings
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings = New-Object VMware.Vim.ClusterVmToolsMonitoringSettings
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.enabled = $true
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.vmMonitoring = "vmMonitoringOnly"
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.failureInterval = 60
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.minUpTime = 240
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailures = 3
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailureWindow = 86400

$cluster = Get-Cluster -Name "Cluster"
$_this = Get-View -Id $cluster.Id
$_this.ReconfigureComputeResource_Task($spec, $true)

Disable VM Monitoring on VM:

$vm = Get-VM -Name "Name"

$spec = New-Object VMware.Vim.ClusterConfigSpecEx
$spec.dasVmConfigSpec = New-Object VMware.Vim.ClusterDasVmConfigSpec[] (1)
$spec.dasVmConfigSpec[0] = New-Object VMware.Vim.ClusterDasVmConfigSpec
$spec.dasVmConfigSpec[0].operation = "edit"
$spec.dasVmConfigSpec[0].info = New-Object VMware.Vim.ClusterDasVmConfigInfo
$spec.dasVmConfigSpec[0].info.key = New-Object VMware.Vim.ManagedObjectReference
$spec.dasVmConfigSpec[0].info.key.type = "VirtualMachine"
$spec.dasVmConfigSpec[0].info.key.value = $vm.ExtensionData.MoRef.Value
$spec.dasVmConfigSpec[0].info.dasSettings = New-Object VMware.Vim.ClusterDasVmSettings
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings = New-Object VMware.Vim.ClusterVmToolsMonitoringSettings
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings.enabled = $false
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings.vmMonitoring = "vmMonitoringDisabled"
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings.clusterSettings = $false

$_this = Get-View -Id $vm.VMHost.Parent.Id
$_this.ReconfigureComputeResource_Task($spec, $true)

If you’re interested in setting the cluster-level VM monitoring at different levels (low, medium, high, custom), here are the settings you’ll need.

Low:

$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.failureInterval = 120
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.minUpTime = 480
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailures = 3
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailureWindow = 604800

Medium:

$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.failureInterval = 60
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.minUpTime = 240
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailures = 3
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailureWindow = 86400

High:

$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.failureInterval = 30
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.minUpTime = 120
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailures = 3
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailureWindow = 3600

Custom: Uses the same keys as above, just with different values for failureInterval, minUpTime, maxFailures, and maxFailureWindow. maxFailureWindow is in seconds, or -1 to disable it.

VM and App Monitoring on cluster:

$spec.dasConfig.vmMonitoring = "vmAndAppMonitoring"

Excluding App Monitoring on a VM (enabled on cluster):

$vm = Get-VM -Name "Name"

$spec = New-Object VMware.Vim.ClusterConfigSpecEx
$spec.dasVmConfigSpec = New-Object VMware.Vim.ClusterDasVmConfigSpec[] (1)
$spec.dasVmConfigSpec[0] = New-Object VMware.Vim.ClusterDasVmConfigSpec
$spec.dasVmConfigSpec[0].operation = "add"
$spec.dasVmConfigSpec[0].info = New-Object VMware.Vim.ClusterDasVmConfigInfo
$spec.dasVmConfigSpec[0].info.key = New-Object VMware.Vim.ManagedObjectReference
$spec.dasVmConfigSpec[0].info.key.type = "VirtualMachine"
$spec.dasVmConfigSpec[0].info.key.value = $vm.ExtensionData.MoRef.Value
$spec.dasVmConfigSpec[0].info.dasSettings = New-Object VMware.Vim.ClusterDasVmSettings
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings = New-Object VMware.Vim.ClusterVmToolsMonitoringSettings
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings.enabled = $true
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings.vmMonitoring = "vmMonitoringOnly"
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings.clusterSettings = $false
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings.failureInterval = 60
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings.minUpTime = 240
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings.maxFailures = 3
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings.maxFailureWindow = 86400

Note: Excluding App Monitoring on a VM will default the VM monitoring to Medium. Adjust as necessary.

Comments

  1. vSphere User says:

    hi Damian, I am in need of a script to disable VM Monitoring for all VMs in a cluster and to selectively turn on for couple of VMs. I have tried your “Disable VM Monitoring on VM:” but it works only for one VM. If I try with a different name for another VM I am getting , “A specified parameter was not correct” error. Strange but couldn’t figure out why. It is working only for the VM I tried first. Also I am a novice and need help in modifying the script to be able to run against all VMs in a cluster/folder. Thank you for your help in advance.

    • Hi, thanks for commenting! My apologies, I’ve been slow in responding. You’re correct, that script only works once in its current form. When you said that you’re having issues with using another VM name, you’re replacing the name in quotes with the display name of the VM in vCenter, correct?

      There’s a number of different ways to run the script on more than one VM. If you want it based on a VM folder, cluster, or virtual datacenter, then use:
      “Get-VM -Location ‘Location'” — that will return all VMs in a particular vicontainer. You could do something like this:

      “$vms = Get-VM -Location ‘Dev’
      foreach ($vm in $vms) {
      //use the code in the article above, minus the Get-VM part
      }”

      Probably the best suggestion I can make, though, is to take some time to understand some of the PowerShell concepts such as pipelining & logic flow like looping, conditional statements, etc. Also, be sure to check out the PowerCLI forum on the VMware Communities and the PowerCLI cmdlet documentation for 5.0.

    • Well done to think of soeinhmtg like that

    • Chuck Norris’s parents used to come into his room and ask to sleep in his bed. These requests were usually followed by a swift roundhouse kick to the face, or a tender kiss on the forehead.

Trackbacks

  1. […] This post was mentioned on Twitter by afokkema. afokkema said: RT @sixfootdad: [New Blog Post] Managing VMware HA’s VM Monitoring: PowerCLI http://bit.ly/exoWBq […]

  2. […] « File upload failed: VMware Update Manager Managing VMware HA’s VM Monitoring: PowerCLI […]

Speak Your Mind

*