VMware Cloud Community
aamodei01
Enthusiast
Enthusiast

Get VM's protection status

Has anyone been successful in getting the specific fault/error message from a VM under a protection group?

I'm trying to get the message shown in the UI via the API.

For Example,

I have a VM sitting on ABR storage - this is fine.

It's not yet protected and it's assigned to a network that is NOT mapped in SRM (This is by design as a test)

When I run the protectVM task via the API, it runs, but when I retrieve the error via the GetResult() method on the task, it simply says:

fault             localizedMessage                                           

-----             ----------------                                           

SRM01.MethodFault Unable to protect VM '<MY VM>' due to unresolved devices

I want the message that appears in the UI, which currently shows:

Mapping missing: Network 'THE MISSING NETWORK PortGroup NAME'

Does anyone know how I can get this information instead of the generic "unresolved devices"

Is it from the VM protection perspective or something on the protection group?

Thanks to all in advance!

Tags (2)
Reply
0 Kudos
1 Reply
aamodei01
Enthusiast
Enthusiast

Ok, so I kept plodding along and I was able to get a solution, while not elegant, it does do the trick:

I'm using powershell for the main app I'm building, so this code is all powershell, running directly on the Protected Site SRM server. This is just the basic building block, I haven't worked out the loops to handle any VM's that are in a state that would require it.

The below code will pull out the reason (being network mapping missing) and what network mapping is missing

#Get Latest SRM DR Log

$srm_log = gci "C:\ProgramData\VMware\VMware vCenter Site Recovery Manager\Logs" | where {$_.Name -like "vmware-dr*.log"} | gc

#Pattern for Missing Device - Target VM being checked

$pattern = "dr.replication.VmProtectionGroup.VmMirrorOptionResult(.*?)--> ]"

$t = [regex]::Matches($srm_log,$pattern)

#Parse log and convert data

$unresolved_device = ((((($t | where{$_.value -match "<VM NAME>"} | Select -Last 1).value -replace "\[ -->","") -split "-->") -replace '"',"") -replace ",","") -replace " ","" | ConvertFrom-String -Delimiter "="

#Create hash of Unresolved Objects - NON-DISK

$unresolved_device_hash = @()

$unresolved_device_hash += New-Object PSObject -Property @{

        VMName = ($unresolved_device | where {$_.P1 -eq "vmname"}).p2

        UnresolvedDeviceReason = (((($unresolved_device | where {$_.P1 -eq "faults"}).p2) -split "\.") | Select -Last 1) -replace "\){",""

        UnresolvedObjects = ($unresolved_device | where {$_.P1 -eq "networkname"}).p2 -join "/ "

    }

The below code is to gather all VM disks that are not on replicated storage, hence flagging the VM is not fully replicated

#Get Latest SRM DR Log

$srm_log = gci "C:\ProgramData\VMware\VMware vCenter Site Recovery Manager\Logs" | where {$_.Name -like "vmware-dr*.log"} | gc

#Pattern for Missing Disk - Target VM being checked

$pattern = "dr.replication.fault.DevicesNotResolved(.*?)\[context]"

$t = [regex]::Matches($srm_log,$pattern)

#Parse log and convert data

$unresolved_device = ((((($t | where{$_.value -match "<VM NAME>"} | Select -Last 1).value -replace "\[ -->","") -split "-->") -replace '"',"") -replace ",","") -replace " ","" | ConvertFrom-String -Delimiter "="

#Create hash of Unresolved Objects - DISK

$unresolved_device_hash = @()

$unresolved_device_hash += New-Object PSObject -Property @{

        VMName = ($unresolved_device | where {$_.P1 -eq "vmname"}).p2

        UnresolvedDeviceReason = (((($unresolved_device | where {$_.P1 -eq "unresolvedDevice"}).p2) -split "\.") | Select -Last 1) -replace "\){",""

        UnresolvedObjects = ($unresolved_device | where {$_.P1 -eq "label"}).p2 -join "/ "

    }

Hope this helps someone else out in a similar situation.

Reply
0 Kudos