Источник данных сценария "Active Directory: проверка DNS"

AD_DNS_Verification.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$Интервал (сек.)
LogSuccessEventstring$Config/LogSuccessEvent$Регистрация успешного события
TimeoutSecondsint$Config/TimeoutSeconds$Время ожидания (сек.)

Source Code:

<DataSourceModuleType ID="AD_DNS_Verification.DataSource" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:int"/>
<xsd:element name="LogSuccessEvent" type="xsd:boolean"/>
<xsd:element name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="LogSuccessEvent" Selector="$Config/LogSuccessEvent$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.CommandExecuterPropertyBagSource">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/AD_DNS_Verification.vbs$ $Config/LogSuccessEvent$</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>AD_DNS_Verification.vbs</Name>
<Contents><Script>
'*************************************************************************
' Script Name - AD DNS Verification
'
' Purpose - Verfies that AD is correctly configured for single level
' names.
'
' Parameters - LogSuccessEvent - True/False value to indicates to log an
' an event for script success
' (useful for demos and debugging)
'
' (c) Copyright 2004, 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

' Event ID Constants
Const EVENT_ID_INVALID_PARAM = 66
Const EVENT_ID_SCRIPT_ERROR = 1000
Const EVENT_ID_SUCCESS = 99
Const EVENT_ID_NOT_AN_EVENT = 2
Const EVENT_ID_AGENTLESS = 98
Const EVENT_ID_NODNSUPDATEFLAG = 72
Const EVENT_ID_DNSUPDATEFLAGOK = 28

' Other Constants
Const SCRIPT_NAME = "AD DNS Verification"
Const E_INVALIDARG = &amp;H80070057
Const ERROR_FILENOTFOUND = &amp;H80070002
Const REGKEY_W2K_UPDATETOPLEVELDOMAINZONES = "HKLM\SYSTEM\CurrentControlSet\Services\DnsCache\Parameters"
Const REGKEY_W2K3_UPDATETOPLEVELDOMAINZONES = "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient"

' TypedPropertyBag
const PerformanceDataType = 2
const StateDataType = 3

Class Error
Public Description
Public Number
Public Source

Sub Init(oErr)
Description = oErr.Description
Number = oErr.Number
Source = oErr.Source
End Sub

Sub Raise(strDescription)
Err.number = Number
Err.Description = Description
Err.Raise Number, Source, strDescription &amp; GetErrorString(Err)
End Sub
End Class

Dim oError
Set oError = new Error
On Error Resume Next

Dim oAPI, oBag
Set oAPI = CreateObject("Mom.ScriptAPI")
Err.Clear

Dim IsTargetAgentless, oParams, bLogSuccess
Set oParams = WScript.Arguments
if oParams.Count &lt; 1 Then
Wscript.quit -1
End if
bLogSuccess = CBool(oParams(0))'LogSuccessEvent

IsTargetAgentless= false

If Not(IsTargetAgentless) Then
Dim dtStart
dtStart = Now

DoDNSValidation
oAPI.ReturnItems
If Err &lt;&gt; 0 Then
CreateEvent EVENT_ID_SCRIPT_ERROR, _
EVENT_TYPE_WARNING, _
"An error occurred while executing '" &amp; SCRIPT_NAME &amp; "'" &amp; _
vbCrLf &amp; Err.Description &amp; vbCrLf &amp; "0x" &amp; Hex(Err.number)


ElseIf bLogSuccess = True Then
strMessage = "The script '" &amp; SCRIPT_NAME &amp; "' completed in " &amp; DateDiff("s", dtStart, Now) &amp; " seconds."
CreateEvent EVENT_ID_SUCCESS, EVENT_TYPE_INFORMATION, strMessage
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

Sub DoDNSValidation()
On Error Resume Next

' Create an instance of OOMADs
Dim oOOMADS, bIsOK
bIsOK=True
Set oOOMADs = CreateObject("McActiveDir.ActiveDirectory")
If Err &lt;&gt; 0 Then
oError.Init(Err)
On Error Goto 0
oError.Raise "Failed to CreateObject 'OOMADs'."
End If

