Discover the list of resources of a Backward Compatibility Virtual Server

System.Mom.BackwardCompatibility.Computer.VirtualServerType.Discovery (Discovery)

Element properties:

TargetMicrosoft.Windows.Server.Computer
EnabledTrue
Frequency900
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:

Member Modules:

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

Source Code:

<Discovery ID="System.Mom.BackwardCompatibility.Computer.VirtualServerType.Discovery" Enabled="true" Target="Windows!Microsoft.Windows.Server.Computer">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="System.Mom.BackwardCompatibility.Computer">
<Property PropertyID="Virtual_Server_Type"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>900</IntervalSeconds>
<SyncTime/>
<ScriptName>DiscoverVirtualServerType.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$ $Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetbiosComputerName$ $Target/Property[Type="Windows!Microsoft.Windows.Server.Computer"]/IsVirtualNode$</Arguments>
<ScriptBody><Script>
' Copyright (c) Microsoft Corporation. All rights reserved.
' Discover values for IsHostingMSCS and Virutal_Server_Type properties in the
' System.Mom.BackwardCompatibility MP
' Targeted at Windows Server class - takes 4 or 5 arguments
' Works agentlessly and against Virtual servers (Wolfpack cluster)
'
'
' Arguments:
' Arg 0 : SourceID
' Arg 1 : MP Element ID
' Arg 2 : Computer ID
' Arg 3 : FQDN
' Arg 4 : NETBIOS Name (required for clustered SQL discovery)
'
'
'variables
Dim SourceID
Dim ManagedEntityID
Dim TargetComputer
Dim TargetComputerNetbios
Dim IsVirtualNode

Call Main

Sub Main()

'process arguments
Dim oParams
Set oParams = WScript.Arguments

If oParams.Count = 3 Then
WScript.Echo "NetbiosComputerName property has not been discovered yet, the script will ignore this and do discovery in the next interval!"
Wscript.Quit
End If

If not (oParams.Count = 4 or oParams.Count =5) Then
ThrowScriptError "Invalid arguments specified.", null
WScript.Quit
End If

'set arguments
SourceID = oParams(0)
ManagedEntityId = oParams(1)
TargetComputer = oParams(2)
TargetComputerNetbios = oParams(3)

If oParams.Count = 5 Then
IsVirtualNode = oParams(4)
Else
IsVirtualNode = "false"
End If

If IsVirtualNode = "false" Then
SubmitDiscoveryData ""
WScript.Quit
End If

'Create Cluster Object
Dim oCluster
On Error Resume Next
Set oCluster = MomCreateObject("MSCluster.Cluster")
On Error Goto 0

'Cluster object creation failed
If IsEmpty(oCluster) Then
SubmitDiscoveryData ""
WScript.Quit
End If

'Define Error Object
On Error Resume Next
'Open cluster node
oCluster.Open TargetComputer

'handle Error
If Err.Number = 70 Then
ThrowScriptError "The MOM action account does not have permission to access the MS Cluster Service", Err
ElseIf Err.Number &lt;&gt; 0 Then
ThrowScriptError "Unable to connect to cluster service. The cluster service may not be running. Please investigate.", Err
End If
On Error Goto 0

'Open Resource Group
Dim oResourceGroup
Set oResourceGroup = GetResourceGroupForVirtualServer(oCluster, TargetComputerNetbios)

'build Resource string
Dim sVirtualServerType
If IsValidObject(oResourceGroup) Then
Dim oResource
Dim sServiceName

For Each oResource In oResourceGroup.Resources
Select Case oResource.TypeName
Case "IP Address", "Physical Disk", "Network Name"
sServiceName = ""
Case "Generic Service"
sServiceName = oResource.PrivateProperties("ServiceName")
Case Else
sServiceName = oResource.TypeName
End Select

If sServiceName &lt;&gt; "" Then
If sVirtualServerType &lt;&gt; "" Then sVirtualServerType = sVirtualServerType &amp; ","
sVirtualServerType = sVirtualServerType &amp; sServiceName
End If

Next
End If

If sVirtualServerType = "" Then sVirtualServerType = "Unmatched server cluster type"

'Submit Discovery data
SubmitDiscoveryData sVirtualServerType
End Sub

Function GetResourceGroupForVirtualServer(ByVal oCluster, ByVal sVirtualServerName)
Set GetResourceGroupForVirtualServer = Nothing
Dim oResource
For Each oResource In oCluster.ResourceTypes.Item("Network Name").Resources
If StrComp(oResource.PrivateProperties("Name"), sVirtualServerName, vbTextCompare) = 0 Then
Set GetResourceGroupForVirtualServer = oResource.Group
Exit Function
End If
Next
End Function

Function SubmitDiscoveryData(ByVal sVirtualServerType)
Dim oAPI, oDiscoveryData

Set oAPI = CreateObject("MOM.ScriptAPI")
set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)

Dim oInstance
Set oInstance = oDiscoveryData.CreateClassInstance("$MPElement[Name='System.Mom.BackwardCompatibility.Computer']$")

With oInstance
.AddProperty "$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer
.AddProperty "$MPElement[Name='System.Mom.BackwardCompatibility.Computer']/Virtual_Server_Type$", sVirtualServerType
End With

oDiscoveryData.AddInstance(oInstance)
oAPI.Return(oDiscoveryData)
End Function


'******************************************************************************
Function ThrowScriptError(Byval sMessage, ByVal oErr)
'
' ThrowScriptError :: Creates an event and sends it back to the mom server
'
'
Dim iErrNum
iErrNum = 1
If not IsNull(oErr) Then
oErrNum = oErr.Number
sMessage = sMessage &amp; oErr.Description
End If

' Calling this externally due to Err.Raise's poor handling of ByRef Variants
Dim raiseError
raiseError = "Err.Raise " &amp; iErrNum &amp; ", ""DiscoverVirtualServerType"", """ &amp; sMessage &amp; """"
Execute raiseError

End Function


'******************************************************************************
Function ThrowScriptErrorNoAbort(Byval sMessage, ByVal oErr)
'
' ThrowScriptError :: Creates an event and sends it back to the mom server
'
'
On Error Resume Next

ThrowScriptError sMessage, oErr
Wscript.echo Err.Description
Err.Clear

On Error Goto 0

End Function


'******************************************************************************
Function MomCreateObject(ByVal sProgramId)

On Error Resume Next
Set MomCreateObject = CreateObject(sProgramId)

If Err.Number &lt;&gt; 0 Then ThrowScriptErrorNoAbort "Unable to create automation object '" &amp; sProgramId &amp; "'. Error Number: " &amp; Err.number &amp; ", Message: " &amp; Err.Description
On Error Goto 0
End Function

'******************************************************************************
Function IsValidObject(ByVal oObject)
IsValidObject = False

If IsObject(oObject) Then
If Not oObject Is Nothing Then
IsValidObject = True
End If
End If
End Function

</Script></ScriptBody>
<TimeoutSeconds>120</TimeoutSeconds>
<EventPolicy>
<StdOutMatches/>
<StdErrMatches/>
</EventPolicy>
</DataSource>
</Discovery>