VMware - trigger alert when a VM moves to a particular datastore?
Solution 1:
A good solution for this would be to use VMware's Storage Policy-Based Management with tags. There may be vendor specific capabilities that you could also take advantage of but as tags are vendor agnostic I'll use those to explain how policies can be leveraged.
A minimal approach would be:
- Create a tag category (storage-performance) with two tags (performance, non-performance).
- Tag each datastores with one of the tags depending on the "type" of storage
- Create two storage policies (performance, non-performance) and use a tag based rule for the policy. For example the performance policy is compatible with datastores with the performance tag. When creating the policy you will be able to see which datastores are compatible with the policy
- Associate the desired storage policy with the virtual machines
What this will do is ensure that the users will be warned if they try to migrate a VM to datastore that will not support the VM's policy. If the user ignores this warning then the VM will be marked as out of compliance.
Solution 2:
In looking at the possible triggers for a Datastore alarm, a few possibilities exist.
For conditionals, you could use:
- Datastore Disk Usage (%)
- Datastore Disk Provisioned (%)
While for events these might work:
- File or directory copied to datastore
- File or directory moved to datastore
The former two would require you to have known numbers, just above which you'd set the threshold.
The latter two might not even work depending on whether or not an svMotion counts as files being copied/moved to the datastore.
Solution 3:
I went where EEAA was heading and just ended up with a simple PowerCLI provided from here.
and set the "-ge" equal to 1 since the datastore in question should only house the one VM it is intended for.
I have that set to run on our administrative server twice a day.
It doesn't really answer the question itself of when a VM moves to a particular non-SDRS datastore, but it is a workaround that gets me close enough to knowing. Plus it only emails me when the potential that it has happened occurs. And if the admins mess up and then move the VM back before the script runs that's ok.
Code here for posterity:
#
# PowerCLI script to send e-mail if the number of virtual machines per datastore exceeds 48
# Version 1.0
# Magnus Andersson, Real Time Services AB
#
#
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
#
#
# Get login password
$pwd = Get-Content d:vspherescriptspowerclicred | ConvertTo-SecureString
$cred = New-Object System.Management.Automation.PsCredential “homedomainpowercli“, $pwd
#
#
# Connect to vCenter Server
connect-viserver vc-demo01.home.test
#
#
$sendTo = “[email protected]“
$ds = get-datastore
foreach ($datastore in $ds){
$num = Get-Datastore $datastore | Select @{N=”TotalVMs”;E={@($_ | Get-VM ).Count}}
if ($num.TotalVMs -ge 48) {
send-mailmessage -to $sendTo -from [email protected] -Subject “Number of VMs per datastore $datastore is” -smtpserver smtp.home.test -body $num.TotalVms
}
else
{
}
}
#