Fonte de Dados do Script de Disponibilidade do Cliente do AD

AD_Client_GC_Availability.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
MinimumAvailableGCsint$Config/MinimumAvailableGCs$G Cs Mínimo Disponível
TimeoutSecondsint$Config/TimeoutSeconds$Tempo limite (segundos)

Source Code:

<DataSourceModuleType ID="AD_Client_GC_Availability.DataSource" Accessibility="Internal">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:int"/>
<xsd:element name="TargetComputerName" type="xsd:string"/>
<xsd:element name="MinimumAvailableGCs" type="xsd:int"/>
<xsd:element name="LogSuccessEvent" type="xsd:boolean"/>
<xsd:element name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" ParameterType="int" Selector="$Config/IntervalSeconds$"/>
<OverrideableParameter ID="LogSuccessEvent" ParameterType="string" Selector="$Config/LogSuccessEvent$"/>
<OverrideableParameter ID="MinimumAvailableGCs" ParameterType="int" Selector="$Config/MinimumAvailableGCs$"/>
<OverrideableParameter ID="TimeoutSeconds" ParameterType="int" Selector="$Config/TimeoutSeconds$"/>
</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_GC_Availability.vbs$ $Config/TargetComputerName$ $Config/MinimumAvailableGCs$ $Config/LogSuccessEvent$</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>AD_Client_GC_Availability.vbs</Name>
<Contents><Script>
'*************************************************************************
' Script Name - AD Client GC Availability
'
' Purpose - Attempts to contact all the configured GCs
' Generates alerts if either there are not enough GCs
' configured, or if not enough GCs are contactable
'
' Assumptions - Script is run by a timed event
'
' Parameters - MinimumAvailableGCs - the minimum number of GCs that must
' be available at all times
' LogSuccessEvent - Logs an event when the script completes.
'
' (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_EVENT_RULE_ONLY = 5002
Const EVENT_ID_INVALID_PARAMETER = 5003
Const EVENT_ID_AGENTLESS = 98

' Script specific Event IDs
Const EVENT_ID_FAILED_AVAILABLE_GCS = 9002
Const EVENT_ID_AVAILABLE_GCS_OK = 998

' Other Constants
Const SCRIPT_NAME = "AD Client GC Availability"

' TypedPropertyBag
const PerformanceDataType = 2
const StateDataType = 3

' Variables
Dim IsTargetAgentless,TargetFQDNComputer
IsTargetAgentless = False

Dim oAPI,oBag
Set oAPI = CreateObject("Mom.ScriptAPI")
If Err &lt;&gt; 0 Then
ScriptError "initializing Mom.ScriptAPI."
End if

Call Main()

Sub Main()
On Error Resume Next
Dim dtStart
dtStart = Now

If Not(IsTargetAgentless) Then
Dim oParams, iMinimumConfiguredGCs, iMinimumAvailableGCs, bLogSuccessEvent
Set oParams = WScript.Arguments
if oParams.Count &lt; 3 then
Wscript.Quit -1
End if
TargetFQDNComputer = oParams(0)
iMinimumAvailableGCs = CLng(oParams(1))'MinimumAvailableGCs
bLogSuccessEvent = CBool(oParams(2))'LogSuccessEvent

Dim strInvalidParam
If (iMinimumAvailableGCs &lt; 0) Then
strInvalidParam = strInvalidParam &amp; "MinimumAvailableGCs must be greater than 0." &amp; _
"The current value of MinimumAvailableGCs is '" &amp; _
iMinimumAvailableGCs &amp; "'." &amp; vbCrLf &amp; _
"MinimumAvailableGCs will be set to the default value of 3" &amp; _
" for this execution of this script." &amp; vbCrLf
iMinimumAvailableGCs = 3
End If
If Len(strInvalidParam) &gt; 0 Then
' Found invalid parameters
InvalidParam strInvalidParam
End If

Err.Clear

' Obtain the RootDSE of any GC that this client computer can connect to.
Dim oRootDSE
Set oRootDSE = GetObject("GC://RootDSE")
If 0 &lt;&gt; Err Then
ScriptError "attempting to bind to the RootDSE of any GC in the domain."
Else
' Now query the root DSE to get the site of the DC
Dim strSite, strServerName, strDNSHostName, strConfigNamingContext
strServerName = oRootDSE.Get("ServerName")
strDNSHostName = oRootDSE.Get("DNSHostName")
strConfigNamingContext = oRootDSE.Get("ConfigurationNamingContext")
If 0 &lt;&gt; Err Then
ScriptError "attempting to read the 'ConfigurationNamingContext' of the GC '" &amp; strDNSHostName &amp; "'."
Else

