DCLocator Data Source

Microsoft.Windows.Server.2012.R2.AD.Availability.DCLocator.DataSource (DataSourceModuleType)

Data Source for the DC locator monitors.

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.CommandExecuterPropertyBagSource Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$TimeoutTime out in Sec
IntervalSecondsint$Config/IntervalSeconds$FrequencyHow often the monitor is run

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.Server.2012.R2.AD.Availability.DCLocator.DataSource" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.CommandExecuterPropertyBagSource">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<ApplicationName>cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/DCLocatorRunning.vbs$</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>DCLocatorRunning.vbs</Name>
<Contents><Script>'*****************************************************************
'* DCLocatorRunning.vbs
'*****************************************************************
Option Explicit

SetLocale("en-us")

'/* TypedPropertyBag */
Const StateDataType = 3

'/* Event Constants */
Const EVENT_TYPE_WARNING = 2

'/* Event ID Constants */
Const EVENTID_SCRIPT_ERROR = 1000

'*****************************************************************
'* PreapreScriptEnvironment
'* - MOMScriptAPI
'* - Create propertybag
'* - Get WMI result
'* - Output
'* - Satus
'* 0 : Success
'* 1 : MOMScriptAPI failed
'* 2 : PropertyBag creation failed
'* 3 : WMI failed
'* 4 : ADSystemInfo failed
'*****************************************************************
Function PrepareScriptEnvironment(ByRef oAPI, ByRef oBag, ByRef oWMI, ByRef oSysInfo)
Set oAPI = CreateObject("Mom.ScriptAPI")
If Err &lt;&gt; 0 Then
PrepareScriptEnvironment = 1
Exit Function
End If
Set oBag = oAPI.CreateTypedPropertyBag(StateDataType)
If Err &lt;&gt; 0 Then
PrepareScriptEnvironment = 2
Exit Function
End If
Set oWMI = GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
If Err &lt;&gt; 0 Then
PrepareScriptEnvironment = 3
Exit Function
End If
Set oSysInfo = CreateObject("ADSystemInfo")
If Err &lt;&gt; 0 Then
PrepareScriptEnvironment = 4
Exit Function
End If
End Function

Function GetDCLocatorState(ByRef oWMI, ByRef oSysInfo)
Dim oNetworkAdapter
Dim strDCName
Dim iResult
iResult = 1
strDCName = GetHostName(oSysInfo.GetAnyDCName())
For Each oNetworkAdapter In oWMI
If IsObject(oNetworkAdapter) And Len(oNetworkAdapter.DNSHostName) &gt; 0 Then '//kyekim: oNetworkAdpater.DNSHostName appears to be the DNS name of current box. In this case, we are assuming All DC's are DNS... =(
If LCase(strDCName) = LCase(oNetworkAdapter.DNSHostName) Then
iResult = 0
Exit For
End IF
End If
Next
GetDCLocatorState = iResult
End Function

Function GetHostName(ByVal strFQDN)
Dim iPtr
Dim strResult
strResult = strFQDN
iPtr = Instr(strFQDN, ".") - 1
If iPtr &gt; 0 Then
strResult = Left(strResult, iPtr)
End If
GetHostName = strResult
End Function

Function FilloutPropertyBag(ByRef oBag, ByVal state)
Dim iResult
If state = 0 Then
oBag.AddValue "Status", "GOOD"
Else
oBag.AddValue "Status", "BAD"
End If
FilloutPropertyBag = 0
End Function

'******************************************************************************
' Name: CreateEvent
'
' Purpose: Creates a MOM event
'
' Parameters: lngEventID, the ID for the event
' lngEventType, the severity for the event. See constants at head of file
' strMessage, the message for the event
'
' Return: nothing
'******************************************************************************
Sub CreateEvent(ByRef oAPI, lngEventID, lngEventType, iStatus)
On Error Resume Next
Dim strMessage
Select Case iStatus
Case 1 strMessage = "Cannot create MOM Script API"
Case 2 strMessage = "Cannot create PropertyBag"
Case 3 strMessage = "WMI error"
Case 4 strMessage = "Cannot create ADSystemInfo"
End Select
oAPI.LogScriptEvent "DCLocatorRunning.vbs",lngEventID, lngEventType, strMessage
End Sub

Sub Main()
Dim oAPI
Dim oWMI
Dim oBag
Dim oSysInfo
Dim iResult

iResult = PrepareScriptEnvironment(oAPI, oBag, oWMI, oSysInfo)
If iResult &lt;&gt; 0 Then
CreateEvent oAPI, EVENTID_SCRIPT_ERROR, EVENT_TYPE_WARNING, iResult
Exit Sub
End If

iResult = GetDCLocatorState(oWMI, oSysInfo)
FilloutPropertyBag oBag, iResult
oAPI.Return oBag
End Sub

Call Main()
</Script></Contents>
<Unicode>1</Unicode>
</File>
</Files>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>