Set sh = CreateObject("WScript.Shell")
host0 = sh.RegRead ("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname")
var0 = sh.RegRead ("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Domain")
If Len(var0) > 0 Then host0 = host0 & "." & var0
sDebugMsg = sDebugMsg & host0 & ", " & sourceKey0
Set wmi = GetObject("winmgmts:\\.\root\cimv2")
Set oDoc = CreateObject("Microsoft.XMLDOM")
Set nodeList = Nothing
Set vRoot = Nothing
keys = Split(sourceKey0, ":")
On Error Resume Next
If UBound(keys) = 0 Then
var0 = sh.RegRead ("HKLM\SYSTEM\CurrentControlSet\services\" & sourceKey0 & "\VblocksData")
Call oDoc.load(var0)
Set nodelist = oDoc.documentElement.SelectNodes("/*/vblock")
bDebug = sh.RegRead ("HKLM\SYSTEM\CurrentControlSet\services\" & sourceKey0 & "\mpDebug")
Else
Set svcItems = wmi.ExecQuery("SELECT * FROM Win32_Service WHERE Name LIKE 'VCEProxy_%'")
For Each svcItem in svcItems
var0 = sh.RegRead ("HKLM\SYSTEM\CurrentControlSet\services\" & svcItem.Name & "\VblocksData")
Call oDoc.load(var0)
Set vRoot = oDoc.documentElement.SelectSingleNode("/*/vblock[./moId='" & keys(0) &"']")
If Not vRoot Is Nothing Then
Dim vce2scomNodeList, vce2scomNode, vce2scomAttrNodeList, vce2scomAttrNode, vtype, attrList
Set vce2scomNodeList = oDoc.documentElement.SelectNodes("//vce2scom/genericComponent")
For Each vce2scomNode In vce2scomNodeList
vtype = vce2scomNode.SelectSingleNode("./@type").Text
If Not dct.Exists(vtype & ".type") Then
Call dct.Add(vtype & ".type", "$MPElement[Name='VCE.Vision.Monitoring.Class.VblockGenericComponent']$")
Call dct.Add(vtype & ".rel", "$MPElement[Name='VCE.Vision.Monitoring.Relationship.VblockBaseContainsVblockGenericComponent']$")
End If
attrList = ""
Set vce2scomAttrNodeList = vce2scomNode.SelectNodes("./includeAttribute")
For Each vce2scomAttrNode In vce2scomAttrNodeList
attrList = attrList & "|./" & vce2scomAttrNode.Text
Next
If attrList <> "" Then
Call dct.Add(vtype & ".attr0","$MPElement[Name='VCE.Vision.Monitoring.Class.VblockGenericComponent']/sourceData$" & attrList)
End If
Next
sVblockId = vRoot.SelectSingleNode("./moId").Text
Set nodelist = oDoc.documentElement.SelectNodes("/*/*[./associatedObject/dbId='" & keys(1) & "']")
bDebug = sh.RegRead ("HKLM\SYSTEM\CurrentControlSet\services\" & svcItem.Name & "\mpDebug")
Exit For
End If
Next
End If
On Error GoTo 0 'restores VBS error trapping
End Sub
Sub AddPropertiesByNode(oInst, xnode, hash)
Dim attrName, attrNode, attrVal, xPath, tmpVar, tmpArray, clsArray(2), i, j
clsArray(0) = "vblockbase"
clsArray(1) = xnode.NodeName
For i = 0 To UBound(clsArray)
If hash.Exists(clsArray(i) & ".attr0") Then
tmpVar = hash.item(clsArray(i) & ".attr0")
tmpArray = Split(tmpVar, "|")
attrName = tmpArray(0)
attrVal = ""
For j = 1 To UBound(tmpArray)
xPath = tmpArray(j)
Set attrNode = xnode.SelectSingleNode(xPath)
If Not attrNode Is Nothing Then
attrVal = attrVal & Mid(xPath,3) & "=" & attrNode.Text & ";" & vbNewLine
End If
Next
Call oInst.AddProperty(attrName, Trim(attrVal))
End If
For j = 1 To 100
tmpVar = hash.item(clsArray(i) & ".attr" & j)
If tmpVar = "" Then Exit For
Set attrNode = xnode.SelectSingleNode(xPath)
If Not attrNode Is Nothing Then
attrVal = Trim(attrNode.Text)
If Len(attrVal) > 0 Then
Call oInst.AddProperty(attrName, attrVal)
End If
End If
Next
Next
End Sub
Sub AddComputeServerProperties(oInst, dbId)
Dim rootNode : Set rootNode = oDoc.documentElement
Dim numOfMemoryUnit, numOfProcessor
numOfMemoryUnit = rootNode.SelectNodes("/*/memoryunit[./associatedObject/dbId='" & dbId & "']").length
If numOfMemoryUnit > 0 Then
Call oInst.AddProperty("$MPElement[Name='VCE.Vision.Monitoring.Class.VblockComputeServer']/numOfMemoryUnit$", numOfMemoryUnit)
Call oInst.AddProperty("$MPElement[Name='VCE.Vision.Monitoring.Class.VblockComputeServer']/capacityPerMemoryUnit$", _
rootNode.SelectSingleNode("/*/memoryunit[./associatedObject/dbId='" & dbId & "']/capacity").Text)
Call oInst.AddProperty("$MPElement[Name='VCE.Vision.Monitoring.Class.VblockComputeServer']/memoryClock$", _
rootNode.SelectSingleNode("/*/memoryunit[./associatedObject/dbId='" & dbId & "']/clock").Text)
End If
numOfProcessor = rootNode.SelectNodes("/*/processorunit[./associatedObject/dbId='" & dbId & "']").length
If numOfProcessor > 0 Then
Call oInst.AddProperty("$MPElement[Name='VCE.Vision.Monitoring.Class.VblockComputeServer']/numOfProcessor$", numOfProcessor)
Call oInst.AddProperty("$MPElement[Name='VCE.Vision.Monitoring.Class.VblockComputeServer']/coresPerProcessor$", _
rootNode.SelectSingleNode("/*/processorunit[./associatedObject/dbId='" & dbId & "']/cores").Text)
Call oInst.AddProperty("$MPElement[Name='VCE.Vision.Monitoring.Class.VblockComputeServer']/cpuSpeed$", _
rootNode.SelectSingleNode("/*/processorunit[./associatedObject/dbId='" & dbId & "']/speed").Text)
Call oInst.AddProperty("$MPElement[Name='VCE.Vision.Monitoring.Class.VblockComputeServer']/cpuModel$", _
rootNode.SelectSingleNode("/*/processorunit[./associatedObject/dbId='" & dbId & "']/modelName").Text)
End If
End Sub
Function GetInstanceName(xnode)
Dim xtext : xtext = xnode.SelectSingleNode("./name").Text
If xtext = "" Then
xtext = xnode.SelectSingleNode("./alias").Text
End If
If xtext = "" Then
xtext = xnode.SelectSingleNode("./description").Text
End If
If xtext = "" Then
xtext = xnode.NodeName
End If
GetInstanceName = xtext
End Function
Sub AssignHealthService(oInst0, oHealthServiceInst)
Dim oShouldManageInst
Set oShouldManageInst = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthServiceShouldManageEntity']$")
oShouldManageInst.Source = oHealthServiceInst
oShouldManageInst.Target = oInst0
Call oDiscoveryData.AddInstance(oShouldManageInst)
End Sub
Set oDiscoveryData = oAPI.CreateDiscoveryData(0, source0, target0)
If nodeList Is Nothing Then
Call oAPI.Return(oDiscoveryData)
Exit Sub
End If
If nodeList.Length = 0 Then
Call oAPI.Return(oDiscoveryData)
Exit Sub
End If
Set oHealthServiceInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthService']$")
Call oHealthServiceInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", host0)
Call oDiscoveryData.AddInstance(oHealthServiceInst)
Dim oNode, pNode, oInst, pInst, oRel
Dim childDbId, childUId, parentUid, parentTag, childTag
For Each oNode In nodeList
If sVblockId = "" Then 'it's VblockRoot
sVblockId = oNode.SelectSingleNode("./moId").Text
End If
childTag = oNode.NodeName
childDbId = oNode.SelectSingleNode("./dbId").Text
childUId = sVblockId & ":" & childDbId
Set pNode = oNode.SelectSingleNode("./associatedObject[assocationType='parent']")
If Not pNode Is Nothing Then
parentTag = pNode.SelectSingleNode("./elementName").Text
parentUid = sVblockId & ":" & pNode.SelectSingleNode("./dbId").Text
End If
If dct.Exists(childTag & ".type") Then
Set oInst = oDiscoveryData.CreateClassInstance(dct.Item(childTag & ".type"))
Call oInst.AddProperty("$MPElement[Name='VCE.Vision.Monitoring.Class.VblockBase']/uuid$", childUId)
Call AddPropertiesByNode(oInst, oNode, dct)
If childTag = "computeserver" Then
Call AddComputeServerProperties(oInst, childDbId)
End If
Call oDiscoveryData.AddInstance(oInst)
Call AssignHealthService(oInst, oHealthServiceInst)
If pNode Is Nothing Then
sDebugMsg = sDebugMsg & vbNewLine & "+" & childTag & ": " & childUId
Else
If dct.Exists(parentTag & ".type") Then
Set pInst = oDiscoveryData.CreateClassInstance(dct.Item(parentTag & ".type"))
Else
Set pInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='VCE.Vision.Monitoring.Class.VblockGenericComponent']$")
End If
Call pInst.AddProperty("$MPElement[Name='VCE.Vision.Monitoring.Class.VblockBase']/uuid$", parentUid)
Set oRel = oDiscoveryData.CreateRelationshipInstance(dct.Item(childTag & ".rel"))
oRel.Source = pInst
oRel.Target = oInst
Call oDiscoveryData.AddInstance(oRel)
sDebugMsg = sDebugMsg & vbNewLine & "+" & parentTag & "->" & childTag & ": " & childUId
End If
ElseIf parentTag = "compute" Or parentTag = "network" Or parentTag = "storage" Then
' top level generic objects
Dim attrNodeList, attrNode, attrList
attrList = ""
Set attrNodeList = oNode.SelectNodes("./*[text()]")
For Each attrNode In attrNodeList
If attrExclList.IndexOf(attrNode.NodeName, 0) < 0 Then
attrList = attrList & "|./" & attrNode.NodeName
End If
Next
Call dct.Add(childTag & ".attr0","$MPElement[Name='VCE.Vision.Monitoring.Class.VblockGenericComponent']/sourceData$" & attrList)
Set pInst = oDiscoveryData.CreateClassInstance(dct.Item(parentTag & ".type"))
Call pInst.AddProperty("$MPElement[Name='VCE.Vision.Monitoring.Class.VblockBase']/uuid$", parentUid)
Set oRel = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='VCE.Vision.Monitoring.Relationship.VblockBaseContainsVblockGenericComponent']$")
oRel.Source = pInst
oRel.Target = oInst
Call oDiscoveryData.AddInstance(oRel)
sDebugMsg = sDebugMsg & vbNewLine & "+" & parentTag & "->" & childTag & ": " & childUId
End If
Next
If bDebug = "true" Then
Call oAPI.LogScriptEvent("vDiscovery", 1002, 0, sDebugMsg)
End If