' Query AD to determine all the configured GCs
Dim oADOConn
Set oADOConn = CreateObject("ADODB.Connection")
If Err &lt;&gt; 0 Then
ScriptError "creating 'ADODB.Connection'."
Else
oADOConn.Provider = "ADSDsOObject"
oADOConn.Open "ADs Provider"
If Err &lt;&gt; 0 Then
ScriptError "initializing ADODB.Connection."
Else
Dim rsGCs, strQuery
strQuery = "&lt;LDAP://" &amp; strDNSHostName &amp; "/CN=Sites," &amp; strConfigNamingContext &amp; "&gt;;(&amp;(objectClass=nTDSDSA)(options:1.2.840.113556.1.4.803:=1)(!isDeleted=TRUE));adspath,cn;subtree"
Set rsGCs = oADOConn.Execute(strQuery)
If 0 &lt;&gt; Err Then
ScriptError "executing the query '" &amp; strQuery &amp; "'."
Else
Dim oNTDSASettings, iAvailableGCs, strGCs, strUnavailableGCs
iAvailableGCs = 0
rsGCs.MoveFirst
Do Until rsGCs.EOF Or iAvailableGCs &gt;= iMinimumAvailableGCs
Set oNTDSASettings = GetObject(rsGCs.Fields("adspath"))

Err.Clear

If IsObject(oNTDSASettings) Then

Dim oServer
Set oServer = GetObject(oNTDSASettings.Parent)
If 0 &lt;&gt; Err Then
ScriptError "getting the object: '" &amp; oNTDSASettings.Parent &amp; "'."
Else
Dim strGCDNSHostName
strGCDNSHostName = oServer.Get("DNSHostName")
strGCs = strGCs &amp; strGCDNSHostName &amp; vbCrLf

Dim oGC
Set oGC = GetObject("GC://" &amp; strGCDNSHostName &amp; "/RootDSE")
If 0 &lt;&gt; Err Then
strUnavailableGCs = strUnavailableGCs &amp; strGCDNSHostName &amp; vbCrLf
Else
' Attempt to retrieve a property from the object (to force ADSI to actually connect).
Dim strTemp
strTemp = oGC.Get("DNSHostName")
If 0 &lt;&gt; Err Then
strUnavailableGCs = strUnavailableGCs &amp; strGCDNSHostName &amp; vbCrLf
Else
iAvailableGCs = iAvailableGCs + 1

' See if the high performance counters are available
Dim oPerfOS, bUseHighPerfCounters, iTicksPerSecond

Set oPerfOS = GetObject("winmgmts:\\.\root\cimv2:Win32_PerfRawData_PerfOS_System=@")
If Err = 0 Then
iTicksPerSecond = oPerfOS.Frequency_PerfTime
If Err = 0 Then
bUseHighPerfCounters = True
End If
End If

Err.Clear

' Now perform the GC search get perf numbers
strQuery = "&lt;LDAP://" &amp; strTemp &amp; "/" &amp; strConfigNamingContext &amp; "&gt;;(cn=" &amp; oServer.Get("cn") &amp; ");adspath;subtree"

Dim rsGCSearchResults, dtSearchStart, iSearchStart
dtSearchStart = Now
If bUseHighPerfCounters Then
iSearchStart = oPerfOS.TimeStamp_PerfTime
End If
Set rsGCSearchResults = oADOConn.Execute(strQuery)
If Err &lt;&gt; 0 Then
ScriptError "executing the query: '" &amp; strQuery &amp; "'."
Else
rsGCSearchResults.MoveFirst
If Err &lt;&gt; 0 Then
ScriptError "performing the search: '" &amp; strQuery &amp; "'."
Else
' Record perf data for the search
Dim iSearchLength
If bUseHighPerfCounters Then
Set oPerfOS = GetObject("winmgmts:\\.\root\cimv2:Win32_PerfRawData_PerfOS_System=@")
iSearchLength = Round((oPerfOS.TimeStamp_PerfTime - iSearchStart) / iTicksPerSecond, 2)
Else
iSearchLength = DateDiff("s", dtSearchStart, Now)
End If

