AD General Response (Task and Diagnostic)

Microsoft.Server.AD.2003.GeneralResponseCheck (ProbeActionModuleType)

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
OutputTypeSystem.CommandOutput

Member Modules:

ID Module Type TypeId RunAs 
Script ProbeAction System.Secure.CommandExecuterProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$Timeout Seconds

Source Code:

<ProbeActionModuleType ID="Microsoft.Server.AD.2003.GeneralResponseCheck" Accessibility="Internal" Batching="false" PassThrough="false">
<Configuration>
<xsd:element name="TargetComputer" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="Script" TypeID="System!System.Secure.CommandExecuterProbe">
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/GeneralResponseCheck.vbs$ $Config/TargetComputer$</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>GeneralResponseCheck.vbs</Name>
<Contents><Script>
'*************************************************************************
' Script Name - AD General Response Task
'
' Purpose - Monitors the general responsiveness of active directory and prints to stdout
'
' (c) Copyright 2006, Microsoft Corporation, All Rights Reserved
' Proprietary and confidential to Microsoft Corporation
'*************************************************************************

Option Explicit

SetLocale ("en-us")

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

'Other constants
Const SCRIPT_NAME = "AD General Response"

Const EVENTID_INVALID_PARAMETER = 66
Const EVENT_ID_AGENTLESS = 98
Const EVENTID_SCRIPT_FAILURE = 1000
Const EVENT_ID_AD_GENERAL_RESPONSE_OK = 1091
Const EVENT_ID_AD_GENERAL_RESPONSE_NOTOK = 18909

' TypedPropertyBag

Dim oReg
oReg = NULL

Err.Clear

Sub Main()

Dim objAD, objParams, objEvent, objADsObject
Dim lLastBind, lAverageBind, lCount, lFailureThreshold
Dim strMessage, strComputer
Dim bBindSuccessful
Dim dtStart
dtStart = Now

' Other Variables
Dim oParams, TargetFQDNComputer, strFailureThreshold, bLogSuccessEvent, IsTargetAgentless
Set oParams = WScript.Arguments
if oParams.Count &lt; 1 then
WScript.Echo "One Parameter: &lt;Computername&gt; is required"
Wscript.Quit -1
End if

TargetFQDNComputer = oParams(0)
strFailureThreshold = 1
bLogSuccessEvent = False
Err.Clear

On Error Resume Next

Set objParams = Nothing

strComputer = TargetFQDNComputer
strComputer = LCase(strComputer)

Set objAD = CreateObject("McActiveDir.ActiveDirectory")
If (0 &lt;&gt; Err.Number) Or (Not(IsObject(objAD))) Then

HandleScriptFailure "Failed to create object 'McActiveDir.ActiveDirectory'." &amp; _
"This is an unexpected error." &amp; vbCrLf &amp; _
GetErrorString(Err.Number, Err.Description), _
lFailureThreshold
Else
objAD.Server = strComputer

Set objADsObject = objAD.BindObject("LDAP://rootDSE")
If (Err.Number &lt;&gt; 0) Or (Not(IsObject(objADsObject))) Then
Set oBag = oAPI.CreateTypedPropertyBag(StateDataType)

HandleScriptFailure "Failed to bind to 'LDAP://rootDSE'. This is an unexpected error." &amp; vbCrLf &amp; _
GetErrorString(Err.Number, Err.Description), _
lFailureThreshold
Else
bBindSuccessful = True
End If

Set objADsObject = Nothing

If bBindSuccessful Then
Set oBag = oAPI.CreateTypedPropertyBag(StateDataType)

lLastBind = objAD.BindLast
' Write the perf data, after converting to seconds (originally milliseconds)
Set oBag = oAPI.CreateTypedPropertyBag(PerformanceDataType)

WScript.Echo "Current DC bind time: " &amp; (lLastBind / 1000) &amp; " sec"

End If

Set objAD = Nothing
End If

End Sub

'******************************************************************************
' Name: CreateEvent
'
' Purpose: Creates a MOM event
'
' Parameters: lEventID, the ID for the event
' lEventType, the severity for the event. See constants at head of file
' strMessage, the message for the event
'
' Return: nothing
'
Sub CreateEvent(lEventID, lEventType, strMessage)

Dim sevString

Select Case lEventType
Case EVENT_TYPE_SUCCESS sevString="Success"
Case EVENT_TYPE_ERROR sevString="Error"
Case EVENT_TYPE_WARNING sevString="Warning"
Case EVENT_TYPE_INFORMATION sevString="Information"
End Select

If lEventType &lt;&gt; EVENT_TYPE_SUCCESS Then
WScript.Echo "AD General Respone Check - Event ID: " &amp; lEventID &amp; " " &amp; lEventType
WSCript.Echo strMessage
End If

' oAPI.LogScriptEvent "AD General Response", lEventID, lEventType, strMessage
End Sub

'******************************************************************************
' Name: GetErrorString
'
' Purpose: Attempts to find the description for an error if no description
' is passed in.
'
' Parameters: lErrNumber, the error number
' strErrDescription, the error description (if known)
'
' Return: String, the description for the error. (Includes the error code.)
'
Function GetErrorString(lErrNumber, strErrDescription)
On Error Resume Next
If 0 &gt;= Len(strErrDescription) 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 (lErrNumber And ErrorMask) = HiWord8007 Then
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If IsObject(oShell) Then
Dim oExec
Set oExec = oShell.Exec("net helpmsg " &amp; (lErrNumber And LoWordMask))

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

strErrDescription = strMessage
End If
End If
End If

GetErrorString = "The error returned was '" &amp; strErrDescription &amp; "' (0x" &amp; Hex(lErrNumber) &amp; ")"
End Function

'******************************************************************************
' Name: HandleScriptFailure
'
' Purpose: Handles a script failure. This checks to see if the number of
' failures has exceeded the threshold and if so generates an
' event. Also updates the daily count.
'
' Parameters: strFailure, the description of the failure.
' lThreshold, the failure threshold.
'
' Return: Nothing
'
Sub HandleScriptFailure(strFailure, lThreshold)
On Error Resume Next

CreateEvent EVENTID_SCRIPT_FAILURE, EVENT_TYPE_WARNING, strMessage

End Sub

Call Main()
</Script></Contents>
<Unicode>1</Unicode>
</File>
</Files>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Script"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<InputType>System!System.BaseData</InputType>
</ProbeActionModuleType>