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:
[powershell]
$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)
[/powershell]
Disable VM Monitoring on VM:
[powershell]
$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)
[/powershell]
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:
[powershell]
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.failureInterval = 120
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.minUpTime = 480
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailures = 3
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailureWindow = 604800
[/powershell]
Medium:
[powershell]
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.failureInterval = 60
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.minUpTime = 240
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailures = 3
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailureWindow = 86400
[/powershell]
High:
[powershell]
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.failureInterval = 30
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.minUpTime = 120
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailures = 3
$spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailureWindow = 3600
[/powershell]
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:
[powershell]
$spec.dasConfig.vmMonitoring = "vmAndAppMonitoring"
[/powershell]
Excluding App Monitoring on a VM (enabled on cluster):
[powershell]
$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
[/powershell]
Note: Excluding App Monitoring on a VM will default the VM monitoring to Medium. Adjust as necessary.
sylvain says
Hi Damian,
I just found your website, really interesting,thanks !
it looks like even 9 years later, vmware did not offer yet any powershell function to fully manage vm override setting, then your method accessing (.net method?) is still required.
by using developer mode in web browser, I can see the delete a vm from VM override call 5 functions.
if you still read this, can you help me to manage properly a deletion of a vm from VM override.
we’re migrating vm from one to another vCenter, and it looks like some of those settings are kept.
thank you for your feedback,
take care
Damian Karlson says
Hello! Unfortunately, I don’t know. My suggestion would be to check with VMware’s PowerCLI community. https://communities.vmware.com/community/vmtn/automationtools/powercli/content
Best of luck!
D
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.
Damian Karlson says
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.