Dim oAPI, oParams, TargetFQDNComputer, IsTargetAgentless, lFailureThreshold
Set oParams = WScript.Arguments
if oParams.Count < 2 then
Wscript.Quit -1
End if
TargetFQDNComputer = oParams(0)
lFailureThreshold = oParams(1)
Set oAPI = CreateObject("Mom.ScriptAPI")
Err.Clear
Sub Main()
Dim objAD, objParams, objADsObject
Dim lLastBind, strComputer, bBindSuccessful
Set objAD = CreateObject("McActiveDir.ActiveDirectory")
If (0 <> Err.Number) Or (Not(IsObject(objAD))) Then
Dim errorString
errorString = "The script '" & SCRIPT_NAME & "' failed to create object " & _
"'McActiveDir.ActiveDirectory'. This is an unexpected error." & vbCrLf & vbCrLf & _
GetErrorString(Err.Number, Err.Description) & vbCrLf & vbCrLf & _
"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."
HandleScriptFailure errorString
Else
objAD.Server = strComputer
Set objADsObject = objAD.BindObject("LDAP://rootDSE")
If (Err.Number <> 0) Or (Not(IsObject(objADsObject))) Then
Set oBag = oAPI.CreateTypedPropertyBag(StateDataType)
HandleScriptFailure "Failed to bind to 'LDAP://rootDSE'. This is an unexpected error." & vbCrLf & vbCrLf & _
GetErrorString(Err.Number, Err.Description)
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: " & (lLastBind / 1000) & " sec"
If ((lLastBind / 1000) > CLng(lFailureThreshold)) then
HandleScriptFailure "The current DC bind time was " & (lLastBind / 1000) & _
" second(s) which is outside of the defined threshold of " & lFailureThreshold & _
" second(s). Please check the domain controller as this may indicate a performance problem."
End If
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)
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 >= 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 = &HFFFF0000
Const HiWord8007 = &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 " & (lErrNumber And LoWordMask))
Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i < 5)
strErrDescription = strMessage
End If
End If
End If
GetErrorString = "The error returned was '" & strErrDescription & "' (0x" & Hex(lErrNumber) & ")"
End Function
'******************************************************************************
' Name: HandleScriptFailure
'
' Purpose: Handles a script failure.
'
' Parameters: strFailure, the description of the failure.
'
' Return: Nothing
'
Sub HandleScriptFailure (strFailure)
CreateEvent EVENTID_SCRIPT_FAILURE, EVENT_TYPE_WARNING, strFailure
WScript.Echo "Error: " & strFailure
End Sub