Dim strDomain
strDomain = oOOMADS.GetDomainForDC(".")
If Err &lt;&gt; 0 Then
oError.Init(Err)
On Error Goto 0
oError.Raise "Failed to get DNS Domain Name."
End If
If Right(strDomain, 1) = "." Then
strDomain = Left(strDomain, Len(strDomain) - 1)
End If
If Instr(strDomain, ".") = 0 Then
' Got a single-level name. Check to see if we're W2K-SP4 or above
' and if so, check for the registry key.
Dim oOS, oReg, strValue
Set oReg = CreateObject("WScript.Shell")
If Err &lt;&gt; 0 Then
oError.Init(Err)
On Error Goto 0
oError.Raise "Failed to CreateObject 'WScript.Shell'."
End If
For Each oOS in GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")
If Err &lt;&gt; 0 Then
oError.Init(Err)
On Error Goto 0
oError.Raise "Failed to enumerate instances of 'Win32_OperatingSystem'."
End If
If CDbl(Left(oOS.Version, Len("5.1"))) = 5.1 Then
If oOS.ServicePackMajorVersion &gt;= 4 Then
strValue = oReg.RegRead(REGKEY_W2K_UPDATETOPLEVELDOMAINZONES)
If Err.number = 0 Or Err.number = ERROR_FILENOTFOUND Then
If strValue &lt;&gt; "1" Then
Set oBag = oAPI.CreateTypedPropertyBag(StateDataType)
oBag.AddValue "State", "BAD"
oBag.AddValue "EventID", "" &amp; EVENT_ID_NODNSUPDATEFLAG
oAPI.AddItem oBag

bIsOK=false
CreateEvent EVENT_ID_NODNSUPDATEFLAG, EVENT_TYPE_ERROR, "DNS registrations of essential Domain controller records is failing because the Active Directory Domain is a single label domain for Windows 2000 SP 4 and 2003."
End If
Else
CreateEvent EVENT_ID_SCRIPT_ERROR, EVENT_TYPE_WARNING, _
"The script '" &amp; SCRIPT_NAME &amp; "' " &amp; vbCrLf &amp; _
"failed to read the registry key '" &amp; REGKEY_W2K3_UPDATETOPLEVELDOMAINZONES &amp; _
"'. The error returned was " &amp; GetErrorString(Err)

End If
End If
ElseIf CDbl(Left(oOS.Version, Len("5.2"))) &gt;= 5.2 Then
strValue = oReg.RegRead(REGKEY_W2K3_UPDATETOPLEVELDOMAINZONES)
If Err.number = 0 Or Err.number = ERROR_FILENOTFOUND Then
If strValue &lt;&gt; "1" Then
Set oBag = oAPI.CreateTypedPropertyBag(StateDataType)
oBag.AddValue "State", "BAD"
oBag.AddValue "EventID", "" &amp; EVENT_ID_NODNSUPDATEFLAG
oAPI.AddItem oBag
bIsOK=false
CreateEvent EVENT_ID_NODNSUPDATEFLAG, EVENT_TYPE_ERROR, "DNS registrations of essential Domain controller records is failing because the Active Directory Domain is a single label domain for Windows 2000 SP 4 and 2003."
End If
Else
CreateEvent EVENT_ID_SCRIPT_ERROR, EVENT_TYPE_WARNING, _
"The script '" &amp; SCRIPT_NAME &amp; "' " &amp; vbCrLf &amp; _
"failed to read the registry key '" &amp; REGKEY_W2K3_UPDATETOPLEVELDOMAINZONES &amp; _
"'. The error returned was " &amp; GetErrorString(Err)
End If
End If
Exit For
Next
End If

If bIsOK = true Then
Set oBag = oAPI.CreateTypedPropertyBag(StateDataType)
oBag.AddValue "State", "GOOD"
oBag.AddValue "EventID", "" &amp; EVENT_ID_DNSUPDATEFLAGOK
oAPI.AddItem oBag
End If

End Sub

'******************************************************************************
Sub CreateEvent(lngEventID, lngEventType, strMessage)
'
' 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
'
oAPI.LogScriptEvent "AD DNS Verification", lngEventID, lngEventType, strMessage
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

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