Most of my blog topics come from customer questions and use cases. This is one I lost sleep over.
The use case was to limit a disk usage rule from firing on a specific host. It got bigger when we dug in a bit, as the rule should be limited to only virtual machines that aren't part of a specific VM cluster.
The first thing to do is look at the rule. The Rule Definition tab shows what object the rule scope applies to. Data driven rules will generally have this, and it applies to everything of that type, by default.
In this case, the scope is "VMWVirtualMachineLogicalDisk" - so any virtual machine that populates data on 1 or more of its logical disks will be impacted by the rule. (I've added text from the "where" clause on.. we'll get to that in a later post.)
Clicking the green check mark will validate the scope, and return the impacted objects.
We see objects like "C:\ (32E7726B-8BDB-430A-A99A-1C03213E88BB/vm-117661)"
The first part is easy to decipher - that's the C: drive. But the rest of it is a bit cryptic.
In cases like this, I turn to the Data browser. I suspect it is some property of a host or VM, but this will confirm it. Drill into a host, select the Property Viewer dashboard, and take a look at the properties. Sure enough, there are values for hostId and vmId that match that cryptic string above. This is trial and error though - I'd have to click through each host until I find a matching one to my rule scope.
My colleague, Jesus Nunez, provided a script that takes an input (vmId) and returns the virtual machine name.
qrySvc = server.get("QueryService"); vmId = "32E7726B-8BDB-430A-A99A-1C03213E88BB/vm-117661" //<---change this value VirtualMachineQ= qrySvc.queryTopologyObjects("!VMWVirtualMachine where vmId ='" + vmId +"'") return VirtualMachineQ.get("name")
That can be run in the script console to return the VM name.
Once you have a script, you can modify it to return other values.. In this particular case, I needed the host name (not the VM name), so it just means changing a couple properties:
qrySvc = server.get("QueryService"); hostId = "32E7726B-8BDB-430A-A99A-1C03213E88BB/vm-117661" //<---change this value HostQ = qrySvc.queryTopologyObjects("!Host where hostId ='" + hostId +"'") return HostQ.get("name")
In a future post, we can dive into modifying the rule further to meet the customer use case.