Dim objArgs, SourceID, ManagedEntityId, TargetComputer, ImagePath, SerialNumber
Dim objMOMAPI, objWMIService, objDiscoveryData
Dim colobjPorts, objHBAs, AdaptName, strQuery
Dim objPort, objHBA
Dim arrOfInst(97) '2 * maxadapters.
Dim objPortInst, InstanceName
Dim bFoundInstance, Index, portIndex,SystemEntity, portWWN, FabricName
Dim HyperVGUID
Dim objAdapInst,objHBAPortRel
bFoundInstance = True
Set objArgs = WScript.Arguments
If WScript.Arguments.Count > 0 Then
SourceId = objArgs(0)
ManagedEntityId = objArgs(1)
ImagePath = objArgs(2)
SerialNumber = objArgs(3)
AdaptName = objArgs(4)
TargetComputer = objArgs(5)
HyperVGUID = objArgs(6)
End If
Set objMOMAPI = CreateObject("MOM.ScriptAPI")
Set objDiscoveryData = objMOMAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
Set objWMIService = GetObject( "winmgmts:\\localhost\root\wmi" )
strQuery = "select * from MSFC_FCAdapterHBAAttributes Where SerialNumber='" + SerialNumber +"'"
Set objHBAs = objWMIService.ExecQuery( strQuery)
If (objHBAs is Nothing) Then
bFoundInstance = False
End If
'Get number of port InstanceNames with the same SerialNumber.
Index = 0
For Each objHBA In objHBAs
arrOfInst(Index) = objHBA.InstanceName
Index = Index + 1
Next
Set colobjPorts = objWMIService.ExecQuery("select * from MSFC_FibrePortHBAAttributes" )
If (colobjPorts is Nothing And bFoundInstance) Then
bFoundInstance = False
End If
portIndex = 0
If (colobjPorts.count > 0 And bFoundInstance) Then
For Each objPort In colobjPorts
If (ChkStrExistsInArray(arrOfInst,objPort.InstanceName,Index,False) = true) Then
'Create HBA Instance and HBA PORT relation object.
Set objAdapInst = objDiscoveryData.CreateClassInstance("$MPElement[Name='Brocade.FCHBA.Monitoring.HBA']$")
Call objAdapInst.AddProperty("$MPElement[Name='Brocade.FCHBA.Monitoring.Host']/ImagePath$", ImagePath)
Call objAdapInst.AddProperty ("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
Call objAdapInst.AddProperty("$MPElement[Name='Brocade.FCHBA.Monitoring.HBA']/SerialNumber$", SerialNumber)
'End of new code.
FabricName = WWNToString(objPort.Attributes.FabricName)'unique to this adapter port.
portWWN = WWNToString(objPort.Attributes.PortWWN)'unique to this adapter port.
SystemEntity = AdaptName + "_Port" + CStr(portIndex)
Set objPortInst = objDiscoveryData.CreateClassInstance("$MPElement[Name='Brocade.FCHBA.Monitoring.Port']$")
'Call objPortInst.AddProperty("$MPElement[Name='Brocade.FCHBA.Monitoring.Host']/ImagePath$", ImagePath)
'Call objPortInst.AddProperty ("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
'Call objPortInst.AddProperty("$MPElement[Name='Brocade.FCHBA.Monitoring.HBA']/SerialNumber$", SerialNumber)
'Call objMOMAPI.LogScriptEvent("DiscoverHBAPorts.vbs", 200, 2, "one Port instance added")
portIndex = portIndex + 1
End If
Next
End If
'Call objMOMAPI.LogScriptEvent("DiscoverHBAPorts.vbs", 200, 2, "Completed DiscoverHBAPorts.vbs.")
'Submit the discovery data for processing.
Call objMOMAPI.Return(objDiscoveryData)
WScript.Quit
'----------------------------End Of Main Fn---------------
'Converts WWN to StringWWN
Function WWNToString(arrayWWN)
Dim I
WWNToString = Hex0(arrayWWN(0))
For I = 1 To 7
WWNToString = WWNToString + ":" + Hex0(arrayWWN(I))
Next
End Function
'Returns the hexadecimal string value of input number(as two digits).
Function Hex0(n)
Hex0 = Hex(n)
If (n < &h10) Then Hex0 = "0" + Hex0
End Function
'If str exists then returns true
'If not exists then returns false and adds the string to the array (if bAddTo is true)
'If not exists then returns false and does not add the inputstring to the list(if bAddTo is false)
Function ChkStrExistsInArray(arrayOfStrs(),InputStr,LastItemIndex,bAddTo)
Dim I
ChkStrExistsInArray = False
For I = 0 To LastItemIndex
If (StrComp(LCase(arrayOfStrs(I)),LCase(InputStr)) = 0) Then
ChkStrExistsInArray = true
Exit For
End If
Next
If (ChkStrExistsInArray = False And bAddTo=True) Then
arrayOfStrs(LastItemIndex+1) = InputStr
End If
End Function </Script></ScriptBody>
<TimeoutSeconds>400</TimeoutSeconds>
</DataSource>
</Discovery>