Megosztott fürtkötet parancsprogram-adatforrása

Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.ClusterSharedVolume.Discovery.ScriptDataSource (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.CommandExecuterDiscoveryDataSource Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Időköz
LogSuccessEventbool$Config/LogSuccessEvent$Sikert jelző esemény naplózása
ScriptGroupIdstring$Config/ScriptGroupId$Eseménynapló forrása
TimeoutSecondsint$Config/TimeoutSeconds$Időtúllépés

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.ClusterSharedVolume.Discovery.ScriptDataSource" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="LogSuccessEvent" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ScriptGroupId" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="MPElementID" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TargetID" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TargetComputer" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ClusterName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="LogSuccessEvent" Selector="$Config/LogSuccessEvent$" ParameterType="bool"/>
<OverrideableParameter ID="ScriptGroupId" Selector="$Config/ScriptGroupId$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.CommandExecuterDiscoveryDataSource">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<ApplicationName>%windir%\System32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>$file/Microsoft.Windows.Server.CSV.DiscoverClusterSharedVolume.vbs$ $Config/LogSuccessEvent$ "$Config/ScriptGroupId$" "$Config/MPElementID$" "$Config/TargetID$" "$Config/TargetComputer$" "$Config/ClusterName$"</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>Microsoft.Windows.Server.CSV.DiscoverClusterSharedVolume.vbs</Name>
<Contents><Script>
Option Explicit
Const SCRIPT_VERSION = "1.01"
Const LOG_SUCCESS_EVENT_PARAMETER_NAME = "LogSuccessEvent"
Const MP_ELEMENT_PARAMETER_NAME = "MP Element"
Const MANAGED_ENTITY_ID_PARAMETER_NAME = "Managed Entity"
Const TARGET_COMPUTER_PARAMETER_NAME = "Target Computer"
Const CLUSTER_NAME_PARAMETER_NAME = "Cluster Name"

'WMI constants
Const WMI_MSCLUSTER_NAMESPACE = "root\MSCluster"
Const WMI_CIMV2_NAMESPACE = "root\cimv2"
Const WMI_MSCLUSTER_CLUSTER_SHARED_VOLUME = "MSCluster_ClusterSharedVolume"
Const WMI_CLUSTER_SHARED_VOLUME_TO_PARTITION_ASSOCIATOR_CLASS = "MSCluster_ClusterSharedVolumeToPartition"
Const WMI_CLUSTER_SHARED_VOLUME_TO_RESOURCE_ASSOCIATOR_CLASS = "MSCluster_ClusterSharedVolumeToResource"

Const WMI_MSCLUSTER_CLUSTER_CLASS = "MSCluster_Cluster"
Const WMI_NAME_PROPERTY_NAME = "Name"
Const WMI_PATH_PROPERTY_NAME = "Path"
Const WMI_FILESYSTEM_PROPERTY_NAME = "FileSystem"
Const WMI_TOTALSIZE_PROPERTY_NAME = "TotalSize"
Const WMI_VOLUMELABEL_PROPERTY_NAME = "VolumeLabel"


'State property bag constants
Const STATE_PROPERTY_NAME = "State"
Const STATE_DESCRIPTION_NAME = "Description"
Const STATE_PARTITION_FS_GOOD = "FSGOOD"
Const STATE_PARTITION_FS_WARNING = "FSWARNING"
Const STATE_PARTITION_FS_BAD = "FSBAD"
Const STATE_DIRTY_BIT_GOOD = "DBGOOD"
Const STATE_DIRTY_BIT_BAD = "DBBAD"

'State property bag constants

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

Const EVENT_ID_SUCCESS = 1000 'Use IDs in the range 1 - 1000
Const EVENT_ID_SCRIPTERROR = 999 'Then you can use eventcreate.exe to test the MP

'Scripting.FileSystemObject constants
Const FOR_READING = 1 'Open a file for reading only. You can't write to this file.
Const FOR_WRITING = 2 'Open a file for writing.
Const FOR_APPENDING = 8 'Open a file and write to the end of the file.
Const SCRIPT_SUCCESS = 0
Const SCRIPT_WITH_ERROR = 1

'Global vars
Dim mblnLogSuccessEvent 'As Boolean
Dim mstrIdentifier 'As String
On Error Resume Next

Call Main

'*********************************************************************************************
' PROCEDURE: Main
' DESCRIPTION: Reads the script parameters and creates the cluster shared volume discovery data.
' PARAMETERS: void
'*********************************************************************************************
Private Sub Main()

' Targeted at Microsoft.Windows.Cluster.VirtualServer (based on Microsoft.Windows.Server.Computer)
Dim objFSO 'As Scripting.FileSystemObject
Dim strSourceID 'As String '= oArgs(4). strSourceId is the GUID of the discovery object that runs the script (MPElement).
Dim strManagedEntityId 'As String '= oArgs(5) - strManagedEntityId is the GUID of the computer class that is targeted by the script (Target/Id).
Dim strTargetComputer 'As String '= oArgs(6)
Dim strClusterName 'As String '= oArgs(7)
Dim objMomScriptAPI 'As MOM.ScriptAPI
Dim objDiscoveryData 'As DiscoveryData
Dim intSuccess 'As Integer

Call SetLocale("en-us")

Set objMomScriptAPI = CreateObject("MOM.ScriptAPI")
If Not GetScriptParameters(strSourceID, strManagedEntityId, strTargetComputer, strClusterName) Then
' If the script is called without the required arguments,
' create an information event and then quit.
Call objMomScriptAPI.LogScriptEvent("-- Cluster Shared Volumes Discovery Script -- " &amp; vbCr &amp; vbLf &amp; vbCr &amp; vbLf &amp; "Script name: " &amp; WScript.ScriptName &amp; vbCr &amp; vbLf &amp; "Version: " &amp; SCRIPT_VERSION &amp; vbCr &amp; vbLf, EVENT_ID_SCRIPTERROR, EVENT_TYPE_WARNING, _
vbCr &amp; vbLf &amp; "The script was called with fewer than six arguments or the arguments could not be parsed.")
WScript.Quit -1
End If

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Create new discovery data object
Set objDiscoveryData = objMomScriptAPI.CreateDiscoveryData(0, strSourceID, strManagedEntityId)

'Discover instances
intSuccess = DiscoverClusterSharedVolumes(strTargetComputer, strClusterName, objDiscoveryData)

If intSuccess = SCRIPT_SUCCESS Then
If mblnLogSuccessEvent Then
Call objMomScriptAPI.LogScriptEvent("-- Cluster Shared Volumes Discovery Script -- " &amp; vbCr &amp; vbLf &amp; vbCr &amp; vbLf &amp; "Script name: " &amp; WScript.ScriptName &amp; vbCr &amp; vbLf &amp; "Version: " &amp; SCRIPT_VERSION &amp; _
vbCr &amp; vbLf, EVENT_ID_SUCCESS, EVENT_TYPE_INFORMATION, vbCr &amp; vbLf &amp; "Script executed successfully.")
End If

'Return discovery data
Call objMomScriptAPI.Return(objDiscoveryData)
Else
Call objMomScriptAPI.LogScriptEvent("-- Cluster Shared Volumes Discovery Script -- " &amp; vbCr &amp; vbLf &amp; vbCr &amp; vbLf &amp; "Script name: " &amp; WScript.ScriptName &amp; vbCr &amp; vbLf &amp; "Version: " &amp; SCRIPT_VERSION &amp; vbCr &amp; vbLf, EVENT_ID_SUCCESS, EVENT_TYPE_INFORMATION, _
vbCr &amp; vbLf &amp; "An error occurred while running the script.")
End If
End Sub

'****************************************************************************************************************
' FUNCTION: DiscoverClusterSharedVolumes
' DESCRIPTION: Discover instances of the class 'Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.ClusterSharedVolume' using WMI.
' PARAMETERS: IN String strTargetComputer: principal name of the targeted 'Microsoft.Windows.Cluster.VirtualServer' instance.
' IN String strClusterName: the cluster containing the cluster shared volume
' OUT Object objDiscoveryData: initialised DiscoveryData instance
' RETURNS: Integer: 0 if successful and 1 if fails
'****************************************************************************************************************
Private Function DiscoverClusterSharedVolumes(ByRef strTargetComputer, ByRef strClusterName, ByRef objDiscoveryData) 'As Integer
Dim objMSClusterSWbemServices 'As SWbemServices
Dim objClusterSharedVolumes 'As SWbemObjectSet
Dim objClusterSharedVolume 'As SWbemObject
Dim objClusterDiskPartition 'As SWbemObject
Dim objClusterResource 'As SWbemObject
Dim intSuc 'As Integer
Dim blnCreateDiscoveryData
blnCreateDiscoveryData = false

'Connect to WMI NS \\.\root\MSCluster
If ConnectToWbemNS(".", WMI_MSCLUSTER_NAMESPACE, objMSClusterSWbemServices) Then

If InStr(strTargetComputer, ".") &gt; 0 Then
If LCase(Left(strTargetComputer, InStr(strTargetComputer, ".") - 1)) = LCase(strClusterName) Then blnCreateDiscoveryData = True
Else
If LCase(strTargetComputer) = LCase(strClusterName) Then blnCreateDiscoveryData = True
End If

If blnCreateDiscoveryData = true Then
Set objClusterSharedVolumes = objMSClusterSWbemServices.ExecQuery("select * from " &amp; WMI_MSCLUSTER_CLUSTER_SHARED_VOLUME)

If Err.number &lt;&gt; 0 Then
DiscoverClusterSharedVolumes = SCRIPT_WITH_ERROR
Exit Function
End If

on error goto 0

'Loop through all returned cluster shared volumes
For Each objClusterSharedVolume In objClusterSharedVolumes

'Get the associated disk partition
For Each objClusterDiskPartition In objClusterSharedVolume.Associators_(WMI_CLUSTER_SHARED_VOLUME_TO_PARTITION_ASSOCIATOR_CLASS, "", "", "", False, False, "", "", 0)
'Get the associated resource
For Each objClusterResource In objClusterSharedVolume.Associators_(WMI_CLUSTER_SHARED_VOLUME_TO_RESOURCE_ASSOCIATOR_CLASS, "", "", "", False, False, "", "", 0)
intSuc = CreateDiscoveryData(objClusterSharedVolume, objClusterDiskPartition, objClusterResource, _
strTargetComputer, strClusterName, objDiscoveryData)
Next 'objClusterResource
Next 'objClusterDiskPartition

If Err.number &lt;&gt; 0 Then
DiscoverClusterSharedVolumes = SCRIPT_WITH_ERROR
Exit Function
End If

on error goto 0
Next 'objClusterSharedVolume
DiscoverClusterSharedVolumes = intSuc
Else
DiscoverClusterSharedVolumes = SCRIPT_SUCCESS
End If
Else
End If

End Function

'****************************************************************************************************************
' FUNCTION: CreateDiscoveryData
' DESCRIPTION: Create discovery data for
' &lt;ClassType ID="Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.ClusterSharedVolume" Accessibility="Internal" Abstract="false" Base="Windows!Microsoft.Windows.ApplicationComponent" Hosted="true" Singleton="false"&gt;
' &lt;Property ID="ClusterSharedVolumeName" Type="string" Key="true" CaseSensitive="false" Length="256" MinLength="0" /&gt;
' &lt;Property ID="FriendlyVolumeName" Type="string" Key="false" CaseSensitive="false" Length="256" MinLength="0" /&gt;
' &lt;Property ID="PartitionName" Type="string" Key="false" CaseSensitive="false" Length="256" MinLength="0" /&gt;
' &lt;Property ID="PartitionFileSystem" Type="string" Key="false" CaseSensitive="false" Length="256" MinLength="0" /&gt;
' &lt;Property ID="PartitionSize" Type="int" Key="false" /&gt;
' &lt;Property ID="ClusterName" Type="string" Key="false" CaseSensitive="false" Length="256" MinLength="0" /&gt;
' &lt;Property ID="VolumeLabel" Type="string" Key="false" CaseSensitive="false" Length="256" MinLength="0" /&gt;
' &lt;/ClassType&gt;
'
' PARAMETERS: IN Object objClusterSharedVolume: the cluster shared volume as SWbemObject of type MSCluster_ClusterSharedVolume.
' IN Object objClusterDiskPartition: the associated disk partition as SWbemObject of type MSCluster_DiskPartition.
' IN Object objClusterResource: the associated cluster resource as SWbemObject of type MSCluster_Resource.
' IN String strTargetComputer: the principal name of the targeted cluster virtual server hosting the cluster shared volume,
' i.e. the cluster name and not the current owner!
' IN String strClusterName: the cluster containing the cluster shared volume
' OUT Object objDiscoveryData: initialised DiscoveryData instance
' RETURNS: Integer: 0 if successful or 1 if Error
'****************************************************************************************************************
Private Function CreateDiscoveryData(ByRef objClusterSharedVolume, ByRef objClusterDiskPartition, ByRef objClusterResource, _
ByRef strTargetComputer, ByRef strClusterName, ByRef objDiscoveryData) 'As Integer
Dim objCSVInstance 'As MOMClassInstance

'Create the cluster shared volume instance hosted on the targeted cluster virtual server
Set objCSVInstance = objDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.ClusterSharedVolume']$")

'PrincipalName (host, key)
Call objCSVInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", strTargetComputer)

'ClusterSharedVolumeName (key)
Call objCSVInstance.AddProperty("$MPElement[Name='Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.ClusterSharedVolume']/ClusterSharedVolumeName$", objClusterResource.Properties_(WMI_NAME_PROPERTY_NAME))

If Err.number &lt;&gt; 0 Then
CreateDiscoveryData = SCRIPT_WITH_ERROR
Exit Function
End If

on error goto 0

'FriendlyVolumeName
Call objCSVInstance.AddProperty("$MPElement[Name='Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.ClusterSharedVolume']/FriendlyVolumeName$", objClusterSharedVolume.Properties_(WMI_NAME_PROPERTY_NAME))

If Err.number &lt;&gt; 0 Then
CreateDiscoveryData = SCRIPT_WITH_ERROR
Exit Function
End If

on error goto 0

'PartitionName
Call objCSVInstance.AddProperty("$MPElement[Name='Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.ClusterSharedVolume']/PartitionName$", objClusterDiskPartition.Properties_(WMI_PATH_PROPERTY_NAME))

If Err.number &lt;&gt; 0 Then
CreateDiscoveryData = SCRIPT_WITH_ERROR
Exit Function
End If

on error goto 0

'PartitionFileSystem
Call objCSVInstance.AddProperty("$MPElement[Name='Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.ClusterSharedVolume']/PartitionFileSystem$", objClusterDiskPartition.Properties_(WMI_FILESYSTEM_PROPERTY_NAME))

If Err.number &lt;&gt; 0 Then
CreateDiscoveryData = SCRIPT_WITH_ERROR
Exit Function
End If

on error goto 0

'PartitionSize
Call objCSVInstance.AddProperty("$MPElement[Name='Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.ClusterSharedVolume']/PartitionSize$", objClusterDiskPartition.Properties_(WMI_TOTALSIZE_PROPERTY_NAME))

If Err.number &lt;&gt; 0 Then
CreateDiscoveryData = SCRIPT_WITH_ERROR
Exit Function
End If

on error goto 0

'ClusterName
Call objCSVInstance.AddProperty("$MPElement[Name='Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.ClusterSharedVolume']/ClusterName$", strClusterName)

'VolumeLabel
Call objCSVInstance.AddProperty("$MPElement[Name='Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.ClusterSharedVolume']/VolumeLabel$", objClusterDiskPartition.Properties_(WMI_VOLUMELABEL_PROPERTY_NAME))

If Err.number &lt;&gt; 0 Then
CreateDiscoveryData = SCRIPT_WITH_ERROR
Exit Function
End If

on error goto 0

Call objDiscoveryData.AddInstance(objCSVInstance)

CreateDiscoveryData = SCRIPT_SUCCESS

End Function

'******************************************************************************
' FUNCTION: GetScriptParameters
' DESCRIPTION: Reads the script's parameters
' and sets the global variables.
'
' PARAMETERS: OUT String strSourceID: Id of MP element ($MPElement$)
' OUT String strManagedEntityId: Id of targeted entity ($Target/Id$)
' OUT String strTargetComputer: Principal name of executing computer
' (-Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName-)
' OUT String strClusterName: Cluster name
' RETURNS: Boolean: True if successful
'******************************************************************************
Private Function GetScriptParameters(ByRef strSourceID, ByRef strManagedEntityId, ByRef strTargetComputer, ByRef strClusterName) 'As Boolean

Dim objArguments

On Error Resume Next

'cmdline: &lt;script&gt; True|False &lt;path to debug log&gt; True|False &lt;script id&gt; .MPElement. .Target/Id. .Target/Host/Property[Name="Windows!Microsoft.Windows.Computer"]/PrincipalName.
Set objArguments = WScript.Arguments
If objArguments.Count &lt; 6 Then Exit Function

'Get parameters and set global variables
mblnLogSuccessEvent = CBool(objArguments(0))
mstrIdentifier = Replace(objArguments(1), Chr(34), "")
strSourceID = Replace(objArguments(2), Chr(34), "")
strManagedEntityId = Replace(objArguments(3), Chr(34), "")
strTargetComputer = Replace(objArguments(4), Chr(34), "")
strClusterName = Replace(objArguments(5), Chr(34), "")

If Len(strSourceID) &gt; 0 And Len(strManagedEntityId) &gt; 0 And Len(strTargetComputer) &gt; 0 And Len(strClusterName) &gt; 0 Then GetScriptParameters = True

End Function

'******************************************************************************
' FUNCTION: ConnectToWbemNs
' DESCRIPTION: Connects to a WMI namespace
' PARAMETERS: IN String strServerName: name of the computer. If empty the local computer will be used.
' IN String strNameSpace: WMI namespace
' OUT Object objSWbemServices: WbemScripting.SWbemServices object connected to the given
' namespace on the given server
' RETURNS: Boolean: True if successful
'******************************************************************************
Private Function ConnectToWbemNS(ByRef strServerName, ByRef strNameSpace, ByRef objSWbemServices) 'As Boolean

Dim objSWbemLocator 'as WbemScripting.SWbemLocator

'Create a new WMI Locator object
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

'Connect to WMI namespace on strServerName computer and create WMI Services object
Set objSWbemServices = objSWbemLocator.ConnectServer(strServerName, strNameSpace)

'Connect to WMI namespace on strServerName computer with alternative credentials and create WMI Services object
'Set objSWbemServices = objSWbemLocator.ConnectServer(strServerName, strNameSpace, strUserName, strPassWd)

'If object is initialised function will be successful
If objSWbemServices Is Nothing Then ConnectToWbemNS = False Else ConnectToWbemNS = True

End Function
</Script></Contents>
</File>
</Files>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>