Set oBag= oAPI.CreateTypedPropertyBag(PerformanceDataType)
Call oBag.AddValue("StatusInstance",oServer.Get("cn") )
Call oBag.AddValue("StatusValue","" &amp; iSearchLength )
Call oAPI.addItem(oBag)

End If
End If
End If
End If
End If
End If

rsGCs.MoveNext
Loop


Set oBag= oAPI.CreateTypedPropertyBag(StateDataType)
If iAvailableGCs &lt; iMinimumAvailableGCs Then
'
' Create an event indicating we have not met the minimum
' threshold for available GCs.
'
Dim strFailureMessage
strFailureMessage = "There are not enough GCs available. "
If Len(strUnavailableGCs) &gt; 0 Then
strFailureMessage = strFailureMessage &amp; "The GCs that are configured " &amp; _
"but could not be contacted are:" &amp; vbCrLf &amp; strUnavailableGCs
Else
strFailureMessage = strFailureMessage &amp; "There are fewer GCs configured " &amp; _
"than are specified as the minimum number of available GCs. " &amp; vbCrLf &amp; vbCrLf &amp; _
"Available GCs: " &amp; iAvailableGCs &amp; vbCrLf &amp; _
"Minimum GCs: " &amp; iMinimumAvailableGCs
End If

CreateEvent EVENT_ID_FAILED_AVAILABLE_GCS, EVENT_TYPE_ERROR, strFailureMessage

'
' Remember that we're in this state so we can create a success event later.
'
Call oBag.AddValue("State","BAD" )
Call oBag.AddValue("EventID",EVENT_ID_FAILED_AVAILABLE_GCS )

Else

Dim strSuccessMessage
strSuccessMessage = "There are now enough GCs available." &amp; vbCrLf &amp; vbCrLf &amp; _
"Available GCs: " &amp; iAvailableGCs &amp; vbCrLf &amp; _
"Minimum GCs: " &amp; iMinimumAvailableGCs

CreateEvent EVENT_ID_FAILED_AVAILABLE_GCS, EVENT_TYPE_SUCCESS, strSuccessMessage
Call oBag.AddValue("State","GOOD" )
Call oBag.AddValue("EventID",EVENT_ID_AVAILABLE_GCS_OK )

End If

Call oAPI.addItem(oBag)

If iAvailableGCs &gt;= iMinimumAvailableGCs And _
bLogSuccessEvent Then
CreateEvent EVENT_ID_SUCCESS, EVENT_TYPE_SUCCESS, _
"The script '" &amp; SCRIPT_NAME &amp; "' has completed successfully in " &amp; _
DateDiff("s", dtStart, Now) &amp; " second(s)." &amp; vbCrLf &amp; vbCrLf &amp; _
"The GCs configured are:" &amp; vbCrLf &amp; strGCs
End If
End If
End If
End If
End If
End If
Else
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

Call oAPI.ReturnItems()
End Sub

'******************************************************************************
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 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
Call oAPI.LogScriptEvent("AD Client GC Availability",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
'
Dim strError
strError = "The script '" &amp; SCRIPT_NAME &amp; "' encountered an error while " &amp; strContext &amp; _
GetErrorString(Err)

CreateEvent EVENT_ID_SCRIPT_FAILURE, EVENT_TYPE_WARNING, strError
End Sub

'******************************************************************************
Function GetErrorString(oErr)
'
' 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.)
'
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
End If
End If

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

'******************************************************************************
Sub InvalidParam(strError)
'
' Purpose: To generate an invalid parameter warning.
'
' Arguments: strError, the description of the error
'
CreateEvent EVENT_ID_INVALID_PARAMETER, EVENT_TYPE_WARNING, "The script '" &amp; SCRIPT_NAME &amp; _
"' detected an error with one or more " &amp; _
"parameters. The error is:" &amp; vbCrLf &amp; strError &amp; vbCrLf &amp; vbCrLf &amp; _
"To correct the error, find the rule 'Script - " &amp; SCRIPT_NAME &amp; "' and from the response tab of it's " &amp; _
"properties, edit the script and modify the parameter in question."
End Sub
</Script></Contents>
<Unicode>1</Unicode>
</File>
</Files>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>