DHCP Server 2012 Failover Server Relationship Health Data Source Module

Microsoft.Windows.DHCPServer.2012.FailoverServerWatcher.DS (DataSourceModuleType)

Knowledge Base article:

Summary

This data source module checks status for Fail over Server Relationships in Windows Server 2012 that got the DHCP feature enabled.

Configuration

Interval Seconds: How frequently (in seconds) the value should be checked.

Sync Time: Synchronization time for the module execution.

Timeout Seconds: How much time (in seconds) to wait for the module to finish execution.

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
Schedule DataSource System.SimpleScheduler Default
Probe ProbeAction Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval secondsHow frequently (in seconds) the value should be sampled.
SyncTimestring$Config/SyncTime$Sync TimeSynchronization time for the module execution.
TimeoutSecondsint$Config/TimeoutSeconds$Timeout SecondsExpecting time (in seconds) that the module wait to finish the execution.

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.DHCPServer.2012.FailoverServerWatcher.DS" Accessibility="Public" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ComputerName" type="xsd:string"/>
<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="SyncTime" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="Schedule" TypeID="System!System.SimpleScheduler">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime>$Config/SyncTime$</SyncTime>
</DataSource>
<ProbeAction ID="Probe" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>GetDHCPServer2012FailoverServerWatcher.ps1</ScriptName>
<ScriptBody><Script>

param ([String] $PrincipalName)
$SCRIPT_NAME = "DHCP2012FailoverServerWatcherProbe"
$ErrorActionPreference = "Stop"

# Event type constants
$EVENT_TYPE_LOG = 0
$EVENT_TYPE_ERROR = 1
$EVENT_TYPE_WARNING = 2
$EVENT_TYPE_INFORMATION = 4

# Typed property bag constants
$PROPERTY_TYPE_ALERT = 0
$PROPERTY_TYPE_EVENT = 1
$PROPERTY_TYPE_PERFORMANCE = 2
$PROPERTY_TYPE_STATE = 3

# State type constants
$STATE_SUCCESS = "Success"
$STATE_WARNING = "Warning"
$STATE_ERROR = "Error"

$momAPI = new-object -comObject MOM.ScriptAPI
Write-Host "$SCRIPT_NAME - Executing DHCP Failover 2012 Probe Powershell Script"

try
{
$DHCPFailoverWatchers = Get-DhcpServerv4Failover -ComputerName $PrincipalName

if ($DHCPFailoverWatchers -ne $null)
{

if($DHCPFailoverWatchers.Count -eq $null)
{
$FailoverCount = 1
}
else
{
$FailoverCount = $DHCPFailoverWatchers.Count
}

if ($FailoverCount -eq 0)
{
Write-Host "$SCRIPT_NAME - No DHCP Failover configured in this DHCP Server 2012"
exit
}
else
{
if ($FailoverCount -gt 0)
{
$ErrorNumber = 0
$ErrorDesc = ""

for ($itmFO=0; $itmFO -lt $FailoverCount; $itmFO++)
{
if($FailoverCount -eq 1)
{
$FailOvObj = $DHCPFailoverWatchers
}
else
{
$FailOvObj = $DHCPFailoverWatchers.Item($itmFO)
}

switch($FailOvObj.State)
{
"CommunicationInterrupted" {$CurrState = "0"}
"PartnerDown" {$CurrState = "0"}
"Normal" {$CurrState = "1"}
}

$PerformancePropertyBag = $momAPI.CreatePropertyBag()
$PerformancePropertyBag.AddValue("Name",$FailOvObj.Name)
$PerformancePropertyBag.AddValue("LocalServer",$PrincipalName)
$PerformancePropertyBag.AddValue("PartnerServer",$FailOvObj.PartnerServer)

if ($FailOvObj.ScopeId -ne $null)
{
if ($FailOvObj.ScopeId -is [System.Array])
{
$addressList = $FailOvObj.ScopeId -join ', '
}
else
{
$addressList = $FailOvObj.ScopeId.ToString()
}
}
$PerformancePropertyBag.AddValue("ScopeId",$addressList)

$PerformancePropertyBag.AddValue("State",$FailOvObj.State)
$PerformancePropertyBag.AddValue("StateID",$CurrState)
$PerformancePropertyBag.AddValue("ErrorNumber", $ErrorNumber)
$PerformancePropertyBag.AddValue("ErrorDescription", $ErrorDesc)

$PerformancePropertyBag

Write-Host "$SCRIPT_NAME - DHCP IPV4 Failover State Added to Property Bag"
}

}
}
}
}
catch [System.Exception]
{
$Description = $_.ToString()
$ErrNumber = $_.Exception.ErrorCode

Write-Warning "$SCRIPT_NAME - $Description"
$State = 0

$PerformancePropertyBag = $momAPI.CreatePropertyBag()
$PerformancePropertyBag.AddValue("Name","Any")
$PerformancePropertyBag.AddValue("LocalServer",$PrincipalName)
$PerformancePropertyBag.AddValue("PartnerServer","Any")
$PerformancePropertyBag.AddValue("ScopeId","Any")
$PerformancePropertyBag.AddValue("State","Error")
$PerformancePropertyBag.AddValue("StateID",$State)
$PerformancePropertyBag.AddValue("ErrorNumber", $ErrNumber)
$PerformancePropertyBag.AddValue("ErrorDescription", $Description)

$PerformancePropertyBag

}
finally
{
Write-Host "$SCRIPT_NAME - multiple performance property bag returned"
}</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>PrincipalName</Name>
<Value>$Config/ComputerName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Probe">
<Node ID="Schedule"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>