Fonte de Dados do Script AD Client Connectivity

AD_Client_Connectivity.DataSource (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.CommandExecuterPropertyBagSource Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Intervalo em Segundos
LogSuccessEventstring$Config/LogSuccessEvent$Evento de Log Bem-sucedido
BindThresholdstring$Config/BindThreshold$Limite de Ligações
PingThresholdstring$Config/PingThreshold$Limite de Ping
FailureThresholdstring$Config/FailureThreshold$Limite de Falhas
SearchThresholdstring$Config/SearchThreshold$Limite de Pesquisas
TimeoutSecondsint$Config/TimeoutSeconds$Tempo limite (segundos)
VerboseLoggingstring$Config/VerboseLogging$

Source Code:

<DataSourceModuleType ID="AD_Client_Connectivity.DataSource" Accessibility="Internal">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:int"/>
<xsd:element name="TargetComputerName" type="xsd:string"/>
<xsd:element name="LogSuccessEvent" type="xsd:boolean"/>
<xsd:element name="BindThreshold" type="xsd:string"/>
<xsd:element name="SearchThreshold" type="xsd:string"/>
<xsd:element name="FailureThreshold" type="xsd:string"/>
<xsd:element name="PingThreshold" type="xsd:string"/>
<xsd:element name="ManagementGroupName" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:int"/>
<xsd:element name="VerboseLogging" type="xsd:boolean"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" ParameterType="int" Selector="$Config/IntervalSeconds$"/>
<OverrideableParameter ID="LogSuccessEvent" ParameterType="string" Selector="$Config/LogSuccessEvent$"/>
<OverrideableParameter ID="BindThreshold" ParameterType="string" Selector="$Config/BindThreshold$"/>
<OverrideableParameter ID="PingThreshold" ParameterType="string" Selector="$Config/PingThreshold$"/>
<OverrideableParameter ID="FailureThreshold" ParameterType="string" Selector="$Config/FailureThreshold$"/>
<OverrideableParameter ID="SearchThreshold" ParameterType="string" Selector="$Config/SearchThreshold$"/>
<OverrideableParameter ID="TimeoutSeconds" ParameterType="int" Selector="$Config/TimeoutSeconds$"/>
<OverrideableParameter ID="VerboseLogging" ParameterType="string" Selector="$Config/VerboseLogging$"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.CommandExecuterPropertyBagSource">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/AD_Client_Connectivity.vbs$ $Config/TargetComputerName$ $Config/LogSuccessEvent$ $Config/BindThreshold$ $Config/SearchThreshold$ $Config/FailureThreshold$ $Config/PingThreshold$ $Config/ManagementGroupName$ $Config/VerboseLogging$</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>AD_Client_Connectivity.vbs</Name>
<Contents><Script>
'*************************************************************************
' Script Name - AD Client Connectivity
'
' Purpose - Determines if the DCs being tested are in sync time-wise
'
' Assumptions - Script is run by a timed event
'
' Parameters - BindThreshold - The number of milliseconds a bind is allowed
' to take.
' - SearchThreshold - The number of milliseconds that a search
' is allowed to take.
' - FailureThreshold - The number of consecutive failures allowed
' before an alert is raised.
' - LogSuccessEvent - Logs an event when the script completes.
' - VerboseLogging - Turns on extra logging to help debug any
' issues with this script. Debug data is
' logged in 1004 events in the OPS MGR log.
'
' (c) Copyright 2002, Microsoft Corporation, All Rights Reserved
' Proprietary and confidential to Microsoft Corporation
'*************************************************************************

Option Explicit

' Event Constants
Const EVENT_TYPE_SUCCESS = 0
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4

' Standard Event IDs
Const EVENT_ID_SUCCESS = 5000
Const EVENT_ID_SCRIPT_FAILURE = 5001
Const EVENT_ID_INVALID_PARAMETER = 5003
Const EVENT_ID_TEST_FAILED = 1001
Const EVENT_ID_ALERT_TEST_FAILED = 1002
Const EVENT_ID_TEST_SUCCEEDED = 1003
Const EVENT_ID_AGENTLESS = 98
Const EVENT_ID_SUCCEEDED = 999
Const EVENT_ID_VERBOSE_LOGGING = 1004

' Error Codes
Const ERR_PING_FAILED = 1
Const ERR_BIND_FAILED = 2
Const ERR_PARAM_NOT_FOUND = 3
Const ERR_GET_NEXT_COMPUTER_ERROR = 4
Const ERR_NETUSE_FAILED = 5
Const ERR_SEARCH_TIMEOUT = 6
Const ERR_LDAP_PING_FAILED = 7
Const ERR_SEARCH_FAILED = 8

' Script Specific Constants
Const SCRIPT_NAME = "AD Client Connectivity"
Const MAX_REPEAT_COUNT = 2


' Parameter validation Constants
Const GTE = 1
Const LTE = 2
Const BAND = 3

' Test Names
Const PING_TEST = 1001
Const NETUSE_TEST = 1002
Const ADSIBIND_TEST = 1003
Const LDAP_PING_TEST = 1004

' Test Parameter Names
Const BIND_THRESHOLD = "BindThreshold"
Const SEARCH_THRESHOLD = "SearchThreshold"
Const FAIL_LIMIT = "FailureThreshold"
Const LOG_SUCCESS = "LogSuccessEvent"
Const LDAP_PING_TIMEOUT = "LDAPPingTimeout"

' TypedPropertyBag
const PerformanceDataType = 2
const StateDataType = 3

Dim oADOConn, oOOMADS, lErr, strErr, lFailLimit, bVerboseLogging

' Globals to hold client state for this execution of the script
Dim bPerformance, bAvailability, bFoundErrorState
bPerformance = True
bAvailability = True

' Accessed via many parts of the script
Dim owParams, IsTargetAgentless,TargetFQDNComputer, oReg, oAPI, bLogSuccess, oBag, strVerboseLogging
Set owParams = WScript.Arguments
if owParams.Count &lt; 7 Then
Wscript.quit -1
End if

IsTargetAgentless = false
oReg = Null
Set oAPI = CreateObject("Mom.ScriptAPI")
Err.Clear


Dim sStateValuePath
sStateValuePath= "HKLM\" &amp; oAPI.GetScriptStateKeyPath(owParams(6))

' Registry Constants
Dim REGISTRY_TESTS
REGISTRY_TESTS = sStateValuePath &amp; "\AD Management Pack\Tests"

' Registry Path to share data across scripts
Dim REG_Key
REG_Key = sStateValuePath &amp; "\AD Management Pack\AD Client Connectivity"

Sub Main()
On Error Resume Next

If Not(IsTargetAgentless) Then
Dim dtStart
dtStart = Now
bFoundErrorState = false

TargetFQDNComputer = owParams(0)
bLogSuccess = CBool(owParams(1))'LogSuccessEvent
bVerboseLogging = CBool(owParams(7))

Dim strClientComputer
strClientComputer = TargetFQDNComputer

PerformGlobalSetup
If Err = 0 Then
' Run the tests
Dim astrDCs, strComputer, strDomain, strFQDN, bContinue, bFailed
astrDCs = LoadDCsFromFile()
If Err &lt;&gt; 0 Then
ScriptError "while loading the Domain Controllers from file."
Else
Dim iIndex
For iIndex = 0 To UBound(astrDCs)
Dim strLine
strLine = astrDCs(iIndex)
Err.Clear

if iIndex = 0 Then
If 0 = Len(strLine) Then ' in case the array of DCs is empty
strFQDN = oOOMADS.PDCMaster
strComputer = oOOMADS.GetFlatComputerName(strFQDN)
strDomain = oOOMADS.GetDomainForDC(strFQDN)
End if
Else
' Split the line into a DC and Domain components
SplitConfigLineIntoComponents strLine, strDomain, strComputer, strFQDN
End If

If Err = 0 Then
If 0 &lt; Len(strComputer) And 0 &lt; Len(strDomain) And 0 &lt; Len(strFQDN) Then
bContinue = False
bFailed = False
PingTest strFQDN
If Err = 0 Then
bContinue = True
Else
bFailed = True
bAvailability = False
End If
HandleScriptReturn strComputer, strDomain, PING_TEST
If bContinue Then
NetUseTest strFQDN
If Err &lt;&gt; 0 Then
bFailed = True
bAvailability = False
End If
HandleScriptReturn strComputer, strDomain, NETUSE_TEST

' Clear any residual errors
Err.Clear
LDAPPingTest strFQDN, strComputer, strDomain
If Err = 0 Then
bContinue = True
Else
bFailed = True
bContinue = False
bAvailability = False
End If
HandleScriptReturn strComputer, strDomain, LDAP_PING_TEST

If bContinue Then
ADSIBindTest strFQDN, strComputer, strDomain
If Err = 0 Then
bContinue = True
Else
bFailed = True
bContinue = False
' We're not setting bAvailability to False here because
' it has to be set inside the ADSIBindTest in case it failed
' the performance test rather than the connectivity test
End If
HandleScriptReturn strComputer, strDomain, ADSIBIND_TEST
End If
End If

If Not(bFailed) Then
' We did not encounter any errors for this iteration of the tests
' clear the consecutive errors counter for this computer.
ResetConsecutiveErrorCounters strComputer, strDomain

' Note that we do not create the property bag with the state "GOOD" here because that will be
' created only if by the end of iterating through the Domain Controller's array we find no issues.
End If
End If
End If
Next
End If
Else
ScriptError "while performing global setup."
End If


If CBool(GetTestParameter(SCRIPT_NAME, LOG_SUCCESS, bLogSuccess)) Then
CreateEvent EVENT_ID_SUCCESS, EVENT_TYPE_INFORMATION, "The script '" &amp; SCRIPT_NAME &amp; _
"' has completed in " &amp; DateDiff("s", dtStart, Now) &amp; " seconds."
End If
Else
bFoundErrorState=true
CreateEvent EVENT_ID_AGENTLESS, EVENT_TYPE_ERROR, "The AD Management Pack does not support the agentless management mode." &amp; vbCrLf &amp; _
"The script '" &amp; SCRIPT_NAME &amp; "' will not execute." &amp; vbCrLf &amp; _
"To prevent this alert being generated again, either change the monitoring " &amp; _
"mode of the computer '" &amp; TargetFQDNComputer &amp; "' to agent-managed " &amp; _
"or disable the rule that generated this alert."
End If
if bFoundErrorState=false Then
set oBag = oAPI.CreateTypedPropertyBag(StateDataType)
oBag.AddValue "State", "GOOD"
oBag.AddValue "EventID", EVENT_ID_SUCCEEDED
oAPI.AddItem oBag
End If

oAPI.ReturnItems
End Sub

'******************************************************************************
Function GetTestParameter(strTest, strParameterName, strDefaultParamValue)
'
' Purpose: To retrieve a script parameter. The parameter is first retrieved
' from the ScriptContext, then if an entry exists in the .ini file
' that entry will be used instead.
'
' Parameters: strTest - The name of the test.
' strParameterName - The name of the parameter being retrieved.
'
' Returns: The value of the parameter (if it is found in either the ScriptContext,
' or the registry)
'
On Error Resume Next
GetTestParameter = strDefaultParamValue

Dim oReg
Set oReg = CreateObject("WScript.Shell")
If 0 &lt;&gt; Err Then
ScriptError "create the 'WScript.Shell' object."
Else
Dim strKey, strValue
strKey = REGISTRY_TESTS &amp; "\" &amp; strTest &amp; "\" &amp; strParameterName
strValue = oReg.RegRead(strKey)
If Err = 0 Then
If 0 &lt; Len(strValue) Then
GetTestParameter = strValue
End If
Else
If Err = &amp;H80040004 Or _
Err = &amp;H80070002 Or _
Err = &amp;H80070003 Then
' The registry key wasn't there, this is expected if the user does
' not wish to override the global parameter
Err.Clear
Else
ScriptError "reading the parameter '" &amp; strParameterName &amp; "' for the test '" &amp; _
strTest &amp; "' from the registry."
End If
End If
End If
End Function

'******************************************************************************
Sub GetTestParameters(strTest, dictParams)
'
' Purpose: To retrieve the parameters for the script.
'
' Parameters: strTest - the name of the test
' dictParams - a dictionary that holds the parameter names. The
' parameter values will be filled in by this method.
'
' Returns: Nothing
'
If Not IsObject(dictParams) Then
Err.Raise ERR_PARAM_NOT_FOUND, "GetScriptParameters", "dictParams must be an object."
End If

Dim aKeys, avalues
aKeys = dictParams.Keys
avalues = dictParams.Items

Dim iIndex
For iIndex = 0 to UBound(aKeys)
dictParams.Item(aKeys(iIndex)) = GetTestParameter(strTest, aKeys(iIndex), avalues(iIndex))
Next
End Sub

'******************************************************************************
Function LoadDCsFromFile()
'
' Purpose: To retrieve a list of DC names from a file
'
' Parameters: astrDCs - the array to put the DC names into
'
' Returns: Nothing
'
Dim oFSO, oTempFolder, oFile, astrDCs
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTempFolder = oFSO.GetSpecialFolder(2) ' Temp Folder

On Error Resume Next
Set oFile = oFSO.OpenTextFile(oTempFolder.Path &amp; "\MonitoredDCs.txt", 1, False, -1)

If Err = 0 Then
Do Until oFile.AtEndOfStream
On Error Goto 0
Dim strLine
strLine = oFile.ReadLine()

If IsArray(astrDCs) Then
Dim iSize
' LBound is always 0, so with one element, UBound is also 0. Increment it
' by one to make space for the new item.
iSize = UBound(astrDCs) + 1
Redim Preserve astrDCs(iSize)
astrDCs(iSize) = strLine
Else
' Create an array with the first item in it.
astrDCs = Array(strLine)
End If
Loop
Else
' If the error is 'file does not exist' then it just means that
' the script 'AD Client Update DCs' has not produced a list of
' DCs yet. Ignore this error.
If Err = &amp;H35 Then
Err.Clear
astrDCs = Array("")
End If
End If

LoadDCsFromFile = astrDCs
End Function

'******************************************************************************
Function GetLocalSiteName()
'
' Purpose: To retrieve the site name for this computer.
'
' Returns: String, the site name (or an empty string if it cannot be determined)
'
Dim oADSysInfo
Set oADSysInfo = CreateObject("ADSystemInfo")

GetLocalSiteName = oADSysInfo.SiteName
End Function

'******************************************************************************
Sub LogEvent()
'
' Purpose: To log the current error as an event
'
' Parameters: None
'
' Returns: Nothing
'
lErr = Err.number
strErrorDescription = Err.Description
strErrorSource = Err.Source

On Error Resume Next
CreateEvent EVENT_ID_SCRIPT_FAILURE, EVENT_TYPE_INFORMATION, "An error occurred while executing " &amp; _
strErrorSource &amp; "." &amp; vbCrLf &amp; "The error was:" &amp; vbCrLf &amp; _
strErrorDescription &amp; " (0x" &amp; Hex(lError) &amp; ")"
End Sub

'******************************************************************************
Sub LogError()
'
' Purpose: To log the current error as an error
'
' Parameters: None
'
' Returns: Nothing
'
lErr = Err.number
strErrorDescription = Err.Description
strErrorSource = Err.Source

On Error Resume Next
CreateEvent EVENT_ID_SCRIPT_FAILURE, EVENT_TYPE_ERROR, "An error occurred while executing " &amp; _
strErrorSource &amp; "." &amp; vbCrLf &amp; "The error was:" &amp; vbCrLf &amp; _
strErrorDescription &amp; " (0x" &amp; Hex(lError) &amp; ")"
End Sub

'******************************************************************************
Sub CreateEvent(lEventID, lEventType, strMessage)
'
' Purpose: To generate a MOM event
'
' Arguments: lEventID, the event code
' lEventType, the severity of the event
' strMessage, the message to include in the event
'
On Error Resume Next

oAPI.LogScriptEvent "AD Client Connectivity", lEventID, lEventType, strMessage
End Sub

'******************************************************************************
Sub ScriptError(strContext)
'
' Purpose: To generate an alert for the current error and then throw the
' exception so it can be caught at a higher level.
'
' Arguments: strContext - the current context, this is added to the message
' that is alerted to the user
'
' Returns: nothing
'
' Remarks: Always throws an error
'
Dim strError
strError = "The script '" &amp; SCRIPT_NAME &amp; "' failed while " &amp; strContext &amp; _
GetErrorString(Err)

CreateEvent EVENT_ID_SCRIPT_FAILURE, EVENT_TYPE_WARNING, strError
bFoundErrorState=true
End Sub

'******************************************************************************
Sub PingTest(strComputer)
'
' Purpose: To perform a ping test against the specified computer
'
' Arguments: strComputer - the computer to be tested.
'
' Returns: nothing
'
' Remarks: If an error occurs, it will be thrown, it must be caught by the
' caller
'
On Error Resume Next

' Use the OOMADS object to Ping the computer
'Dim strIPAddress
'strIPAddress = oOOMADS.GetIPAddress(strComputer)

Dim bBindSuccess, bPingSuccess, bDNSSuccess, lAttemptCount
bBindSuccess = False
bPingSuccess = False
bDNSSuccess = False

'If Len(strIPAddress) &gt; 0 Then
If Len(strComputer) &gt; 0 Then
bDNSSuccess = True

Dim lngPingTime
lngPingTime = 0
lAttemptCount = 0

' If the ping or bind fails then retry it up to MAX_REPEAT_COUNT times.
' This is to accomodate any transient network conditions that may exist.
Do
lngPingTime = oOOMADS.Ping(strComputer)
If 0 &gt; lngPingTime Then
' Wait a bit before trying again.
oOOMADS.Sleep 500
End If

lAttemptCount = lAttemptCount + 1
Loop While (0 &gt; lngPingTime) And (lAttemptCount &lt; MAX_REPEAT_COUNT)

If 0 &gt; lngPingTime Then
' The ping failed, generate an alert
lErr = Err.number
strErr = Err.Description

On Error Goto 0
Err.Raise ERR_PING_FAILED, "Ping Test", "Failed to ping the domain controller '" &amp; _
strComputer &amp; "." &amp; strErr &amp; " (0x" &amp; Hex(lErr) &amp; ")"
End If
Else
lErr = Err.number
strErr = Err.Description

Dim strMessage
strMessage = "Getting the IP Address of the " &amp; _
"domain controller '" &amp; strComputer &amp; "' failed." &amp; vbCrLf &amp; _
strErr &amp; " (0x" &amp; Hex(lErr) &amp; ")" &amp; vbCrLf

' Get the DNS servers configured for this machine
Dim strDNSServers
strDNSServers = GetDNSServerList()

If Len(strDNSServers) &gt; 0 Then
strMessage = strMessage &amp; "The DNS servers configured for this machine are:" &amp; _
vbCrLf &amp; strDNSServers
End If

On Error Goto 0
Err.Raise ERR_PING_FAILED, "Ping Test", strMessage
End If

If bVerboseLogging Then
strVerboseLogging = vbCrLf &amp; _
"The Ping test for " &amp; SCRIPT_NAME &amp; " has been invoked with the following arguments:" &amp; vbCrLf &amp; _
"StateValuePath = " &amp; sStateValuePath &amp; vbCrLf &amp; _
"Computer = " &amp; strComputer &amp; vbCrLf &amp; _
"FailLimit = " &amp; lFailLimit &amp; vbCrLf &amp; _
"AttemptCount = " &amp; lAttemptCount &amp; vbCrLf &amp; _
"MaxRepeatCount = " &amp; MAX_REPEAT_COUNT &amp; vbCrLf &amp; _
"PingTime = " &amp; lngPingTime &amp; vbCrLf &amp; _
"VerboseLogging = " &amp; bVerboseLogging &amp; vbCrLf
End If
End Sub

'******************************************************************************
Sub PerformGlobalSetup()
'
' Purpose: To perform global setup for the
'
' Arguments: none
'
' Returns: nothing
'
' Remarks: Sets up the global variables and objects. If an error is thrown
' by this method, the other tests cannot run.
' NOTE: No error handling, any errors must be caught by caller
'
' Make sure there is no error handling
On Error Goto 0

' Create an instance of the COM object
Set oOOMADS = CreateObject("McActiveDir.ActiveDirectory")

If (0 &lt;&gt; Err.Number) Or (Not(IsObject(oOOMADS))) Then
Dim errorString
errorString = "The script '" &amp; SCRIPT_NAME &amp; "' failed to create object " &amp; _
"'McActiveDir.ActiveDirectory'. This is an unexpected error." &amp; vbCrLf &amp; vbCrLf &amp; _
GetErrorString(Err) &amp; vbCrLf &amp; vbCrLf &amp; _
"The Active Directory Management Pack Objects (OOMADs) components are not installed on the Domain Controller. These components are required for the monitoring scripts to run successfully. See Alert Knowledge for additional details."

CreateEvent EVENT_ID_SCRIPT_FAILURE, EVENT_TYPE_ERROR, errorString

Exit Sub
End If

' Create an instance of the ADO object
Set oADOConn = CreateObject("ADODB.Connection")
oADOConn.Provider = "ADSDsOObject"
oADOConn.Open "ADs Provider"

' Get the global script parameters

lFailLimit = CLng(GetTestParameter(SCRIPT_NAME, FAIL_LIMIT, owParams(4)))
If lFailLimit &lt; 1 Then
InvalidParameter FAIL_LIMIT, GTE, 3, "", 1, 0
lFailLimit = 3
End If



End Sub

'******************************************************************************
Sub NetUseTest(strComputer)
'
' Purpose: To perform a net use test against the specified computer
'
' Arguments: strComputer - the computer to be tested.
'
' Returns: nothing
'
' Remarks: If an error occurs, it will be thrown, it must be caught by the
' caller
'
On Error Resume Next

Dim oNetwork
Set oNetwork = CreateObject("WScript.Network")
If 0 &lt;&gt; Err.Number Then
On Error Goto 0
lErr = Err.number
strErr = Err.Description
On Error Goto 0
Err.Raise ERR_NETUSE_FAILED, "NetUseTest", _
"failed to create the object 'WScript.Network'." &amp; vbCrLf &amp; _
strErr &amp; vbCrLf &amp; "(0x" &amp; Hex(lErr) &amp; ")"
Else
' Connect to the Sysvol share on the DC
oNetwork.MapNetworkDrive "", "\\" &amp; strComputer &amp; "\SYSVOL"
If 0 &lt;&gt; Err.Number Then
lErr = Err.number
strErr = Err.Description
On Error Goto 0
Err.Raise ERR_NETUSE_FAILED, "NetUseTest", _
"'net use \\" &amp; strComputer &amp; "\SYSVOL' failed." &amp; vbCrLf &amp; _
strErr &amp; vbCrLf &amp; "(0x" &amp; Hex(lErr) &amp; ")"
Else
' Delete the share that was created
oNetwork.RemoveNetworkDrive "\\" &amp; strComputer &amp; "\SYSVOL"
End If
Set oNetwork = Nothing
End If

If bVerboseLogging Then
strVerboseLogging = vbCrLf &amp; _
"The NET USE test for " &amp; SCRIPT_NAME &amp; " has been invoked with the following arguments:" &amp; vbCrLf &amp; _
"StateValuePath = " &amp; sStateValuePath &amp; vbCrLf &amp; _
"Computer = " &amp; strComputer &amp; vbCrLf &amp; _
"FailLimit = " &amp; lFailLimit &amp; vbCrLf &amp; _
"VerboseLogging= " &amp; bVerboseLogging &amp; vbCrLf
End If

' Sometimes the RemoveNetworkDrive call fails, ignore it and continue
Err.Clear
End Sub

'******************************************************************************
Sub LDAPPingTest(strFQMN, strComputer, strDomain)
'
' Purpose: To perform an LDAP Ping against the specified computer
'
' Arguments: strFQDN - the FQMN of the machine to be tested
' strComputer - the computer to be tested.
' strDomain - the domain of the computer being tested
'
' Returns: nothing
'
' Load the parameters
Dim oParams
Set oParams = CreateObject("Scripting.Dictionary")

' Add the parameters to the dictionary
oParams.Add LDAP_PING_TIMEOUT, owParams(5)

' Get the parameter values
GetTestParameters SCRIPT_NAME, oParams
If 0 &lt;&gt; Err.number Then
ScriptError Err
Else
' Read the parameters from the dictionary
Dim lTimeout
lTimeout = CDbl(oParams.Item(LDAP_PING_TIMEOUT))

' Validate the parameters
If lTimeout &gt; 60 Then
InvalidParameter LDAP_PING_TIMEOUT, LTE, 10, "seconds", 60, 0
lTimeout = 10
End If

' Make sure we don't have any residual errors lingering around
Err.Clear

' Do the test using the global oomads object
Dim lPingTime
On Error Resume Next
lPingTime = oOOMADS.LDAPPing(strFQMN, lTimeout)

If Err &lt;&gt; 0 Then
lErr = Err.number
strErr = Err.Description
On Error Goto 0
Err.Raise ERR_LDAP_PING_FAILED, "LDAPPingTest", "The LDAP Ping to '" &amp; strComputer &amp; "' failed." &amp; _
vbCrLf &amp; strErr &amp; " (0x" &amp; Hex(lErr) &amp; ")"
Else
' Ping succeeded, record the perf data (in seconds rather than milliseconds)
Set oBag= oAPI.CreateTypedPropertyBag(PerformanceDataType)
oBag.AddValue "StatusCounter", "AD Client LDAP Ping Time"
oBag.AddValue "StatusInstance", strFQMN
oBag.AddValue "StatusValue", "" &amp; (lPingTime / 1000)
oAPI.addItem oBag

End If
End If

If bVerboseLogging Then
strVerboseLogging = vbCrLf &amp; _
"The LDAP Ping test for " &amp; SCRIPT_NAME &amp; " has been invoked with the following arguments:" &amp; vbCrLf &amp; _
"StateValuePath = " &amp; sStateValuePath &amp; vbCrLf &amp; _
"FQMN = " &amp; strFQMN &amp; vbCrLf &amp; _
"Computer = " &amp; strComputer &amp; vbCrLf &amp; _
"Domain = " &amp; strDomain &amp; vbCrLf &amp; _
"FailLimit = " &amp; lFailLimit &amp; vbCrLf &amp; _
"Timeout = " &amp; lTimeout &amp; vbCrLf &amp; _
"VerboseLogging = " &amp; bVerboseLogging &amp; vbCrLf
End If

End Sub

'******************************************************************************
Sub ADSIBindTest(strFQMN, strComputer, strDomain)
'
' Purpose: To perform a bind test against the specified computer
'
' Arguments: strFQMN - the FQMN of the machine to be tested
' strComputer - the computer to be tested.
' strDomain - the domain of the computer being tested
'
' Returns: nothing
'
On Error Resume Next

' Load the parameters
Dim oParams
Set oParams = CreateObject("Scripting.Dictionary")

' Add the parameters to the dictionary
oParams.Add BIND_THRESHOLD, owParams(2)
oParams.Add SEARCH_THRESHOLD, owParams(3)

' Get the parameter values
GetTestParameters SCRIPT_NAME, oParams
If 0 &lt;&gt; Err.number Then
ScriptError "getting the ADSI Bind test parameters."
Else
' Read the parameters from the dictionary
Dim lBindThreshold, lSearchThreshold
lBindThreshold = CDbl(oParams.Item(BIND_THRESHOLD))
lSearchThreshold = CDbl(oParams.Item(SEARCH_THRESHOLD))

' Validate the parameters
If lBindThreshold &gt; 60000 Then
InvalidParameter BIND_THRESHOLD, LTE, 1000, "milliseconds", 60000, 0
lBindThreshold = 1000
End If
If lSearchThreshold &gt; 60000 Then
InvalidParameter SEARCH_THRESHOLD, LTE, 2000, "milliseconds", 60000, 0
lSearchThreshold = 2000
End If

If bVerboseLogging Then
strVerboseLogging = vbCrLf &amp; _
"The ADSI Bind test for " &amp; SCRIPT_NAME &amp; " has been invoked with the following arguments:" &amp; vbCrLf &amp; _
"StateValuePath = " &amp; sStateValuePath &amp; vbCrLf &amp; _
"FQMN = " &amp; strFQMN &amp; vbCrLf &amp; _
"Computer = " &amp; strComputer &amp; vbCrLf &amp; _
"Domain = " &amp; strDomain &amp; vbCrLf &amp; _
"FailLimit = " &amp; lFailLimit &amp; vbCrLf &amp; _
"BindThreshold = " &amp; lBindThreshold &amp; vbCrLf &amp; _
"SearchThreshold = " &amp; lSearchThreshold &amp; vbCrLf &amp; _
"VerboseLogging = " &amp; bVerboseLogging &amp; vbCrLf
End If


Dim oRootDSE
Dim dtStart, dtEnd, lDiff
Set oRootDSE = oOOMADs.BindObject("LDAP://" &amp; strFQMN &amp; "/RootDSE")
lDiff = oOOMADs.BindLast
If Err &lt;&gt; 0 Then
ScriptError "getting 'LDAP://" &amp; strFQMN &amp; "/RootDSE."
bAvailability = False
Else
' Bind succeeded, record perf data
Set oBag= oAPI.CreateTypedPropertyBag(PerformanceDataType)
oBag.AddValue "StatusCounter", "AD Client LDAP Bind Time"
oBag.AddValue "StatusInstance", strFQMN
oBag.AddValue "StatusValue", "" &amp; (lDiff / 1000)
oAPI.addItem oBag

If lDiff &gt; lBindThreshold Then
bPerformance = False
' The bind threshold was exceeded, generate an event
On Error Goto 0
' The search threshold was exceeded, raise an error
Err.Raise ERR_SEARCH_TIMEOUT, "ADSIBindTest", "The bind to 'LDAP://" &amp; _
strFQMN &amp; "/RootDSE' took " &amp; lDiff &amp; " milliseconds, " &amp; _
"which is longer than the allowed " &amp; lBindThreshold &amp; _
" milliseconds."
End If

' We have the RootDSE, now try searching for an object
Dim strDomainNamingContext
strDomainNamingContext = oRootDSE.Get("defaultNamingContext")

Dim strSearch
strSearch = "&lt;LDAP://" &amp; strFQMN &amp; "/" &amp; strDomainNamingContext &amp; _
"&gt;;(cn=" &amp; strComputer &amp; ");cn;subtree"

dtStart = Now
Dim rsResults
Set rsResults = oADOConn.Execute(strSearch)
dtEnd = Now
lDiff = DateDiff("s", dtStart, dtEnd)
If 0 &lt;&gt; Err Then
lErr = Err.number
strErr = Err.Description
bAvailability = False
On Error Goto 0
Err.Raise ERR_SEARCH_FAILED, "ADSIBindTest", "The search '" &amp; strSearch &amp; "' failed." &amp; _
vbCrLf &amp; strErr &amp; " (0x" &amp; Hex(lErr) &amp; ")"
Else
' Enumerate the results
While Not rsResults.EOF
rsResults.MoveNext
Wend

If 0 &lt;&gt; Err Then
lErr = Err.number
strErr = Err.Description
bAvailability = False
On Error Goto 0
Err.Raise ERR_SEARCH_FAILED, "ADSIBindTest", "Enumerating the results from the " &amp; _
"search '" &amp; strSearch &amp; "' failed." &amp; vbCrLf &amp; strErr &amp; _
" (0x" &amp; Hex(lErr) &amp; ")"
Else
' Search succeeded, record perf data
Set oBag= oAPI.CreateTypedPropertyBag(PerformanceDataType)
oBag.AddValue "StatusCounter", "ADSI Client Search Time"
oBag.AddValue "StatusInstance",""
oBag.AddValue "StatusValue", "" &amp; lDiff
oAPI.addItem oBag

If lDiff &gt; lSearchThreshold Then
bPerformance = False
On Error Goto 0
' The search threshold was exceeded, raise an error
Err.Raise ERR_SEARCH_TIMEOUT, "ADSIBindTest", "The search '" &amp; strSearch &amp; _
"' took " &amp; lDiff &amp; " milliseconds, which is longer than the " &amp; _
"allowed " &amp; lSearchThreshold &amp; " milliseconds."
End If
End If
End If
End If
End If
End Sub

'******************************************************************************
Sub InvalidParameter(strParameter, lParamType, lDefault, strUnits, l1st, l2nd)
'
' Purpose: To log an event indicating what was wrong with the parameter
'
' Arguments: strParamter - the parameter name
' lParamType - the type of the error, whether it should have been
' less than a number, greater or within a band
' lDefault - the default value that the parameter will be set to
' strUnits - the units for the parameter (currently unused)
' l1st - the first boundary (used for all parameter types)
' l2nd - the second boundary (only used for bands)
'
' Returns: nothing
'
On Error Resume Next

Dim strMessage
strMessage = "The script '" &amp; SCRIPT_NAME &amp; "' has detected an invalid parameter." &amp; _
vbCrLf &amp; "The parameter '" &amp; strParameter &amp; "'"
Select Case lParamType
Case LTE
strMessage = strMessage &amp; " must be less than " &amp; l1st &amp; "."

Case GTE
strMessage = strMessage &amp; " must be greater than " &amp; l1st &amp; "."

Case BAND
strMessage = strMessage &amp; " must be between " &amp; l1st &amp; " and " &amp; l2nd &amp; "."
End Select

strMessage = strMessage &amp; vbCrLf &amp; vbCrLf &amp; "'" &amp; strParameter &amp; "' will be set to " &amp; _
lDefault &amp; " for this execution of the script."
CreateEvent EVENT_ID_INVALID_PARAMETER, EVENT_TYPE_WARNING, strMessage

End Sub

'******************************************************************************
Sub HandleScriptReturn(strComputer, strDomain, lTestID)
'
' Purpose: If Err &lt;&gt; 0 Then the test failed, generate an event indicating that
' the test failed. If three consecutive failures have occurred then
' generate an alert indicating this fact. If the test succeeded then
' clear the consecutive error count, if we are in an error state,
' generate a success event.
'
' Arguments: strComputer - the computer being tested.
' strDomain - the domain of the computer being tested
' lTestID - the identifier of the test.
'
' Returns: nothing
'
Dim lError, strError, strSource
lError = Err.number
strError = Err.Description
strSource = Err.Source
On Error Resume Next

Dim lConsecutiveErrors, tmp
tmp = GetData(strComputer &amp; "ErrCnt")
if tmp = "" Then
lConsecutiveErrors = 0
else
lConsecutiveErrors = CLng(tmp)
end if
If lError &lt;&gt; 0 Then
lConsecutiveErrors = lConsecutiveErrors + 1
If lConsecutiveErrors &lt;= lFailLimit Then
SetData strComputer &amp; "ErrDesc", CStr(GetData(strComputer &amp; "ErrDesc")) &amp; vbCrLf &amp; _
Now() &amp; " : " &amp; strError &amp; " (0x" &amp; Hex(lError) &amp; ")"
End If

If lConsecutiveErrors = lFailLimit Then
' Generate an event detailing the errors that occurred,
' and send 'BAD' property bag only after the number of
' failures equals the failure threshold.
Dim strMessage
strMessage = "While '" &amp; SCRIPT_NAME &amp; "' was running, " &amp; lFailLimit &amp; _
" consecutive errors were encountered." &amp; vbCrLf &amp; _
"A message will be generated when the test succeeds. " &amp; _
"Look for a success alert from '" &amp; SCRIPT_NAME &amp; _
"' with ID = " &amp; EVENT_ID_TEST_SUCCEEDED &amp; "." &amp; vbCrLf &amp; vbCrLf &amp; _
"To see the errors look for events from '" &amp; SCRIPT_NAME &amp; _
"' with event ID " &amp; EVENT_ID_TEST_FAILED &amp; ". The public " &amp; _
"view 'Client Side Events' shows these events." &amp; _
vbCrLf &amp; vbCrLf &amp; "The last " &amp; lFailLimit &amp; " errors were:"
strMessage = strMessage &amp; GetData(strComputer &amp; "ErrDesc")

CreateRemoteEvent strComputer, strDomain, EVENT_ID_ALERT_TEST_FAILED, EVENT_TYPE_WARNING, strMessage

set oBag = oAPI.CreateTypedPropertyBag(StateDataType)
oBag.AddValue "State", "BAD"
oBag.AddValue "EventID", EVENT_ID_TEST_FAILED
oBag.AddValue "ErrorString", strError
oAPI.AddItem oBag
bFoundErrorState = true
End If
CreateRemoteEvent strComputer, strDomain, EVENT_ID_TEST_FAILED, EVENT_TYPE_WARNING, strError

' Increment the counters
SetData strComputer &amp; "ErrCnt", lConsecutiveErrors

' Set the SuccessCount to 0 so that we'll execute the test again
' the next time the script runs
SetData strComputer &amp; "SuccessCount", 0
End If

If bVerboseLogging Then
strVerboseLogging = strVerboseLogging &amp; _
"ConsecutiveErrors = " &amp; lConsecutiveErrors &amp; vbCrLf
If lError &lt;&gt; 0 Then
strVerboseLogging = strVerboseLogging &amp; _
"Error number = " &amp; lError &amp; vbCrLf &amp; _
"Error Description = " &amp; strError &amp; vbCrLf &amp; _
"Error Source = " &amp; strSource &amp; vbCrLf
End If
CreateRemoteEvent strComputer, strDomain, EVENT_ID_VERBOSE_LOGGING, EVENT_TYPE_INFORMATION, strVerboseLogging
End If

End Sub

'******************************************************************************
Sub ResetConsecutiveErrorCounters(strComputer, strDomain)
'
' Purpose: Reset the consecutive error counters for a computer
'
' Arguments: strComputer, the computer to to reset the counters for
'
Dim lConsecutiveErrors, tmp
tmp = GetData(strComputer &amp; "ErrCnt")
if tmp = "" Then
lConsecutiveErrors = 0
else
lConsecutiveErrors = CLng(tmp)
end if

If lConsecutiveErrors &gt;= lFailLimit Then
' We have succeeded after a number of consecutive failures. Create a
' success event.
CreateRemoteEvent strComputer, strDomain, EVENT_ID_TEST_SUCCEEDED, EVENT_TYPE_INFORMATION, "The script '" &amp; SCRIPT_NAME &amp; "' has succeeded following " &amp; _
lConsecutiveErrors &amp; " consecutive failures." &amp; vbCrLf
End If

SetData strComputer &amp; "ErrCnt", 0
SetData strComputer &amp; "ErrDesc", ""
End Sub

'******************************************************************************
Sub CreateRemoteEvent(strComputer, strDomain, lEventID, lEventType, strMessage)
oAPI.LogScriptEvent "AD Client Connectivity", lEventID, lEventType, strMessage 'we dont have the api to log on remote machine
End Sub


'******************************************************************************
Function GetData(strKey)
On Error Resume Next

If IsNull(oReg) Then
Set oReg = CreateObject("WScript.Shell")
End If
Dim regData
regData = oReg.RegRead(REG_Key &amp; "\" &amp; strKey )
If IsNull(regData) or IsEmpty(regData) or regData = "" Then
GetData = ""
Else
GetData = regData
End If
Err.Clear
End Function

'******************************************************************************
Sub SetData(strKey, strData)

If IsNull(oReg) Then
Set oReg = CreateObject("WScript.Shell")
End If
Call oReg.RegWrite(REG_Key &amp; "\" &amp; strKey , strData )
Err.Clear
End Sub





'******************************************************************************
' Name: GetErrorString
'
' Purpose: Attempts to find the description for an error if an error with
' no description is passed in.
'
' Parameters: oErr, the error object
'
' Return: String, the description for the error. (Includes the error code.)
'
Function GetErrorString(oErr)
Dim lErr, strErr
lErr = oErr
strErr = oErr.Description

On Error Resume Next
If 0 &gt;= Len(strErr) Then
' If we don't have an error description, then check to see if the error
' is a 0x8007xxxx error. If it is, then look it up.
Const ErrorMask = &amp;HFFFF0000
Const HiWord8007 = &amp;H80070000
Const LoWordMask = 65535 ' This is equivalent to 0x0000FFFF

If (lErr And ErrorMask) = HiWord8007 Then
' Attempt to use 'net helpmsg' to get a description for the error.
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If Err = 0 Then
Dim oExec
Set oExec = oShell.Exec("net helpmsg " &amp; (lErr And LoWordMask))

Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i &lt; 5)

strErr = strMessage
End If
Else
Select Case lErr
Case &amp;H80041003
strErr = "WMI Provider Returned : Access Denied"
End Select
End If
End If

GetErrorString = "The error returned was: '" &amp; strErr &amp; "' (0x" &amp; Hex(lErr) &amp; ")"
End Function

'******************************************************************************
Function GetDNSServerList()
'
' Purpose: Generates a list of the DNS servers configured for the local
' computer
'
' Parameters: none
'
' Returns: String - the list of DNS servers
'
On Error Resume Next
' Work out what the configured DNS servers are:
Dim oWMI
Set oWMI = GetObject("winmgmts:").ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration")
If 0 &lt;&gt; Err Then
GetDNSServerList = "An error occurred while querying for the DNS servers configured " &amp; _
"for this machine." &amp; GetErrorString(Err)
Else
If IsEmpty(oWMI) Then
GetDNSServerList = "There are no DNS servers configured for this machine."
Else
Dim strDNSServers

' Add the configured DNS Servers to the message
Dim oX, strDNS
If IsObject(oWMI) Then
For Each oX in oWMI
If Not(IsNull(oX)) Then
If Not(IsNull(oX.DNSServerSearchOrder)) Then
For Each strDNS in oX.DNSServerSearchOrder
If Len(strDNS) &gt; 0 Then
strDNSServers = strDNSServers &amp; strDNS &amp; vbCrLf
End If
Next
End If
End If
Next
End If

GetDNSServerList = strDNSServers
End If
End If
End Function

'******************************************************************************
Sub SplitConfigLineIntoComponents(strLine, strDomain, strComputer, strFQDN)
'
' Purpose: Splits a line read from the configuration file into it's
' components.
'
' Parameters: strLine - The line to split
' strDomain - The domain part
' strComputer - The short computer name
' strFQDN - The computers FQDN (will hold the short name if
' there is no FQDN in the file)
'
' Returns: nothing
'
Dim iSplit
' Find the first delimiter
iSplit = Instr(strLine, "\")

' We must have a domain because the machine is a DC. If there is no domain then the
' AD Update DCs script failed.
If 0 &lt;&gt; iSplit Then
strDomain = Left(strLine, iSplit - 1)
strLine = Mid(strLine, iSplit + 1)

' Now look for a second delimiter. If there isn't one, use the remainder of
' the line as both the FQDN and the short name.
iSplit = Instr(strLine, "\")
If 0 &lt;&gt; iSplit Then
strComputer = Left(strLine, iSplit - 1)
strFQDN = Mid(strLine, iSplit + 1)
Else
strComputer = strLine
strFQDN = strComputer
End If
Else
Err.Raise EVENT_ID_INVALID_PARAMETER, SCRIPT_NAME, "The line read from the configuration file is invalid." &amp; vbCrLf &amp; _
"It should be of the form 'Domain/ComputerName/ComputerFQDN'." &amp; vbCrLf &amp; _
"The line in error is:" &amp; vbCrLf &amp; strLine
End If
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>