Veritas.VCS.Script.DiscoveryProvider (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Default

Overrideable Parameters:

IDParameterTypeSelector
IntervalSecondsint$Config/IntervalSeconds$

Source Code:

<DataSourceModuleType ID="Veritas.VCS.Script.DiscoveryProvider" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Computer" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="VCSVersion" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>VCSScriptDiscovery.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Config/Computer$ $Config/VCSVersion$</Arguments>
<ScriptBody><Script>

Option Explicit

'Variables to be used for temp file handling, which will store MOMUtil output data.
Const WindowsFolder = 0
Const ForWriting = 2
Const ForReading = 1
Public MOMUTIL_TEMP_FILENAME
Public TEMP_FILE_DIRECTORY

'Variable to store handle for MOM script API
Dim oMOMScriptAPI

'Variables to store input arguments for script
Dim ArgSourceID, ArgManagedEntityId, ArgTargetComputer, ArgVCSVersion

'Call main function
Main()

'*********************************** Main Function **************************************
Function Main()

'Create and save handle for MOM script API
Set oMOMScriptAPI = CreateObject("MOM.ScriptAPI")

'########### Read and parse script arguments ############

Dim oScriptArgs
Set oScriptArgs = WScript.Arguments

'******* Check for the required script arguments. If the script is called without the required arguments,
' create an information event and SUBMIT EMPTY DATA and then quit.
if oScriptArgs.Count &lt; 4 Then
Call oMOMScriptAPI.LogScriptEvent("VCSScriptDiscovery.vbs",701,0,"VCSScriptDiscovery.vbs script was no executes because it was called with less than three arguments.")
SubmitEmptyDiscoveryDataToMomServer()
Wscript.Quit -1
End If

'******* Read script arguments
ArgSourceID = oScriptArgs(0) ' The GUID of the Discovery that launched the script.
ArgManagedEntityId = oScriptArgs(1) ' The GUID of the computer class targeted by the script.
ArgTargetComputer = oScriptArgs(2) ' The FQDN of the computer targeted by the script.
ArgVCSVersion = oScriptArgs(3)

Call oMOMScriptAPI.LogScriptEvent("VCSScriptDiscovery.vbs",702,0, "arguments are: " + ArgSourceID + " " + ArgManagedEntityId + " " + ArgTargetComputer )

'########### Call MOMUtil and save data to file ###########

'******* Execute Momutil
Dim objShell, objScriptExec, strVCSState
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec("%VCS_HOME%\Bin\MOMUtil.exe discover")
strVCSState = objScriptExec.StdOut.ReadAll


'******* Check for error or save mom util output to temp file
'Check if error in file,if some failure the submit empty discovery data
Dim objTextFile
If InStr (1, strVCSState, "error", 1) &gt; 0 Then
SubmitEmptyDiscoveryDataToMomServer()
Exit Function
Else
'Save data to temp file
Dim fso, wfolder
Set fso = CreateObject("Scripting.FileSystemObject")
Set wfolder = fso.GetSpecialFolder(WindowsFolder)
MOMUTIL_TEMP_FILENAME = "\\Temp\\StateDisc_" + ArgTargetComputer + ".txt"
TEMP_FILE_DIRECTORY = wfolder
Set objTextFile = fsO.OpenTextFile(TEMP_FILE_DIRECTORY &amp; MOMUTIL_TEMP_FILENAME, ForWriting, True)
objTextFile.WriteLine(strVCSState)
objTextFile.close
Call oMOMScriptAPI.LogScriptEvent("VCSScriptDiscovery.vbs",703,0, "Temp File location is: " + TEMP_FILE_DIRECTORY &amp; MOMUTIL_TEMP_FILENAME)
End If

'########## Call function to create discovery objects ##########
CreateVCSDiscoveryData()

End Function
'********************************* End Main Function ************************************

'************************* CreateVCSDiscoveryData Function *********************************
Function CreateVCSDiscoveryData()

'Call oMOMScriptAPI.LogScriptEvent("VCSScriptDiscovery.vbs",704,0, "CreateDiscoveryData is called." )

'Create discovery data object
Dim oDiscoveryData
Set oDiscoveryData = oMOMScriptAPI.CreateDiscoveryData(0, ArgSourceID, ArgManagedEntityId)

'################## Create servernode class instance ###################
'******* Create ServerNode class instance object
Dim oNodeClassInst
Set oNodeClassInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Veritas.VCS.ServerNode']$")

'******* Define the property values for servernode class instance and its base classes.
'It is must to set "Principal name" property of "Microsoft.Windows.Computer" class any custom class object
'Setting base class's key properties.
Call oNodeClassInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", ArgTargetComputer)
Call oNodeClassInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", ArgTargetComputer)
'Setting current (servernode) class properties.
Call oNodeClassInst.AddProperty("$MPElement[Name='Veritas.VCS.ServerNode']/ServerName$", ArgTargetComputer)
Call oNodeClassInst.AddProperty("$MPElement[Name='Veritas.VCS.ServerNode']/VCSVersion$", ArgVCSVersion)
Call oNodeClassInst.AddProperty("$MPElement[Name='Veritas.VCS.ServerNode']/NodeKeyProperty$", ArgTargetComputer)

'******* Add server node object to discovery data
Call oDiscoveryData.AddInstance(oNodeClassInst)


'################## Read First line from File and check for "End" ###################
'******* Open temp file
Dim objFSO, objTextFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(TEMP_FILE_DIRECTORY &amp; MOMUTIL_TEMP_FILENAME,ForReading, true)

'******* Read first line
Dim arrTokenListForLine
arrTokenListForLine = objTextFile.Readline
arrTokenListForLine = Split(arrTokenListForLine , ",")

'*******If first line is End then submit empty data
If ( StrComp(arrTokenListForLine(0),"End") = 0 ) Then
Call oMOMScriptAPI.Return(oDiscoveryData) 'or SubmitEmptyDiscoveryDataToMomServer(). Need to think
Exit Function
End if

'First line in file is not "End", it should be group, so parse the file to get SG and resources
'////Format of MOMUtil output////
'Group,PDTestSG1,PARTIAL,
'Resource,FileOnOff,FileOnOffRes,ONLINE
'Resource,FileOnOff,FileOnOffRes1,OFFLINE
'Group,PDTestSG2,ONLINE,PD-W2K8R2-YEB1
'Resource,FileOnOff,FileOnOffRes21,ONLINE
'Group,d,OFFLINE,
'Resource,GenericService,myres,OFFLINE
'End

'^^^^^^^^^^^^^^^^^^^^^^ while loop for Group ^^^^^^^^^^^^^^^^^^^^^^^^^^
Do While( StrComp(arrTokenListForLine(0),"Group") = 0)

'################## Create ServiceGroup class instance ###################
'*******create servicegroup class object
Dim oSGClassInst
Set oSGClassInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Veritas.VCS.ServiceGroup']$")

'******* Define the property values for ServiceGroup class instance and its base classes.
'It is must to set "Principal name" property (key property) of "Microsoft.Windows.Computer" class any custom class object
'Setting top most base class properties.
Call oSGClassInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", ArgTargetComputer)
'Setting base clas (ServerNode) key property
Call oSGClassInst.AddProperty("$MPElement[Name='Veritas.VCS.ServerNode']/NodeKeyProperty$", ArgTargetComputer)
'Setting current (ServiceGroup) class properties. KeyProperty here is: NodeName + SGName
Dim strSGName
strSGName = arrTokenListForLine(1)
Call oSGClassInst.AddProperty("$MPElement[Name='Veritas.VCS.ServiceGroup']/SGName$", strSGName)
Call oSGClassInst.AddProperty("$MPElement[Name='Veritas.VCS.ServiceGroup']/State$", arrTokenListForLine(2))
Call oSGClassInst.AddProperty("$MPElement[Name='Veritas.VCS.ServiceGroup']/SGKeyProperty$", ArgTargetComputer + "-" + strSGName)
Call oSGClassInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", strSGName)'used as instance name field in ui in detail view

'******* Add ServiceGroup object to discovery data
Call oDiscoveryData.AddInstance(oSGClassInst) 'shud we add if there is atleast one res. In this case need to add below while loop.

'Get next line which must be resource, and keep on creating resource object until we get next "group" or "End" line.
arrTokenListForLine = objTextFile.Readline
arrTokenListForLine = Split(arrTokenListForLine, ",")

'^^^^^^^^^^^^^^^^^^^^^^ Inner while loop for Resource^^^^^^^^^^^^^^^^^^^^^^^^^^
Do While( StrComp(arrTokenListForLine(0),"Resource") = 0)

'################## Create Resource class instance ###################
'******* create Resource class object
Dim oResourceClassInst
Set oResourceClassInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Veritas.VCS.Resource']$")

'******* Define the property values for Resource class instance and its base classes.
'It is must to set "Principal name" property (key property) of "Microsoft.Windows.Computer" class any custom class object
'Setting top most base class properties.
Call oResourceClassInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", ArgTargetComputer)
'Setting another base clas (ServerNode) key property
Call oResourceClassInst.AddProperty("$MPElement[Name='Veritas.VCS.ServerNode']/NodeKeyProperty$", ArgTargetComputer)
'Set immediate base class's property
Call oResourceClassInst.AddProperty("$MPElement[Name='Veritas.VCS.ServiceGroup']/SGKeyProperty$", ArgTargetComputer + "-" + strSGName)
'Setting current (Resource) class properties. KeyProperty here is: NodeName + SGName + ResName
Dim strResName
strResName = arrTokenListForLine(2)
Call oResourceClassInst.AddProperty("$MPElement[Name='Veritas.VCS.Resource']/ResourceName$", strResName)
Call oResourceClassInst.AddProperty("$MPElement[Name='Veritas.VCS.Resource']/SGName$", strSGName)
Call oResourceClassInst.AddProperty("$MPElement[Name='Veritas.VCS.Resource']/State$", arrTokenListForLine(3))
Call oResourceClassInst.AddProperty("$MPElement[Name='Veritas.VCS.Resource']/ResKeyProperty$", ArgTargetComputer + "-" + strSGName + "-" + strResName)
Call oResourceClassInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", strResName)

'******* Add ServiceGroup object to discovery data
Call oDiscoveryData.AddInstance(oResourceClassInst)

'Get next line which can be "resource", "Group" or "End",
'This loop will continue to create resource objects, if its resource.
'If its group this inner loop will exit, and then oujter loop will create group object.
'If its an "End" line then both loops will exit.
arrTokenListForLine = objTextFile.Readline
arrTokenListForLine = Split(arrTokenListForLine , ",")

Loop
'^^^^^^^^^^^^^^^^^^^ End of while loop for Resource^^^^^^^^^^^^^^^^^^^^^^^^^^

Loop
'^^^^^^^^^^^^^^^^^^^ End of while loop for Group^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

'################### Submit discovery data for processing ####################
Call oMOMScriptAPI.Return(oDiscoveryData)

End Function
'*********************** End CreateVCSDiscoveryData Function *******************************

'******************* SubmitEmptyDiscoveryDataToMomServer Function ***********************
Function SubmitEmptyDiscoveryDataToMomServer()
'This function will create only server node object.

Call oMOMScriptAPI.LogScriptEvent("VCSScriptDiscovery.vbs",115,0, "SubmitEmptyDiscoveryDataToMomServer is called." )
Dim oDiscoveryData
Set oDiscoveryData = oMOMScriptAPI.CreateDiscoveryData(0, ArgSourceID, ArgManagedEntityId)

'################## Create servernode class instance ###################
'******* Create ServerNode class instance object
Dim oNodeClassInst
Set oNodeClassInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Veritas.VCS.ServerNode']$")

'******* Define the property values for servernode class instance and its base classes.
'It is must to set "Principal name" property of "Microsoft.Windows.Computer" class any custom class object
'Setting base class's key properties.
Call oNodeClassInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", ArgTargetComputer)
Call oNodeClassInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", ArgTargetComputer)
'Setting current (servernode) class properties.
Call oNodeClassInst.AddProperty("$MPElement[Name='Veritas.VCS.ServerNode']/ServerName$", ArgTargetComputer)
Call oNodeClassInst.AddProperty("$MPElement[Name='Veritas.VCS.ServerNode']/VCSVersion$", ArgVCSVersion)
Call oNodeClassInst.AddProperty("$MPElement[Name='Veritas.VCS.ServerNode']/NodeKeyProperty$", ArgTargetComputer)

'******* Add server node object to discovery data
Call oDiscoveryData.AddInstance(oNodeClassInst)

' Submit the empty discovery data for processing.
Call oMOMScriptAPI.Return(oDiscoveryData)

End Function
'******************* End SubmitEmptyDiscoveryDataToMomServer Function *******************
</Script></ScriptBody>
<TimeoutSeconds>180</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>