Microsoft.Windows.HyperV.2012.R2.VMReplicationHealthMonitorType (UnitMonitorType)

Element properties:

RunAsDefault
AccessibilityPublic
Support Monitor RecalculateFalse

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.HyperV.PowershellDataSourceType Default
CDOnCritical ConditionDetection System.ExpressionFilter Default
CDOnhealthy ConditionDetection System.ExpressionFilter Default

Overrideable Parameters:

IDParameterTypeSelector
IntervalSecondsint$Config/IntervalSeconds$
TimeoutSecondsint$Config/TimeoutSeconds$

Source Code:

<UnitMonitorType ID="Microsoft.Windows.HyperV.2012.R2.VMReplicationHealthMonitorType" Accessibility="Public">
<MonitorTypeStates>
<MonitorTypeState ID="VMReplicationHealthy" NoDetection="false"/>
<MonitorTypeState ID="VMReplicationCritical" NoDetection="false"/>
</MonitorTypeStates>
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="VMId" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ErrorProperty" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ErrorCode" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<MonitorImplementation>
<MemberModules>
<DataSource ID="DS" TypeID="Microsoft.Windows.HyperV.PowershellDataSourceType">
<Parameters/>
<ScriptBody><Script>
function ImportCimXml([Xml] $inputXml)
#++
# Converts a CIM-XML representation of a WMI object to a custom
# PowerShell object. This only supports scalar and string properies. Array and
# reference properties are ignored, as are qualifiers.
#--
{
$CimXml = [Xml]$inputXml
if ($CimXml -eq $null)
{
ReportError("Input XML is not specified")
return $null
}

$CimObj = New-Object -TypeName PSObject

foreach ($CimProperty in $CimXml.SelectNodes("/INSTANCE/PROPERTY"))
{
$CimObj | Add-Member -MemberType NoteProperty `
-Name $CimProperty.NAME `
-Value $CimProperty.VALUE
}

return $CimObj
}

$oAPI = New-Object -comObject 'MOM.ScriptAPI'
$pBag = $oAPI.CreatePropertyBag()

$evdId = 1000
$evtSource = "Microsoft.Windows.HyperV.2012.VMReplicationHealthMonitor";
$infoevent = 0;
$errevent = 2;


$error.Clear();

$vmList = gwmi Msvm_ComputerSystem -namespace "root\virtualization\v2"
if ($vmList -ne $null)
{
$replicaService = gwmi Msvm_ReplicationService -namespace "root\virtualization\v2"
if ($replicaService -ne $null)
{
$eventMessage = ""
$healthIssuesFound = $false
$hostHealthIssuesFound = $false
$hostHealthIssuesList = ""

#add one entry for host as well, since 33418 is a host level issue
if ($vmList -ne $null)
{
if ($vmList.Count -ne $null -and $vmList.Count -gt 1)
{
$pBag.AddValue("localhost-ReplicationHealth", $vmList[1].ReplicationHealth);
$pBag.AddValue("localhost-ReplicationState", $vmList[1].ReplicationState.ToString());
$eventMessage += "`nlocalhost-ReplicationHealth :" + $vmList[1].ReplicationHealth
$eventMessage += "`nlocalhost-ReplicationState :" + $vmList[1].ReplicationState.ToString()
}
else
{
# No VMs exist to get Replication Health
$pBag.AddValue("localhost-ReplicationHealth", 0);
$pBag.AddValue("localhost-ReplicationState", "0");
$eventMessage += "`nlocalhost-ReplicationHealth : 0"
$eventMessage += "`nlocalhost-ReplicationState : 0"
}
}
foreach ($vm in $vmList)
{
$pBag.AddValue($vm.Name +"-ReplicationHealth", $vm.ReplicationHealth);
$pBag.AddValue($vm.Name +"-ReplicationState", $vm.ReplicationState.ToString());
$eventMessage += "`n" + $vm.Name +"-ReplicationHealth :" + $vm.ReplicationHealth
$eventMessage += "`n" + $vm.Name +"-ReplicationState :" + $vm.ReplicationState
# replicationhealth 0 means Not Applicable
if ($vm.ReplicationHealth -gt 0)
{
$rsHealthIssueList = ""
$rss = $replicaService.GetReplicationStatistics($vm.__PATH);
if ($rss.ReplicationHealthIssues -ne $null)
{
foreach($errorObj in $rss.ReplicationHealthIssues)
{
$msg = ImportCimXml($errorObj)
if ($msg -ne $null)
{
$rsHealthIssueList += $msg.MessageID + ","
$healthIssuesFound = $true
}
}
$pBag.AddValue($vm.Name +"-ReplicationHealthIssuesList", $rsHealthIssueList);
$eventMessage += "`n" + $vm.Name +"-ReplicationHealthIssuesList :" + $rsHealthIssueList
if ($hostHealthIssuesFound -eq $false)
{
$hostHealthIssuesFound = $true
$hostHealthIssuesList = $rsHealthIssueList
}
}
}
#Add a blank property entry for the VM if no issues found
if ($healthIssuesFound -eq $false)
{
$pBag.AddValue($vm.Name +"-ReplicationHealthIssuesList", "0");
$eventMessage += "`n" + $vm.Name +"-ReplicationHealthIssuesList : 0"
}
}

$pBag.AddValue("localhost-ReplicationHealthIssuesList", $hostHealthIssuesList);
$eventMessage += "`nlocalhost-ReplicationHealthIssuesList :" + $hostHealthIssuesList

$oAPI.LogScriptEvent($evtSource, $evdId, $infoevent, $eventMessage);
}
}
else
{
$oAPI.LogScriptEvent($evtSource, $evdId, $infoevent, "Msvm_ComputerSystem enumeration failed "+ $error);
}


$pBag

</Script></ScriptBody>
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
<!--
ReplicationHealth
N/A (0) Not applicable.
Ok (1) Replication is working fine
Warning (2) Replication is happening but not optimal
Error (3) Replication is in error
-->
<ConditionDetection ID="CDOnhealthy" TypeID="System!System.ExpressionFilter">
<Expression>
<Or>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Integer">Property[@Name='$Config/VMId$-ReplicationHealth']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Integer">0</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Integer">Property[@Name='$Config/VMId$-ReplicationHealth']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Integer">1</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</Or>
</Expression>
</ConditionDetection>
<!--
ReplicationHealthIssues
33400 Resync suspended
33402 Replication critical, check event viewer for more details
33404 Replication suspended
33406 Replication enabled but initial replication is not started
33408 Initial replication is not complete
33410 Primary needs resync, need to initiate resync
33412 Recovery failed over. Start reverse replication.
33414 Last Replication was before 1 hour
33416 Missed more than 20% of replication cycles
33418 Replication broker is not configured in cluster
33420 Vm is not in cluster
33422 Resync required
33424 VM configuration is corrupt
-->
<ConditionDetection ID="CDOnCritical" TypeID="System!System.ExpressionFilter">
<Expression>
<RegExExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='$Config/VMId$-$Config/ErrorProperty$']</XPathQuery>
</ValueExpression>
<Operator>ContainsSubstring</Operator>
<Pattern>$Config/ErrorCode$</Pattern>
</RegExExpression>
</Expression>
</ConditionDetection>
</MemberModules>
<RegularDetections>
<RegularDetection MonitorTypeStateID="VMReplicationHealthy">
<Node ID="CDOnhealthy">
<Node ID="DS"/>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="VMReplicationCritical">
<Node ID="CDOnCritical">
<Node ID="DS"/>
</Node>
</RegularDetection>
</RegularDetections>
</MonitorImplementation>
</UnitMonitorType>