Módulo de origen de datos de estado de relaciones de servidores de conmutación por error DHCP Server 2012

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

Knowledge Base article:

Resumen

Este módulo de origen de datos comprueba el estado de las relaciones de servidores de conmutación por error en Windows Server 2012 que tenían habilitada la característica DHCP.

Configuración

Segundos de intervalo: frecuencia (en segundos) con la que se debe comprobar el valor.

Tiempo de sincronización: tiempo de sincronización para la ejecución del módulo.

Segundos de tiempo de espera: cuánto tiempo (en segundos) se debe esperar a que el módulo finalice la ejecución.

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$Segundos de intervaloFrecuencia (en segundos) con la que se debe muestrear el valor.
SyncTimestring$Config/SyncTime$Hora de sincronizaciónTiempo de sincronización para la ejecución del módulo.
TimeoutSecondsint$Config/TimeoutSeconds$Tiempo de espera en segundosTiempo de espera (en segundos) que aguarda el módulo a que finalice la ejecución.

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 -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>